Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for .NET Core #160

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6afd70c
Create solution for Core; add conditional compilation FEATURE_SERIALI…
Jan 5, 2017
501d90e
Add FEATURE_PERFCOUNTERS for using performance counters.
Jan 6, 2017
9223a5b
Edit gitignore.
Jan 6, 2017
5f72ec4
Add FEATURE_APPDOMAIN, FEATURE_REMOTING, FEATURE_LEGACY_REFLECTION_AP…
Jan 11, 2017
bcf93db
Add FEATURE_GAC
Jan 13, 2017
8bc3579
Add build options NETCORE, FEATURE_ASSEMBLYLOADCONTEXT
Jan 13, 2017
9522492
Add FEATURE_ISUPPORTINITIALIZE
Jan 16, 2017
a1223c2
Add FEATURE_SECURITY_PERMISSIONS
Jan 17, 2017
93a45d8
Add System.Threading.Thread
Jan 17, 2017
96d740c
Replace [MethodImpl(MethodImplOptions.Synchronized)] with lock(this)
Jan 17, 2017
c615097
Add dependency System.Text.RegularExpressions
Jan 17, 2017
773b88c
Exclude from NET Core compilation the code that uses System.Web and S…
Jan 17, 2017
09bef55
Exclude the code that uses ICloneable from compilation on NET Core
Jan 17, 2017
ab7f716
Add FEATURE_SYSTEM_CONFIGURATION
Jan 17, 2017
10169c8
Use "://" for Uri.SchemeDelimiter, fix the conditional compilation fo…
Jan 17, 2017
102a592
Use a custom Converter delegate for NET Core
Jan 18, 2017
87892c1
Replace ForEach() with foreach loop
Jan 18, 2017
d9b641e
Replace ConvertAll with Select
Jan 19, 2017
cfbd89d
Add CustomAttributeExtensions, port the code that contains Attribute/…
Jan 19, 2017
fd22b8d
Replace Delegate.CreateDelegate with MethodInfo.CreateDelegate and so…
Jan 20, 2017
4c9e085
Add new methods that require the calling assembly passed in because A…
Jan 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ src/*/obj
src/*/bin
samples/*/obj
samples/*/bin
*.csproj.user
*.user
*ReSharper.user
_ReSharper*
*resharper*
Expand All @@ -19,4 +19,7 @@ _ReSharper*
*.orig
*.bak
*.sln.DotSettings.user
*.DotSettings.user
*.DotSettings.user

project.lock.json
.vs
22 changes: 22 additions & 0 deletions Castle.Windsor-NetCore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Castle.Windsor", "src\Castle.Windsor\Castle.Windsor.xproj", "{6C92C875-3E3B-4CE3-A46D-FB309AC28557}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6C92C875-3E3B-4CE3-A46D-FB309AC28557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C92C875-3E3B-4CE3-A46D-FB309AC28557}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C92C875-3E3B-4CE3-A46D-FB309AC28557}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C92C875-3E3B-4CE3-A46D-FB309AC28557}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !(SILVERLIGHT || CLIENTPROFILE || DOTNET35)
#if !(SILVERLIGHT || CLIENTPROFILE || DOTNET35 || NETCORE)

using System.Web;

Expand Down
19 changes: 11 additions & 8 deletions src/Castle.Windsor/Castle.Windsor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<OutputPath>bin\NET40-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET DOTNET40 </DefineConstants>
<DefineConstants>TRACE;DOTNET DOTNET40 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET40-Release\Castle.Windsor.XML</DocumentationFile>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -50,7 +50,7 @@
</TargetFrameworkProfile>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\NET40-Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET40 </DefineConstants>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET40 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET40-Debug\Castle.Windsor.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
Expand All @@ -69,7 +69,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NET45-Release|AnyCPU'">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>bin\NET45-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET;DOTNET45</DefineConstants>
<DefineConstants>TRACE;DOTNET;DOTNET45 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET45-Release\Castle.Windsor.XML</DocumentationFile>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -82,7 +82,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\NET45-Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;DOTNET;DOTNET45</DefineConstants>
<DefineConstants>TRACE;DEBUG;DOTNET;DOTNET45 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET45-Debug\Castle.Windsor.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
Expand All @@ -94,7 +94,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<OutputPath>bin\NET40CP-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET DOTNET40 CLIENTPROFILE</DefineConstants>
<DefineConstants>TRACE;DOTNET DOTNET40 CLIENTPROFILE FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\Release\Castle.Windsor.XML</DocumentationFile>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -117,7 +117,7 @@
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\NET40CP-Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET40 CLIENTPROFILE</DefineConstants>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET40 CLIENTPROFILE FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\Debug\Castle.Windsor.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
Expand All @@ -138,7 +138,7 @@
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<OutputPath>bin\NET35-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET DOTNET35</DefineConstants>
<DefineConstants>TRACE;DOTNET DOTNET35 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET35-Release\Castle.Windsor.XML</DocumentationFile>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -162,7 +162,7 @@
</TargetFrameworkProfile>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\NET35-Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET35</DefineConstants>
<DefineConstants>TRACE;DEBUG;DOTNET DOTNET35 FEATURE_APPDOMAIN FEATURE_GAC FEATURE_ISUPPORTINITIALIZE FEATURE_LEGACY_REFLECTION_API FEATURE_PERFCOUNTERS FEATURE_REMOTING FEATURE_SECURITY_PERMISSIONS FEATURE_SERIALIZATION FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DocumentationFile>bin\NET35-Debug\Castle.Windsor.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
Expand Down Expand Up @@ -341,6 +341,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Compatibility\CustomAttributeExtensions.cs" />
<Compile Include="Compatibility\IntrospectionExtensions.cs" />
<Compile Include="Compatibility\NetCoreReflectionExtensions.cs" />
<Compile Include="Core\Internal\SimpleThreadSafeCollection.cs" />
<Compile Include="Core\Internal\SimpleThreadSafeSet.cs" />
<Compile Include="Facilities\Startable\IStartFlagInternal.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/Castle.Windsor/Castle.Windsor.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>6c92c875-3e3b-4ce3-a46d-fb309ac28557</ProjectGuid>
<RootNamespace>Castle.Windsor</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
63 changes: 63 additions & 0 deletions src/Castle.Windsor/Compatibility/CustomAttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2004-2015 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if FEATURE_LEGACY_REFLECTION_API

namespace System.Reflection
{
using System.Collections.Generic;

// This allows us to use the new reflection API while still supporting .NET 3.5 and 4.0.
//
// Methods like Attribute.IsDefined no longer exist in .NET Core so this provides a shim
// for .NET 3.5 and 4.0.
//
// This class only implemented the required extensions so add more if needed in the order
// from https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Extensions/ref/System.Reflection.Extensions.cs
internal static class CustomAttributeExtensions
{
public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
{
foreach (T a in Attribute.GetCustomAttributes(element, typeof(T)))
{
yield return a;
}
}

public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element, bool inherit) where T : Attribute
{
foreach (T a in Attribute.GetCustomAttributes(element, typeof(T), inherit))
{
yield return a;
}
}

public static bool IsDefined(this MemberInfo element, Type attributeType)
{
return Attribute.IsDefined(element, attributeType);
}

public static bool IsDefined(this ParameterInfo element, Type attributeType)
{
return Attribute.IsDefined(element, attributeType);
}

public static bool IsDefined(this ConstructorInfo element, Type attributeType)
{
return Attribute.IsDefined(element, attributeType);
}
}
}

#endif
35 changes: 35 additions & 0 deletions src/Castle.Windsor/Compatibility/IntrospectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2004-2015 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if FEATURE_LEGACY_REFLECTION_API

namespace System.Reflection
{
internal static class IntrospectionExtensions
{
// This allows us to use the new reflection API which separates Type and TypeInfo
// while still supporting .NET 3.5 and 4.0. This class matches the API of the same
// class in .NET 4.5+, and so is only needed on .NET Framework versions before that.
//
// Return the System.Type for now, we will probably need to create a TypeInfo class
// which inherits from Type like .NET 4.5+ and implement the additional methods and
// properties.
public static Type GetTypeInfo(this Type type)
{
return type;
}
}
}

#endif
59 changes: 59 additions & 0 deletions src/Castle.Windsor/Compatibility/NetCoreReflectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2004-2015 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if FEATURE_NETCORE_REFLECTION_API

namespace System.Reflection
{
using System.Linq;

internal static class NetCoreReflectionExtensions
{
// .NET Core needs to expose GetConstructor that takes both flags and parameter types,
// because we need to get the private constructor for a type with multiple constructors.
// It should also provide the same for GetMethod, which luckily we don't need yet.
public static ConstructorInfo GetConstructor(this Type type, BindingFlags bindingAttr, object binder, Type[] types, object[] modifiers)
{
if (binder != null) throw new NotSupportedException("Parameter binder must be null.");
if (modifiers != null) throw new NotSupportedException("Parameter modifiers must be null.");

return type.GetConstructors(bindingAttr)
.SingleOrDefault(ctor => ctor.GetParameters().Select(p => p.ParameterType).SequenceEqual(types));
}

public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingAttr, object binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
{
if (binder != null) throw new NotSupportedException("Parameter binder must be null.");
if (modifiers != null) throw new NotSupportedException("Parameter modifiers must be null.");

var property = type.GetProperty(name, bindingAttr);
if (property.PropertyType == returnType)
return property;
return null;
}

public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingAttr, object binder, Type[] types, ParameterModifier[] modifiers)
{
if (binder != null) throw new NotSupportedException("Parameter binder must be null.");
if (modifiers != null) throw new NotSupportedException("Parameter modifiers must be null.");

var method = type.GetMethod(name, bindingAttr);
if (method.GetParameters().Select(p => p.ParameterType).SequenceEqual(types))
return method;
return null;
}
}
}

#endif
10 changes: 8 additions & 2 deletions src/Castle.Windsor/Core/CastleComponentAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Castle.Core
{
using System;
using System.Reflection;

/// <summary>
/// This attribute is useful only when you want to register all components
Expand Down Expand Up @@ -58,8 +59,13 @@ public bool HasName

public static CastleComponentAttribute GetDefaultsFor(Type type)
{
var attribute = (CastleComponentAttribute)GetCustomAttribute(type, typeof(CastleComponentAttribute));
if (attribute != null)
#if FEATURE_LEGACY_REFLECTION_API
var attribute = (CastleComponentAttribute)GetCustomAttribute(type, typeof(CastleComponentAttribute));
#else
var attribute = type.GetTypeInfo().GetCustomAttribute(typeof(CastleComponentAttribute)) as CastleComponentAttribute;
#endif

if (attribute != null)
{
if (attribute.ServicesSpecifiedExplicitly == false)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Castle.Windsor/Core/ComponentDependencyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ namespace Castle.Core
{
using System;

#if FEATURE_SERIALIZATION
[Serializable]
public class ComponentDependencyModel : DependencyModel
#endif
public class ComponentDependencyModel : DependencyModel
{
public ComponentDependencyModel(string referencedComponentName) : this(referencedComponentName, null)
{
Expand Down
Loading