diff --git a/src/NMS.Leo.Typed/Leo.Typed.csproj b/src/NMS.Leo.Typed/Leo.Typed.csproj index a689b77..25e58d7 100644 --- a/src/NMS.Leo.Typed/Leo.Typed.csproj +++ b/src/NMS.Leo.Typed/Leo.Typed.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net5.0;net6.0; + netstandard2.0;netcoreapp3.1;net5.0;net6.0; enable disable diff --git a/src/NMS.Leo/Core/Builder/DictBuilder.cs b/src/NMS.Leo/Core/Builder/DictBuilder.cs index 165487c..c84f190 100644 --- a/src/NMS.Leo/Core/Builder/DictBuilder.cs +++ b/src/NMS.Leo/Core/Builder/DictBuilder.cs @@ -1,8 +1,12 @@ using BTFindTree; +using Natasha.CSharp.Compiler; +using NMS.Leo.Metadata; using System.Reflection; using System.Text; -using NMS.Leo.Metadata; -using Natasha.CSharp.Compiler; + +#if NETCOREAPP3_1_OR_GREATER +using Natasha.CSharp.MultiDomain.Extension; +#endif // ReSharper disable once CheckNamespace namespace NMS.Leo.Builder; @@ -203,8 +207,14 @@ public static Type InitType(Type type, AlgorithmKind kind = AlgorithmKind.Hash) } - var classBuilder = NClass.UseDomain(type.GetDomain()) + var classBuilder = NClass +#if NETCOREAPP3_1_OR_GREATER + .UseDomain(type.GetDomain()) +#else + .DefaultDomain() +#endif .Public() + .Modifier(ModifierFlags.Sealed) .Using(type) .Namespace("NMS.Leo.NCallerDynamic") .InheritanceAppend(callType) @@ -229,7 +239,11 @@ public static Type InitType(Type type, AlgorithmKind kind = AlgorithmKind.Hash) private static Action> InitMetadataMappingCaller(Type runtimeProxyType) { return NDelegate - .UseDomain(runtimeProxyType.GetDomain()) +#if NETCOREAPP3_1_OR_GREATER + .UseDomain(runtimeProxyType.GetDomain()) +#else + .DefaultDomain() +#endif .Action>($"{runtimeProxyType.GetDevelopName()}.InitMetadataMapping(obj);"); } } \ No newline at end of file diff --git a/src/NMS.Leo/Core/Builder/FuzzyDictBuilder.cs b/src/NMS.Leo/Core/Builder/FuzzyDictBuilder.cs index 518ac5c..f0ffe01 100644 --- a/src/NMS.Leo/Core/Builder/FuzzyDictBuilder.cs +++ b/src/NMS.Leo/Core/Builder/FuzzyDictBuilder.cs @@ -1,5 +1,8 @@ using BTFindTree; using System.Collections.Concurrent; +#if NETCOREAPP3_1_OR_GREATER +using Natasha.CSharp.MultiDomain.Extension; +#endif // ReSharper disable once CheckNamespace namespace NMS.Leo.Builder; @@ -14,7 +17,7 @@ static FuzzyDictBuilder() private static readonly ConcurrentDictionary _type_cache; private static readonly ConcurrentDictionary _str_cache; - + public static unsafe DictBase Ctor(Type type) { //获得动态生成的类型 @@ -32,11 +35,15 @@ public static unsafe DictBase Ctor(Type type) //生成脚本 var newAction = NDelegate - .UseDomain(type.GetDomain()) - .ConfigUsing(_type_cache.Keys.ToArray(),"NMS.Leo.NCallerDynamic") +#if NETCOREAPP3_1_OR_GREATER + .UseDomain(type.GetDomain()) +#else + .DefaultDomain() +#endif + .ConfigUsing(_type_cache.Keys.ToArray(), "NMS.Leo.NCallerDynamic") .UnsafeFunc(newFindTree); - FuzzyDictOperator.CreateFromString = (delegate * managed)(newAction.Method.MethodHandle.GetFunctionPointer()); - return (DictBase) Activator.CreateInstance(proxyType); + FuzzyDictOperator.CreateFromString = (delegate* managed)(newAction.Method.MethodHandle.GetFunctionPointer()); + return (DictBase)Activator.CreateInstance(proxyType); } } \ No newline at end of file diff --git a/src/NMS.Leo/Core/Builder/HashDictBuilder.cs b/src/NMS.Leo/Core/Builder/HashDictBuilder.cs index 30bb8e9..df4a82c 100644 --- a/src/NMS.Leo/Core/Builder/HashDictBuilder.cs +++ b/src/NMS.Leo/Core/Builder/HashDictBuilder.cs @@ -1,6 +1,10 @@ using BTFindTree; using System.Collections.Concurrent; +#if NETCOREAPP3_1_OR_GREATER +using Natasha.CSharp.MultiDomain.Extension; +#endif + // ReSharper disable once CheckNamespace namespace NMS.Leo.Builder; @@ -32,7 +36,11 @@ public static unsafe DictBase Ctor(Type type) //生成脚本 var newAction = NDelegate - .UseDomain(type.GetDomain()) +#if NETCOREAPP3_1_OR_GREATER + .UseDomain(type.GetDomain()) +#else + .DefaultDomain() +#endif .ConfigUsing(_type_cache.Keys.ToArray(), "NMS.Leo.NCallerDynamic") .UnsafeFunc(newFindTree); diff --git a/src/NMS.Leo/Core/Builder/PrecisionDictBuilder.cs b/src/NMS.Leo/Core/Builder/PrecisionDictBuilder.cs index 27c6bbf..bb8094a 100644 --- a/src/NMS.Leo/Core/Builder/PrecisionDictBuilder.cs +++ b/src/NMS.Leo/Core/Builder/PrecisionDictBuilder.cs @@ -1,5 +1,8 @@ using BTFindTree; using System.Collections.Concurrent; +#if NETCOREAPP3_1_OR_GREATER +using Natasha.CSharp.MultiDomain.Extension; +#endif // ReSharper disable once CheckNamespace namespace NMS.Leo.Builder; @@ -32,7 +35,11 @@ public static unsafe DictBase Ctor(Type type) //生成脚本 var newAction = NDelegate - .UseDomain(type.GetDomain()) +#if NETCOREAPP3_1_OR_GREATER + .UseDomain(type.GetDomain()) +#else + .DefaultDomain() +#endif .ConfigUsing(_type_cache.Keys.ToArray(), "NMS.Leo.NCallerDynamic") .UnsafeFunc(newFindTree); diff --git a/src/NMS.Leo/Leo.csproj b/src/NMS.Leo/Leo.csproj index 49a68cc..2675735 100644 --- a/src/NMS.Leo/Leo.csproj +++ b/src/NMS.Leo/Leo.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net5.0;net6.0; + netstandard2.0;netcoreapp3.1;net5.0;net6.0; enable disable @@ -36,7 +36,7 @@ - + \ No newline at end of file diff --git a/test/NCallerUT/DictStaticTest.cs b/test/NCallerUT/DictStaticTest.cs index 5e814c9..ab63ee7 100644 --- a/test/NCallerUT/DictStaticTest.cs +++ b/test/NCallerUT/DictStaticTest.cs @@ -28,21 +28,24 @@ static StaticTest2(){ public static string Name; public static int Age{get;set;} + private static int _j; } }"; //根据脚本创建动态类 var oop = new AssemblyCSharpBuilder(); oop.Add(text); var type = oop.GetTypeFromShortName("StaticTest2"); + type.AllowLeoPrivate(); //创建动态类实例代理 var instance = PrecisionDictOperator.CreateFromType(type); //Get动态调用 Assert.Equal("111", (string) instance["Name"]); //调用动态委托赋值 instance["Name"] = "222"; - + instance["_j"] = 222; Assert.Equal("222", (string) instance["Name"]); Assert.Equal("222", instance.Get("Name")); + Assert.Equal(222, instance.Get("_j")); }