From 4303a788abf3ab2603f2aa80528cbce905868331 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 14 Jun 2024 13:04:45 +0100 Subject: [PATCH] Move Mapster config to static constructors (#7) --- .../FileGenerators/ProxyClassesGenerator.cs | 16 ++++++++-- ...Akka.Actor.LocalActorRefProviderProxy.g.cs | 3 +- ....SharePoint.Client.ClientContextProxy.g.cs | 6 ++-- ...t.SharePoint.Client.ClientObjectProxy.g.cs | 6 ++-- ...oint.Client.ClientRuntimeContextProxy.g.cs | 6 ++-- ...harePoint.Client.SecurableObjectProxy.g.cs | 6 ++-- .../Microsoft.SharePoint.Client.WebProxy.g.cs | 6 ++-- .../Destination/NoNamespaceProxy.g.cs | 3 +- ...ests.Namespace1.ClassInNamespaceProxy.g.cs | 3 +- ...ests.Namespace2.ClassInNamespaceProxy.g.cs | 3 +- ...eGeneratorTests.Source.Generic`1Proxy.g.cs | 3 +- ...ourceGeneratorTests.Source.HumanProxy.g.cs | 3 +- ...atorTests.Source.MixedVisibilityProxy.g.cs | 3 +- ...neratorTests.Source.OperatorTestProxy.g.cs | 3 +- ...eratorTests.Source.PersonExtendsProxy.g.cs | 3 +- ...urceGeneratorTests.Source.PersonProxy.g.cs | 6 ++-- ...orTests.Source.TestClassInternalProxy.g.cs | 3 +- ...eratorTests.Source.ÜberGeneric`3Proxy.g.cs | 3 +- .../System.Net.Http.HttpClientProxy.g.cs | 3 +- ...stem.Net.Http.HttpMessageInvokerProxy.g.cs | 3 +- ...y_Should_GenerateCorrectFiles.verified.txt | 26 ++++++--------- ...rateFiles_ForClassWithIgnores.verified.txt | 26 ++++++--------- ...es_ForClassWith_BaseInterface.verified.txt | 26 ++++++--------- ...teFiles_ForClassWith_Extended.verified.txt | 32 ++++++++----------- .../ProxyInterfaceSourceGeneratorTest.cs | 8 ++--- 25 files changed, 98 insertions(+), 111 deletions(-) diff --git a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs index e2e572e..ea583f6 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs @@ -119,7 +119,18 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator var configurationForMapster = string.Empty; if (Context.ReplacedTypes.Count > 0) { - configurationForMapster = GenerateMapperConfigurationForMapster(); + configurationForMapster = GenerateMapperConfigurationForMapster().Trim(); + } + + var staticConstructor = string.Empty; + if (!string.IsNullOrWhiteSpace(configurationForMapster)) + { + staticConstructor = $@" + static {constructorName}() + {{ + {configurationForMapster} + }} + "; } var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(pd.Namespace); @@ -152,9 +163,8 @@ operators} {{ _Instance = instance; {instanceBaseSetter} - -{configurationForMapster} }} +{staticConstructor} }} {namespaceEnd} {SupportsNullable.IIf("#nullable restore")}"; diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/AkkaGenerated/Akka.Actor.LocalActorRefProviderProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/AkkaGenerated/Akka.Actor.LocalActorRefProviderProxy.g.cs index c062e28..9b3c295 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/AkkaGenerated/Akka.Actor.LocalActorRefProviderProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/AkkaGenerated/Akka.Actor.LocalActorRefProviderProxy.g.cs @@ -130,9 +130,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs index 20136c3..16e9979 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs @@ -46,7 +46,10 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { _Instance = instance; _InstanceClientRuntimeContext = instance; + } + static ClientContextProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); @@ -61,9 +64,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance290679610 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.WebProxy(instance290679610)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_1534869484 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.WebProxy) proxy_1534869484)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs index 68773b5..e088926 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs @@ -83,15 +83,17 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { _Instance = instance; + } + static ClientObjectProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs index b6c2732..474c2eb 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs @@ -141,7 +141,10 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { _Instance = instance; + } + static ClientRuntimeContextProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); @@ -153,9 +156,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_1483513702 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(instance_1483513702)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy343311664 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy) proxy343311664)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs index 3be67cd..b770e34 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs @@ -44,7 +44,10 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { _Instance = instance; _InstanceClientObject = instance; + } + static SecurableObjectProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); @@ -53,9 +56,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_247129254 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(instance_247129254)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_117192422 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy) proxy_117192422)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs index 27d4907..287d29b 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs @@ -1129,7 +1129,10 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { _Instance = instance; _InstanceSecurableObject = instance; + } + static WebProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); @@ -1141,9 +1144,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_1483513702 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(instance_1483513702)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy343311664 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy) proxy343311664)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/NoNamespaceProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/NoNamespaceProxy.g.cs index 4aabccf..4ebb13e 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/NoNamespaceProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/NoNamespaceProxy.g.cs @@ -22,9 +22,8 @@ using System; { _Instance = instance; - - } + } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespaceProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespaceProxy.g.cs index d20befb..59121bd 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespaceProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespaceProxy.g.cs @@ -21,9 +21,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Namespace1 { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespaceProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespaceProxy.g.cs index b0677e7..9bacdfa 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespaceProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespaceProxy.g.cs @@ -21,9 +21,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Namespace2 { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs index 54ecd75..5728dff 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs @@ -28,9 +28,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs index 35fca57..6a9747a 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs @@ -30,9 +30,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs index 106dc8d..f8eb0b4 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs @@ -23,9 +23,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs index fd9c206..c6af6d7 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs @@ -45,9 +45,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs index 0c5bbae..4303d26 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs @@ -115,9 +115,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs index 5c321a4..d91e4c6 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs @@ -172,12 +172,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; _InstanceHuman = instance; + } + static PersonProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance2145588841 => new global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy(instance2145588841)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1567394325 => ((global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy) proxy1567394325)._Instance); - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs index 6c323b3..7521646 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs @@ -23,9 +23,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs index 4793470..409f683 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs @@ -42,9 +42,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs index cd4066e..c768a6b 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs @@ -394,9 +394,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; _InstanceHttpMessageInvoker = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs index 6cac66f..a1c96af 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs @@ -43,9 +43,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; - - } + } } #nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt index fb5222d..03ba694 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt @@ -61,12 +61,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; + } + static FooProxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance2058774601 => new global::ProxyInterfaceSourceGeneratorTests.Source.FooProxy(instance2058774601)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1662609081 => ((global::ProxyInterfaceSourceGeneratorTests.Source.FooProxy) proxy1662609081)._Instance); - - } + } } #nullable restore @@ -150,16 +152,7 @@ namespace Speckle.ProxyGenerator ProxyForBaseInterface = 8 } - public interface IProxyMap - { - Type? GetMappedTypeFromHostType(Type type); - Type? GetMappedTypeFromProxyType(Type type); - Type? GetHostTypeFromMappedType(Type type); - - object CreateProxy(Type type, object toWrap); - } - - public class ProxyMap : IProxyMap + public static class ProxyMap { private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_revitToInterfaceMap = new(); private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_proxyToInterfaceMap = new(); @@ -183,7 +176,7 @@ namespace Speckle.ProxyGenerator s_interfaceToRevit.TryAdd(typeof(TInterface), typeof(T)); } - public Type? GetMappedTypeFromHostType(Type type) + public static Type? GetMappedTypeFromHostType(Type type) { if (s_revitToInterfaceMap.TryGetValue(type, out var t)) { @@ -192,7 +185,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetMappedTypeFromProxyType(Type type) + public static Type? GetMappedTypeFromProxyType(Type type) { if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) { @@ -202,7 +195,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetHostTypeFromMappedType(Type type) + public static Type? GetHostTypeFromMappedType(Type type) { if (s_interfaceToRevit.TryGetValue(type, out var t)) { @@ -212,7 +205,8 @@ namespace Speckle.ProxyGenerator return null; } - public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static T CreateProxy(object toWrap) => (T)CreateProxy(typeof(T), toWrap); } #nullable restore } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt index 83274e2..ee07c44 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt @@ -69,12 +69,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; + } + static Foo2Proxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance1325374861 => new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(instance1325374861)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1047178445 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy) proxy1047178445)._Instance); - - } + } } #nullable restore @@ -158,16 +160,7 @@ namespace Speckle.ProxyGenerator ProxyForBaseInterface = 8 } - public interface IProxyMap - { - Type? GetMappedTypeFromHostType(Type type); - Type? GetMappedTypeFromProxyType(Type type); - Type? GetHostTypeFromMappedType(Type type); - - object CreateProxy(Type type, object toWrap); - } - - public class ProxyMap : IProxyMap + public static class ProxyMap { private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_revitToInterfaceMap = new(); private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_proxyToInterfaceMap = new(); @@ -191,7 +184,7 @@ namespace Speckle.ProxyGenerator s_interfaceToRevit.TryAdd(typeof(TInterface), typeof(T)); } - public Type? GetMappedTypeFromHostType(Type type) + public static Type? GetMappedTypeFromHostType(Type type) { if (s_revitToInterfaceMap.TryGetValue(type, out var t)) { @@ -200,7 +193,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetMappedTypeFromProxyType(Type type) + public static Type? GetMappedTypeFromProxyType(Type type) { if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) { @@ -210,7 +203,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetHostTypeFromMappedType(Type type) + public static Type? GetHostTypeFromMappedType(Type type) { if (s_interfaceToRevit.TryGetValue(type, out var t)) { @@ -220,7 +213,8 @@ namespace Speckle.ProxyGenerator return null; } - public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static T CreateProxy(object toWrap) => (T)CreateProxy(typeof(T), toWrap); } #nullable restore } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_BaseInterface.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_BaseInterface.verified.txt index 2c705a1..e43337e 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_BaseInterface.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_BaseInterface.verified.txt @@ -71,12 +71,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; + } + static Foo2Proxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance1325374861 => new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(instance1325374861)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1047178445 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy) proxy1047178445)._Instance); - - } + } } #nullable restore @@ -160,16 +162,7 @@ namespace Speckle.ProxyGenerator ProxyForBaseInterface = 8 } - public interface IProxyMap - { - Type? GetMappedTypeFromHostType(Type type); - Type? GetMappedTypeFromProxyType(Type type); - Type? GetHostTypeFromMappedType(Type type); - - object CreateProxy(Type type, object toWrap); - } - - public class ProxyMap : IProxyMap + public static class ProxyMap { private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_revitToInterfaceMap = new(); private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_proxyToInterfaceMap = new(); @@ -193,7 +186,7 @@ namespace Speckle.ProxyGenerator s_interfaceToRevit.TryAdd(typeof(TInterface), typeof(T)); } - public Type? GetMappedTypeFromHostType(Type type) + public static Type? GetMappedTypeFromHostType(Type type) { if (s_revitToInterfaceMap.TryGetValue(type, out var t)) { @@ -202,7 +195,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetMappedTypeFromProxyType(Type type) + public static Type? GetMappedTypeFromProxyType(Type type) { if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) { @@ -212,7 +205,7 @@ namespace Speckle.ProxyGenerator return null; } - public Type? GetHostTypeFromMappedType(Type type) + public static Type? GetHostTypeFromMappedType(Type type) { if (s_interfaceToRevit.TryGetValue(type, out var t)) { @@ -222,7 +215,8 @@ namespace Speckle.ProxyGenerator return null; } - public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static T CreateProxy(object toWrap) => (T)CreateProxy(typeof(T), toWrap); } #nullable restore } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_Extended.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_Extended.verified.txt index be6f694..ae368bc 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_Extended.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWith_Extended.verified.txt @@ -83,12 +83,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; + } + static Foo3Proxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance969373361 => new global::ProxyInterfaceSourceGeneratorTests.Source.Bar3Proxy(instance969373361)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy339001485 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Bar3Proxy) proxy339001485)._Instance); - - } + } } #nullable restore @@ -119,12 +121,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { _Instance = instance; + } + static Bar3Proxy() + { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance969373361 => new global::ProxyInterfaceSourceGeneratorTests.Source.Bar3Proxy(instance969373361)); Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy339001485 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Bar3Proxy) proxy339001485)._Instance); - - } + } } #nullable restore @@ -208,16 +212,7 @@ namespace Speckle.ProxyGenerator ProxyForBaseInterface = 8 } - public interface IProxyMap - { - Type? GetMappedTypeFromHostType(Type type); - Type? GetMappedTypeFromProxyType(Type type); - Type? GetHostTypeFromMappedType(Type type); - - object CreateProxy(Type type, object toWrap); - } - - public class ProxyMap : IProxyMap + public static class ProxyMap { private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_revitToInterfaceMap = new(); private static readonly global::System.Collections.Concurrent.ConcurrentDictionary s_proxyToInterfaceMap = new(); @@ -242,7 +237,7 @@ Add s_proxyFactory[type](toWrap); + public static object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); + public static T CreateProxy(object toWrap) => (T)CreateProxy(typeof(T), toWrap); } #nullable restore } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs index fb107ff..f4e278c 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs @@ -615,7 +615,7 @@ public class ProxyInterfaceSourceGeneratorTest .And.Be(File.ReadAllText($"../../../Destination/{interfacePersonFilename}")); // Assert Proxy Human - var proxyClassHuman = result.Files[3].SyntaxTree; + var proxyClassHuman = result.Files[2].SyntaxTree; proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename); var proxyCodeHuman = proxyClassHuman.ToString(); @@ -627,7 +627,7 @@ public class ProxyInterfaceSourceGeneratorTest .And.Be(File.ReadAllText($"../../../Destination/{proxyClassHumanFilename}")); // Assert Proxy Person - var proxyClassPerson = result.Files[4].SyntaxTree; + var proxyClassPerson = result.Files[3].SyntaxTree; proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename); var proxyCode = proxyClassPerson.ToString(); @@ -726,7 +726,7 @@ public class ProxyInterfaceSourceGeneratorTest ); // Assert Proxy IHttpClient - var proxyClassIHttpClient = result.Files[3].SyntaxTree; + var proxyClassIHttpClient = result.Files[2].SyntaxTree; proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename); var proxyCodeIHttpClient = proxyClassIHttpClient.ToString(); @@ -741,7 +741,7 @@ public class ProxyInterfaceSourceGeneratorTest .And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}")); // Assert Proxy IHttpMessageInvoker - var proxyClassIMessageInvoker = result.Files[4].SyntaxTree; + var proxyClassIMessageInvoker = result.Files[3].SyntaxTree; proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename); var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString();