diff --git a/SRC/Private/Extensions/CodeAnalysisExtensions.cs b/SRC/Private/Extensions/CodeAnalysisExtensions.cs index a90d4798..ff6319ab 100644 --- a/SRC/Private/Extensions/CodeAnalysisExtensions.cs +++ b/SRC/Private/Extensions/CodeAnalysisExtensions.cs @@ -5,6 +5,9 @@ ********************************************************************************/ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; +using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -71,5 +74,28 @@ public static NameSyntax Qualify(this IEnumerable parts) right: (SimpleNameSyntax) coll[coll.Count - 1] ); } + + [SuppressMessage("Security", "CA5351:Do Not Use Broken Cryptographic Algorithms")] + public static string GetMD5HashCode(this SyntaxNode node) + { + using MD5 md5 = MD5.Create(); + + byte[] hash = md5.ComputeHash + ( + Encoding.UTF8.GetBytes(node.ToFullString()) + ); + + StringBuilder sb = new(); + + for (int i = 0; i < hash.Length; i++) + { + sb.Append + ( + md5.Hash[i].ToString("X2", null) + ); + } + + return sb.ToString(); + } } } diff --git a/SRC/Private/Extensions/Metadata/MemberInfoExtensions.cs b/SRC/Private/Extensions/Metadata/MemberInfoExtensions.cs index db2c789b..29a03fae 100644 --- a/SRC/Private/Extensions/Metadata/MemberInfoExtensions.cs +++ b/SRC/Private/Extensions/Metadata/MemberInfoExtensions.cs @@ -4,7 +4,6 @@ * Author: Denes Solti * ********************************************************************************/ using System; -using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; @@ -53,8 +52,6 @@ private static MemberInfo DoExtractFrom(LambdaExpression expr) public static ExtendedMemberInfo ExtractFrom(Delegate accessor) => Cache.GetOrAdd(accessor, static accessor => { - Debug.Assert(accessor.Target is null); - MethodInfo method = (MethodInfo) accessor .Method .GetInstructions() diff --git a/SRC/Private/SourceGenerators/ProxyEmbedder.cs b/SRC/Private/SourceGenerators/ProxyEmbedder.cs index 68901ad8..c0a3c277 100644 --- a/SRC/Private/SourceGenerators/ProxyEmbedder.cs +++ b/SRC/Private/SourceGenerators/ProxyEmbedder.cs @@ -97,10 +97,10 @@ public void Initialize(GeneratorInitializationContext context) public void Execute(GeneratorExecutionContext context) { // - // Csak C# 8.0+ tamogatjuk + // Csak C# 7.0+ tamogatjuk // - if (context.Compilation is not CSharpCompilation { LanguageVersion: >= LanguageVersion.CSharp8 } compilation) + if (context.Compilation is not CSharpCompilation { LanguageVersion: >= LanguageVersion.CSharp7 } compilation) { context.ReportDiagnostic ( diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Constructor.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Constructor.cs index 216cbf65..930a4938 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Constructor.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Constructor.cs @@ -5,6 +5,7 @@ ********************************************************************************/ using System.Collections.Generic; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -20,13 +21,13 @@ internal partial class ClassSyntaxFactoryBase #if DEBUG internal #endif - protected ConstructorDeclarationSyntax ResolveConstructor(IConstructorInfo ctor, string className) + protected ConstructorDeclarationSyntax ResolveConstructor(IConstructorInfo ctor, SyntaxToken name) { IReadOnlyList paramz = ctor.Parameters; return ConstructorDeclaration ( - identifier: Identifier(className) + name ) .WithModifiers ( @@ -75,11 +76,11 @@ protected ConstructorDeclarationSyntax ResolveConstructor(IConstructorInfo ctor, #if DEBUG internal #endif - protected abstract IEnumerable ResolveConstructors(object context); + protected abstract ClassDeclarationSyntax ResolveConstructors(ClassDeclarationSyntax cls, object context); #if DEBUG internal #endif - protected abstract IEnumerable ResolveConstructor(object context, IConstructorInfo ctor); + protected abstract ClassDeclarationSyntax ResolveConstructor(ClassDeclarationSyntax cls, object context, IConstructorInfo ctor); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Event.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Event.cs index 105a5adc..e1b18c6f 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Event.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Event.cs @@ -86,11 +86,11 @@ protected EventDeclarationSyntax ResolveEvent(IEventInfo @event, CSharpSyntaxNod #if DEBUG internal #endif - protected abstract IEnumerable ResolveEvents(object context); + protected abstract ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context); #if DEBUG internal #endif - protected abstract IEnumerable ResolveEvent(object context, IEventInfo evt); + protected abstract ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs index 93c0e45d..f110d6d2 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs @@ -3,6 +3,7 @@ * * * Author: Denes Solti * ********************************************************************************/ +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -45,7 +46,7 @@ protected FieldDeclarationSyntax ResolveStaticGlobal(ITypeInfo type, string name ( TokenList ( - new[] + new SyntaxToken[] { Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.StaticKeyword), @@ -54,5 +55,18 @@ protected FieldDeclarationSyntax ResolveStaticGlobal(ITypeInfo type, string name ) ); } + + /// + /// private static readonly System.Object paramName [= ...]; + /// + #if DEBUG + internal + #endif + protected FieldDeclarationSyntax ResolveStaticGlobal(string name, ExpressionSyntax? initializer = null) => ResolveStaticGlobal + ( + MetadataTypeInfo.CreateFrom(typeof(T)), + name, + initializer + ); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Member.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Member.cs index 2b2fbf81..a065434f 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Member.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Member.cs @@ -3,6 +3,7 @@ * * * Author: Denes Solti * ********************************************************************************/ +using System; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp; @@ -50,6 +51,27 @@ private ExpressionSyntax AmendTarget(ExpressionSyntax? target, IMemberInfo membe member ); + + #if DEBUG + internal + #endif + protected static MemberAccessExpressionSyntax StaticMemberAccess(ClassDeclarationSyntax target, MemberDeclarationSyntax member) => SimpleMemberAccess + ( + AliasQualifiedName + ( + IdentifierName + ( + Token(SyntaxKind.GlobalKeyword) + ), + IdentifierName(target.Identifier) + ), + member switch + { + FieldDeclarationSyntax fld => ToIdentifierName(fld), + _ => throw new NotSupportedException() // TODO: method, prop, etc + } + ); + /// /// [[(Type)] target | [(Type)] this | Namespace.Type].Member /// diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Method.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Method.cs index e6db1a0d..a1e90bec 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Method.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Method.cs @@ -236,11 +236,11 @@ protected InvocationExpressionSyntax InvokeMethod(IMethodInfo method, Expression #if DEBUG internal #endif - protected abstract IEnumerable ResolveMethods(object context); + protected abstract ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context); #if DEBUG internal #endif - protected abstract IEnumerable ResolveMethod(object context, IMethodInfo method); + protected abstract ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo method); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Property.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Property.cs index 740edc02..eac3c828 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Property.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Property.cs @@ -173,11 +173,11 @@ protected IndexerDeclarationSyntax ResolveIndexer(IPropertyInfo property, CSharp #if DEBUG internal #endif - protected abstract IEnumerable ResolveProperties(object context); + protected abstract ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context); #if DEBUG internal #endif - protected abstract IEnumerable ResolveProperty(object context, IPropertyInfo property); + protected abstract ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo property); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Variable.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Variable.cs index 9c77bcf8..8e9d48a7 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Variable.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Variable.cs @@ -58,6 +58,22 @@ protected LocalDeclarationStatementSyntax ResolveLocal(ITypeInfo type, string na #if DEBUG internal #endif - protected static ArgumentSyntax ToArgument(LocalDeclarationStatementSyntax variable) => Argument(ToIdentifierName(variable)); + protected static ArgumentSyntax ToArgument(LocalDeclarationStatementSyntax variable) => Argument + ( + ToIdentifierName(variable) + ); + + #if DEBUG + internal + #endif + protected static IdentifierNameSyntax ToIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier); + + #if DEBUG + internal + #endif + protected static ArgumentSyntax ToArgument(FieldDeclarationSyntax field) => Argument + ( + ToIdentifierName(field) + ); } } diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.cs index d2f0cd20..f1604371 100644 --- a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.cs +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.cs @@ -21,8 +21,9 @@ internal abstract partial class ClassSyntaxFactoryBase: SyntaxFactoryBase #if DEBUG internal #endif - protected virtual ClassDeclarationSyntax ResolveClass(object context, CancellationToken cancellation) => - ClassDeclaration + protected virtual ClassDeclarationSyntax ResolveClass(object context, CancellationToken cancellation) + { + ClassDeclarationSyntax cls = ClassDeclaration ( identifier: ResolveClassName(context) ) @@ -50,28 +51,28 @@ internal abstract partial class ClassSyntaxFactoryBase: SyntaxFactoryBase ) ) ) - ) - .WithMembers - ( - List - ( - ResolveMembers(context, cancellation) - ) ); + return ResolveMembers(cls, context, cancellation); + } + #if DEBUG internal #endif - protected virtual IEnumerable ResolveMembers(object context, CancellationToken cancellation) + protected virtual ClassDeclarationSyntax ResolveMembers(ClassDeclarationSyntax cls, object context, CancellationToken cancellation) { - foreach (Func> factory in new Func>[] { ResolveConstructors, ResolveMethods, ResolveProperties, ResolveEvents }) + foreach (Func factory in new Func[] + { + ResolveConstructors, + ResolveMethods, + ResolveProperties, + ResolveEvents + }) { - foreach (MemberDeclarationSyntax member in factory(context)) - { - cancellation.ThrowIfCancellationRequested(); - yield return member; - } + cancellation.ThrowIfCancellationRequested(); + cls = factory(cls, context); } + return cls; } #if DEBUG diff --git a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.ConstructorFactory.cs b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.ConstructorFactory.cs index 05f5b70b..14a0ee2d 100644 --- a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.ConstructorFactory.cs +++ b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.ConstructorFactory.cs @@ -3,8 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System.Collections.Generic; - using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Solti.Utils.Proxy.Internals @@ -14,23 +12,21 @@ internal partial class DuckSyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveConstructors(object context) + protected override ClassDeclarationSyntax ResolveConstructors(ClassDeclarationSyntax cls, object context) { foreach (IConstructorInfo ctor in BaseType.GetPublicConstructors()) { - foreach (MemberDeclarationSyntax member in ResolveConstructor(null!, ctor)) - { - yield return member; - } + cls = ResolveConstructor(cls, context, ctor); } + return cls; } #if DEBUG internal #endif - protected override IEnumerable ResolveConstructor(object context, IConstructorInfo ctor) - { - yield return ResolveConstructor(ctor, ResolveClassName(null!)); - } + protected override ClassDeclarationSyntax ResolveConstructor(ClassDeclarationSyntax cls, object context, IConstructorInfo ctor) => cls.AddMembers + ( + ResolveConstructor(ctor, cls.Identifier) + ); } } \ No newline at end of file diff --git a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.EventInterceptorFactory.cs b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.EventInterceptorFactory.cs index a7bc8a83..0dc1c233 100644 --- a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.EventInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.EventInterceptorFactory.cs @@ -3,7 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,7 +16,7 @@ internal partial class DuckSyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveEvents(object context) + protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) { foreach (IEventInfo ifaceEvt in InterfaceType.Events) { @@ -35,12 +34,11 @@ protected override IEnumerable ResolveEvents(object con checkRemove: ifaceEvt.RemoveMethod is not null ); - foreach (MemberDeclarationSyntax member in ResolveEvent(ifaceEvt, targetEvt)) - { - yield return member; - } + cls = ResolveEvent(cls, ifaceEvt, targetEvt); } + return cls; + [SuppressMessage("Maintainability", "CA1508:Avoid dead conditional code", Justification = "There is not dead code.")] static bool SignatureEquals(IMemberInfo targetMember, IMemberInfo ifaceMember) { @@ -75,7 +73,7 @@ static bool SignatureEquals(IMemberInfo targetMember, IMemberInfo ifaceMember) #if DEBUG internal #endif - protected override IEnumerable ResolveEvent(object context, IEventInfo targetEvt) + protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo targetEvt) { IEventInfo ifaceEVt = (IEventInfo) context; @@ -85,12 +83,15 @@ protected override IEnumerable ResolveEvent(object cont ? accessor.DeclaringInterfaces.Single() // explicit esemenyhez biztosan csak egy deklaralo interface tartozik : null; - yield return ResolveEvent + return cls.AddMembers ( - ifaceEVt, - addBody: CreateBody(register: true), - removeBody: CreateBody(register: false), - forceInlining: true + ResolveEvent + ( + ifaceEVt, + addBody: CreateBody(register: true), + removeBody: CreateBody(register: false), + forceInlining: true + ) ); ArrowExpressionClauseSyntax CreateBody(bool register) => ArrowExpressionClause diff --git a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.MethodInterceptorFactory.cs b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.MethodInterceptorFactory.cs index f72758a5..2c07db2b 100644 --- a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.MethodInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.MethodInterceptorFactory.cs @@ -3,8 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System.Collections.Generic; - using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,8 +15,10 @@ internal partial class DuckSyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveMethods(object context) + protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) { + cls = base.ResolveMethods(cls, context); + foreach (IMethodInfo ifaceMethod in InterfaceType.Methods) { if (ifaceMethod.IsSpecial) @@ -32,16 +32,10 @@ protected override IEnumerable ResolveMethods(object co Visibility.Check(targetMethod, ContainingAssembly); - foreach (MemberDeclarationSyntax member in ResolveMethod(ifaceMethod, targetMethod)) - { - yield return member; - } + cls = ResolveMethod(cls, ifaceMethod, targetMethod); } - foreach (MemberDeclarationSyntax extra in base.ResolveMethods(context)) - { - yield return extra; - } + return cls; static bool SignatureEquals(IMemberInfo targetMember, IMemberInfo ifaceMember) => targetMember is IMethodInfo targetMethod && @@ -56,7 +50,7 @@ protected override IEnumerable ResolveMethods(object co #if DEBUG internal #endif - protected override IEnumerable ResolveMethod(object context, IMethodInfo targetMethod) + protected override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo targetMethod) { IMethodInfo ifaceMethod = (IMethodInfo) context; @@ -80,7 +74,13 @@ protected override IEnumerable ResolveMethod(object con if (ifaceMethod.ReturnValue.Kind >= ParameterKind.Ref) invocation = RefExpression(invocation); - yield return ResolveMethod(ifaceMethod, forceInlining: true) + return cls.AddMembers + ( + ResolveMethod + ( + ifaceMethod, + forceInlining: true + ) .WithExpressionBody ( expressionBody: ArrowExpressionClause(invocation) @@ -88,7 +88,8 @@ protected override IEnumerable ResolveMethod(object con .WithSemicolonToken ( Token(SyntaxKind.SemicolonToken) - ); + ) + ); } } } diff --git a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.PropertyInterceptorFactory.cs b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.PropertyInterceptorFactory.cs index 5c6006f2..5693d6cb 100644 --- a/SRC/Private/SyntaxFactories/DuckSyntaxFactory.PropertyInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/DuckSyntaxFactory.PropertyInterceptorFactory.cs @@ -3,7 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -18,7 +17,7 @@ internal partial class DuckSyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveProperties(object context) + protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) { foreach (IPropertyInfo ifaceProperty in InterfaceType.Properties) { @@ -36,12 +35,11 @@ protected override IEnumerable ResolveProperties(object checkSet: ifaceProperty.SetMethod is not null ); - foreach (MemberDeclarationSyntax member in ResolveProperty(ifaceProperty, targetProperty)) - { - yield return member; - } + cls = ResolveProperty(cls, ifaceProperty, targetProperty); } + return cls; + [SuppressMessage("Maintainability", "CA1508:Avoid dead conditional code", Justification = "There is not dead code.")] static bool SignatureEquals(IMemberInfo targetMember, IMemberInfo ifaceMember) { @@ -81,7 +79,7 @@ static bool SignatureEquals(IMemberInfo targetMember, IMemberInfo ifaceMember) #if DEBUG internal #endif - protected override IEnumerable ResolveProperty(object context, IPropertyInfo targetProperty) + protected override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo targetProperty) { IPropertyInfo ifaceProperty = (IPropertyInfo) context; @@ -121,21 +119,24 @@ protected override IEnumerable ResolveProperty(object c ) ); - yield return ifaceProperty.Indices.Some() - ? ResolveIndexer - ( - property: ifaceProperty, - getBody: getBody, - setBody: setBody, - forceInlining: true - ) - : ResolveProperty - ( - property: ifaceProperty, - getBody: getBody, - setBody: setBody, - forceInlining: true - ); + return cls.AddMembers + ( + ifaceProperty.Indices.Some() + ? ResolveIndexer + ( + property: ifaceProperty, + getBody: getBody, + setBody: setBody, + forceInlining: true + ) + : ResolveProperty + ( + property: ifaceProperty, + getBody: getBody, + setBody: setBody, + forceInlining: true + ) + ); } } } diff --git a/SRC/Private/SyntaxFactories/ModuleInitializerSyntaxFactory.cs b/SRC/Private/SyntaxFactories/ModuleInitializerSyntaxFactory.cs index 2bda4a2c..c361deb7 100644 --- a/SRC/Private/SyntaxFactories/ModuleInitializerSyntaxFactory.cs +++ b/SRC/Private/SyntaxFactories/ModuleInitializerSyntaxFactory.cs @@ -105,53 +105,41 @@ protected override IEnumerable ResolveBases(object context) #if DEBUG internal #endif - protected override IEnumerable ResolveConstructor(object context, IConstructorInfo ctor) => throw new NotImplementedException(); + protected override ClassDeclarationSyntax ResolveConstructor(ClassDeclarationSyntax cls, object context, IConstructorInfo ctor) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveConstructors(object context) - { - yield break; - } + protected override ClassDeclarationSyntax ResolveConstructors(ClassDeclarationSyntax cls, object context) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveEvent(object context, IEventInfo evt) => throw new NotImplementedException(); + protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveEvents(object context) - { - yield break; - } + protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveMethod(object context, IMethodInfo method) => throw new NotImplementedException(); + protected override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo method) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveMethods(object context) - { - yield break; - } + protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveProperties(object context) - { - yield break; - } + protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) => cls; #if DEBUG internal #endif - protected override IEnumerable ResolveProperty(object context, IPropertyInfo property) => throw new NotImplementedException(); + protected override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo property) => cls; } } \ No newline at end of file diff --git a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.Common.cs b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.Common.cs index 9718de96..8da8073d 100644 --- a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.Common.cs +++ b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.Common.cs @@ -187,7 +187,7 @@ LocalDeclarationStatementSyntax ResolveArgumentsArray(IMethodInfo method) ); /// - /// static object InvokeTarget(object target, object[] args)
+ /// (object target, object[] args) =>
/// {
/// System.Int32 cb_a = (System.Int32)args[0];
/// System.String cb_b;
@@ -200,7 +200,7 @@ LocalDeclarationStatementSyntax ResolveArgumentsArray(IMethodInfo method) #else private #endif - LocalFunctionStatementSyntax ResolveInvokeTarget(IMethodInfo method, Action, List> invocationFactory) + ParenthesizedLambdaExpressionSyntax ResolveInvokeTarget(IMethodInfo method, Action, List> invocationFactory) { ParameterSyntax target = Parameter @@ -227,29 +227,42 @@ LocalFunctionStatementSyntax ResolveInvokeTarget(IMethodInfo method, Action(), - identifier: Identifier("InvokeTarget") - ) - .WithModifiers - ( - TokenList + return + ParenthesizedLambdaExpression() + .WithParameterList ( - Token(SyntaxKind.StaticKeyword) + ParameterList + ( + new ParameterSyntax[] { target, args }.ToSyntaxList() + ) ) - ) - .WithParameterList - ( - ParameterList + .WithBody ( - new ParameterSyntax[] { target, args }.ToSyntaxList() - ) - ) - .WithBody - ( - Block(statements) - ); + Block(statements) + ); } + + /// + /// private static readonly MethodContext FXxX = new MethodContext((object target, object[] args) =>
+ /// {
+ /// System.Int32 cb_a = (System.Int32)args[0];
+ /// System.String cb_b;
+ /// TT cb_c = (TT)args[2];
+ /// ...
+ /// }); + ///
+ #if DEBUG + internal + #else + private + #endif + FieldDeclarationSyntax ResolveMethodContext(ParenthesizedLambdaExpressionSyntax lambda) => ResolveStaticGlobal + ( + $"F{lambda.GetMD5HashCode()}", + ResolveObject + ( + Argument(lambda) + ) + ); } } \ No newline at end of file diff --git a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.ConstructorFactory.cs b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.ConstructorFactory.cs index 932b4f52..704b5889 100644 --- a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.ConstructorFactory.cs +++ b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.ConstructorFactory.cs @@ -3,8 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System.Collections.Generic; - using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,26 +15,24 @@ internal partial class ProxySyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveConstructors(object context) + protected override ClassDeclarationSyntax ResolveConstructors(ClassDeclarationSyntax cls, object context) { foreach (IConstructorInfo ctor in InterceptorType.GetPublicConstructors()) { - foreach (MemberDeclarationSyntax member in ResolveConstructor(null!, ctor)) - { - yield return member; - } + cls = ResolveConstructor(cls, context, ctor); } + return cls; } #if DEBUG internal #endif - protected override IEnumerable ResolveConstructor(object context, IConstructorInfo ctor) - { - yield return ResolveConstructor + protected override ClassDeclarationSyntax ResolveConstructor(ClassDeclarationSyntax cls, object context, IConstructorInfo ctor) => cls.AddMembers + ( + ResolveConstructor ( ctor, - ResolveClassName(null!) + cls.Identifier ) .WithBody ( @@ -64,7 +60,7 @@ protected override IEnumerable ResolveConstructor(objec ) ) ) - ); - } + ) + ); } } \ No newline at end of file diff --git a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.EventInterceptorFactory.cs b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.EventInterceptorFactory.cs index c0c87d08..f2f08500 100644 --- a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.EventInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.EventInterceptorFactory.cs @@ -16,72 +16,92 @@ internal partial class ProxySyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveEvents(object context) + protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) { foreach (IEventInfo evt in InterfaceType.Events) { if (AlreadyImplemented(evt)) continue; - foreach (MemberDeclarationSyntax member in ResolveEvent(null!, evt)) - { - yield return member; - } + cls = ResolveEvent(cls, context, evt); } + + return cls; } /// - /// event EventType IInterface.Event
- /// {
- /// add
- /// {
- /// static object InvokeTarget(ITarget target, object[] args)
- /// {
- /// EventType _value = (EventType) args[0];
- /// Target.Event += _value;
- /// return null;
- /// }
- /// object[] args = new object[] { value };
- /// Invoke(new InvocationContext(args, invokeTarget));
- /// }
- /// remove
- /// {
- /// static object InvokeTarget(ITarget target, object[] args)
- /// {
- /// EventType _value = (EventType) args[0];
- /// Target.Event -= _value;
- /// return null;
- /// }
- /// object[] args = new object[] { value };
- /// Invoke(new InvocationContext(args, invokeTarget, MemberTypes.Event));
- /// }
+ /// private static readonly MethodContext FXxX = new MethodContext((ITarget target, object[] args) =>
+ /// {
+ /// EventType _value = (EventType) args[0];
+ /// Target.Event += _value;
+ /// return null;
+ /// });
+ /// private static readonly MethodContext FYyY = new MethodContext((ITarget target, object[] args) =>
+ /// {
+ /// EventType _value = (EventType) args[0];
+ /// Target.Event -= _value;
+ /// return null;
+ /// });
+ /// event EventType IInterface.Event
+ /// {
+ /// add
+ /// {
+ /// object[] args = new object[] { value };
+ /// Invoke(new InvocationContext(args, FXxX));
+ /// }
+ /// remove
+ /// {
+ /// object[] args = new object[] { value };
+ /// Invoke(new InvocationContext(args, FYyY));
+ /// }
/// } ///
#if DEBUG internal #endif - protected override IEnumerable ResolveEvent(object context, IEventInfo evt) + protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt) { - yield return ResolveEvent - ( - @event: evt, - addBody: Block + List members = new(); + + BlockSyntax? + add = null, + remove = null; + + if (evt.AddMethod is not null) + { + FieldDeclarationSyntax addCtx = BuildField(true, evt.AddMethod); + members.Add(addCtx); + + add = Block ( - BuildBody(add: true) - ), - removeBody: Block + BuildBody(true, evt.AddMethod, addCtx) + ); + } + + if (evt.RemoveMethod is not null) + { + FieldDeclarationSyntax removeCtx = BuildField(false, evt.RemoveMethod); + members.Add(removeCtx); + + remove = Block ( - BuildBody(add: false) - ) + BuildBody(false, evt.RemoveMethod, removeCtx) + ); + } + + members.Add + ( + ResolveEvent(evt, add, remove) ); - IEnumerable BuildBody(bool add) - { - IMethodInfo? method = add ? evt.AddMethod : evt.RemoveMethod; - if (method is null) - yield break; + return cls.WithMembers + ( + cls.Members.AddRange(members) + ); - LocalFunctionStatementSyntax invokeTarget = ResolveInvokeTarget + FieldDeclarationSyntax BuildField(bool add, IMethodInfo method) => ResolveMethodContext + ( + ResolveInvokeTarget ( method, (target, args, locals, body) => @@ -108,9 +128,11 @@ IEnumerable BuildBody(bool add) ReturnNull() ); } - ); - yield return invokeTarget; + ) + ); + IEnumerable BuildBody(bool add, IMethodInfo method, FieldDeclarationSyntax fld) + { LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(method); yield return argsArray; @@ -128,7 +150,7 @@ IEnumerable BuildBody(bool add) ToArgument(argsArray), Argument ( - IdentifierName(invokeTarget.Identifier) + StaticMemberAccess(cls, fld) ) ) ) diff --git a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.MethodInterceptorFactory.cs b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.MethodInterceptorFactory.cs index fa570913..fa71c5db 100644 --- a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.MethodInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.MethodInterceptorFactory.cs @@ -20,8 +20,10 @@ internal partial class ProxySyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveMethods(object context) + protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) { + cls = base.ResolveMethods(cls, context); + foreach (IMethodInfo met in InterfaceType.Methods) { if (AlreadyImplemented(met) || met.IsSpecial) @@ -34,55 +36,60 @@ protected override IEnumerable ResolveMethods(object co if (met.ReturnValue.Kind >= ParameterKind.Ref) throw new NotSupportedException(Resources.BYREF_NOT_SUPPORTED); - foreach (MemberDeclarationSyntax member in ResolveMethod(null!, met)) - { - yield return member; - } + cls = ResolveMethod(cls, context, met); } - foreach (MemberDeclarationSyntax extra in base.ResolveMethods(context)) - { - yield return extra; - } + return cls; } /// - /// TResult IInterface.Foo[TGeneric](T1 para1, ref T2 para2, out T3 para3, TGeneric para4)
+ /// private static readonly MethodContext FXxX = new MethodContext((ITarget target, object[] args) =>
/// {
- /// static object InvokeTarget(ITarget target, object[] args)
- /// {
- /// System.Int32 cb_a = (System.Int32) args[0];
- /// System.String cb_b;
- /// TT cb_c = (TT) args[2];
- /// System.Object result;
- /// result = target.Foo[TT](cb_a, out cb_b, ref cb_c);
+ /// System.Int32 cb_a = (System.Int32) args[0];
+ /// System.String cb_b;
+ /// TT cb_c = (TT) args[2];
+ /// System.Object result;
+ /// result = target.Foo[TT](cb_a, out cb_b, ref cb_c);
///
- /// args[1] = (System.Object) cb_b;
- /// args[2] = (System.Object) cb_c;
- /// return result;
- /// }
+ /// args[1] = (System.Object) cb_b;
+ /// args[2] = (System.Object) cb_c;
+ /// return result;
+ /// });
///
+ /// TResult IInterface.Foo[TGeneric](T1 para1, ref T2 para2, out T3 para3, TGeneric para4)
+ /// {
/// object[] args = new object[] {para1, para2, default(T3), para4};
///
- /// System.Object result = Invoke(new InvocationContext(args, InvokeTarget));
+ /// System.Object result = Invoke(new InvocationContext(args, FXxX));
///
/// para2 = (T2) args[1];
/// para3 = (T3) args[2];
- ///
/// return (TResult) result;
/// } ///
#if DEBUG internal #endif - protected override IEnumerable ResolveMethod(object context, IMethodInfo method) + protected override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo method) { - yield return ResolveMethod(method).WithBody + FieldDeclarationSyntax methodCtx = ResolveMethodContext ( - body: Block - ( - BuildBody() - ) + ResolveInvokeTarget(method) + ); + + return cls.AddMembers + ( + new MemberDeclarationSyntax[] + { + methodCtx, + ResolveMethod(method).WithBody + ( + body: Block + ( + BuildBody() + ) + ) + } ); IEnumerable BuildBody() @@ -90,9 +97,7 @@ IEnumerable BuildBody() List statements = new(); LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(method); - LocalFunctionStatementSyntax invokeTarget = ResolveInvokeTarget(method); - statements.Add(invokeTarget); statements.Add(argsArray); InvocationExpressionSyntax invocation = InvokeMethod @@ -107,7 +112,7 @@ IEnumerable BuildBody() ToArgument(argsArray), Argument ( - IdentifierName(invokeTarget.Identifier) + StaticMemberAccess(cls, methodCtx) ) ) ) @@ -259,7 +264,7 @@ IEnumerable ReassignArgsArray(IMethodInfo method, ParameterSynt } ///
- /// static object InvokeTarget(ITarget target, object[] args)
+ /// (ITarget target, object[] args) =>
/// {
/// System.Int32 cb_a = (System.Int32) args[0];
/// System.String cb_b;
@@ -277,7 +282,7 @@ IEnumerable ReassignArgsArray(IMethodInfo method, ParameterSynt #else private #endif - LocalFunctionStatementSyntax ResolveInvokeTarget(IMethodInfo method) => ResolveInvokeTarget(method, (target, args, locals, body) => + ParenthesizedLambdaExpressionSyntax ResolveInvokeTarget(IMethodInfo method) => ResolveInvokeTarget(method, (target, args, locals, body) => { InvocationExpressionSyntax invocation = InvokeMethod ( diff --git a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.PropertyInterceptorFactory.cs b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.PropertyInterceptorFactory.cs index bc3745c6..dc8d5daf 100644 --- a/SRC/Private/SyntaxFactories/ProxySyntaxFactory.PropertyInterceptorFactory.cs +++ b/SRC/Private/SyntaxFactories/ProxySyntaxFactory.PropertyInterceptorFactory.cs @@ -3,7 +3,6 @@ * * * Author: Denes Solti * ********************************************************************************/ -using System; using System.Collections.Generic; using Microsoft.CodeAnalysis.CSharp; @@ -18,106 +17,106 @@ internal partial class ProxySyntaxFactory #if DEBUG internal #endif - protected override IEnumerable ResolveProperties(object context) + protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) { foreach (IPropertyInfo prop in InterfaceType.Properties) { if (AlreadyImplemented(prop)) continue; - foreach (MemberDeclarationSyntax member in ResolveProperty(null!, prop)) - { - yield return member; - } + cls = ResolveProperty(cls, context, prop); } + + return cls; } /// - /// TResult IInterface.Prop
- /// {
- /// get
- /// {
- /// static object InvokeTarget(ITarget target, object[] args)
- /// {
- /// return target.Prop;
- /// }
- /// object[] args = new object[] { };
- /// return (TResult) Invoke(new InvocationContext(args, InvokeTarget));
- /// }
- /// set
- /// {
- /// static object InvokeTarget(ITarget target, object[] args)
- /// {
- /// TValue _value = (TValue) args[0];
- /// target.Prop = _value;
- /// return null;
- /// }
- /// object[] args = new object[] { value };
- /// Invoke(new InvocationContext(args, InvokeTarget, MemberTypes.Property));
- /// }
+ /// private static readonly MethodContext FxXx = new MethodContext((ITarget target, object[] args) =>
+ /// {
+ /// return target.Prop;
+ /// });
+ /// private static readonly MethodContext FyYy = new MethodContext((ITarget target, object[] args) =>
+ /// {
+ /// TValue _value = (TValue) args[0];
+ /// target.Prop = _value;
+ /// return null;
+ /// });
+ /// TResult IInterface.Prop
+ /// {
+ /// get
+ /// {
+ /// object[] args = new object[] { };
+ /// return (TResult) Invoke(new InvocationContext(args, FxXx));
+ /// }
+ /// set
+ /// {
+ /// object[] args = new object[] { value };
+ /// Invoke(new InvocationContext(args, FyYy));
+ /// }
/// } ///
#if DEBUG internal #endif - protected override IEnumerable ResolveProperty(object context, IPropertyInfo property) + protected override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo property) { - yield return BuildProperty - ( - property.Indices.Some() ? ResolveIndexer : ResolveProperty - ); + List members = new(); - IEnumerable BuildGet() - { - if (property.GetMethod is null) - yield break; + BlockSyntax? + get = null, + set = null; - LocalFunctionStatementSyntax invokeTarget = ResolveInvokeTarget + if (property.GetMethod is not null) + { + FieldDeclarationSyntax getCtx = ResolveMethodContext ( - property.GetMethod, - (target, args, locals, body) => body.Add + ResolveInvokeTarget ( - ReturnResult + property.GetMethod, + (target, args, locals, body) => body.Add ( - null, - CastExpression + ReturnResult ( - ResolveType(), - PropertyAccess + null, + CastExpression ( - property, - IdentifierName(target.Identifier), - castTargetTo: property.DeclaringType, - locals.Convert(ToArgument) + ResolveType(), + PropertyAccess + ( + property, + IdentifierName(target.Identifier), + castTargetTo: property.DeclaringType, + indices: locals.Convert(ToArgument) + ) ) ) - ) + ) ) ); - yield return invokeTarget; + members.Add(getCtx); LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(property.GetMethod); - yield return argsArray; - yield return ReturnResult + get = Block ( - property.Type, - InvokeMethod + argsArray, + ReturnResult ( - Invoke, - target: null, - castTargetTo: null, - Argument + property.Type, + InvokeMethod ( - ResolveObject + Invoke, + target: null, + castTargetTo: null, + Argument ( - ToArgument(argsArray), - Argument + ResolveObject ( - IdentifierName + ToArgument(argsArray), + Argument ( - invokeTarget.Identifier + StaticMemberAccess(cls, getCtx) ) ) ) @@ -126,66 +125,66 @@ IEnumerable BuildGet() ); } - IEnumerable BuildSet() + if (property.SetMethod is not null) { - if (property.SetMethod is null) - yield break; - - LocalFunctionStatementSyntax invokeTarget = ResolveInvokeTarget + FieldDeclarationSyntax setCtx = ResolveMethodContext ( - property.SetMethod, - (target, args, locals, body) => - { - body.Add - ( - ExpressionStatement + ResolveInvokeTarget + ( + property.SetMethod, + (target, args, locals, body) => + { + body.Add ( - expression: AssignmentExpression + ExpressionStatement ( - kind: SyntaxKind.SimpleAssignmentExpression, - left: PropertyAccess + expression: AssignmentExpression ( - property, - IdentifierName(target.Identifier), - castTargetTo: property.DeclaringType, - locals.Convert + kind: SyntaxKind.SimpleAssignmentExpression, + left: PropertyAccess ( - (local, _) => ToArgument(local), - (_, i) => i == locals.Count - 1 - ) - ), - right: ToIdentifierName(locals[locals.Count - 1]) + property, + IdentifierName(target.Identifier), + castTargetTo: property.DeclaringType, + indices: locals.Convert + ( + (local, _) => ToArgument(local), + (_, i) => i == locals.Count - 1 + ) + ), + right: ToIdentifierName(locals[locals.Count - 1]) + ) ) - ) - ); - body.Add - ( - ReturnNull() - ); - } + ); + body.Add + ( + ReturnNull() + ); + } + ) ); - yield return invokeTarget; + members.Add(setCtx); LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(property.SetMethod); - yield return argsArray; - yield return ExpressionStatement + set = Block ( - InvokeMethod + argsArray, + ExpressionStatement ( - Invoke, - target: null, - castTargetTo: null, - Argument + InvokeMethod ( - ResolveObject + Invoke, + target: null, + castTargetTo: null, + Argument ( - ToArgument(argsArray), - Argument + ResolveObject ( - IdentifierName + ToArgument(argsArray), + Argument ( - invokeTarget.Identifier + StaticMemberAccess(cls, setCtx) ) ) ) @@ -194,23 +193,16 @@ IEnumerable BuildSet() ); } - // - // Nem gond ha mondjuk az interface property-nek nincs gettere, akkor a "getBody" - // figyelmen kivul lesz hagyva. - // + members.Add + ( + property.Indices.Some() + ? ResolveIndexer(property, get, set, false) + : ResolveProperty(property, get, set, false) + ); - BasePropertyDeclarationSyntax BuildProperty(Func fact) => fact + return cls.WithMembers ( - property, - Block - ( - BuildGet() - ), - Block - ( - BuildSet() - ), - false + cls.Members.AddRange(members) ); } } diff --git a/SRC/Private/SyntaxFactories/ProxyUnitSyntaxFactory.cs b/SRC/Private/SyntaxFactories/ProxyUnitSyntaxFactory.cs index 17d0516b..b73db70f 100644 --- a/SRC/Private/SyntaxFactories/ProxyUnitSyntaxFactory.cs +++ b/SRC/Private/SyntaxFactories/ProxyUnitSyntaxFactory.cs @@ -33,14 +33,14 @@ internal abstract class ProxyUnitSyntaxFactory : UnitSyntaxFactoryBase #if DEBUG internal #endif - protected override IEnumerable ResolveMethods(object context) - { + protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) => cls.AddMembers + ( // // [ModuleInitializerAttribute] // public static void Initialize() => RegisterInstance(typeof(CurrentClass)); // - yield return MethodDeclaration + MethodDeclaration ( ResolveType ( @@ -95,10 +95,7 @@ protected override IEnumerable ResolveMethods(object co ( Token(SyntaxKind.GlobalKeyword) ), - IdentifierName - ( - ResolveClassName(context) - ) + IdentifierName(cls.Identifier) ) ) ) @@ -108,7 +105,7 @@ protected override IEnumerable ResolveMethods(object co .WithSemicolonToken ( Token(SyntaxKind.SemicolonToken) - ); - } + ) + ); } } \ No newline at end of file diff --git a/SRC/Private/SyntaxFactories/UnitSyntaxFactoryBase.cs b/SRC/Private/SyntaxFactories/UnitSyntaxFactoryBase.cs index 16b506cd..553180d9 100644 --- a/SRC/Private/SyntaxFactories/UnitSyntaxFactoryBase.cs +++ b/SRC/Private/SyntaxFactories/UnitSyntaxFactoryBase.cs @@ -36,7 +36,7 @@ internal abstract class UnitSyntaxFactoryBase : ClassSyntaxFactoryBase #if DEBUG internal #endif - protected abstract IEnumerable ResolveClasses(object context, CancellationToken cancellation); + protected abstract IEnumerable ResolveClasses(object context, CancellationToken cancellation); // TODO: take and return the unit being assembled public OutputType OutputType { get; } @@ -114,7 +114,7 @@ public virtual CompilationUnitSyntax ResolveUnit(object context, CancellationTok #if DEBUG internal #endif - protected virtual IEnumerable ResolveUnitMembers(object context, CancellationToken cancellation) => ResolveClasses(context, cancellation).Convert + protected virtual IEnumerable ResolveUnitMembers(object context, CancellationToken cancellation) => ResolveClasses(context, cancellation).Convert // TODO: take and return the unit being assembled ( cls => cls.WithAttributeLists ( diff --git a/SRC/Properties/Resources.Designer.cs b/SRC/Properties/Resources.Designer.cs index 2dea3783..b3491482 100644 --- a/SRC/Properties/Resources.Designer.cs +++ b/SRC/Properties/Resources.Designer.cs @@ -186,15 +186,6 @@ internal class Resources { } } - /// - /// Looks up a localized string similar to The provided delegate must refer a static method.. - /// - internal static string NOT_STATIC { - get { - return ResourceManager.GetString("NOT_STATIC", resourceCulture); - } - } - /// /// Looks up a localized string similar to The target is NULL.. /// diff --git a/SRC/Properties/Resources.resx b/SRC/Properties/Resources.resx index 057b96a9..2c60c13a 100644 --- a/SRC/Properties/Resources.resx +++ b/SRC/Properties/Resources.resx @@ -156,9 +156,6 @@ The parameter must be a Generator descendant. - - The provided delegate must refer a static method. - At least one public constructor should be declared on {0}. diff --git a/SRC/Properties/SGResources.Designer.cs b/SRC/Properties/SGResources.Designer.cs index 4d89ad63..d1bd9533 100644 --- a/SRC/Properties/SGResources.Designer.cs +++ b/SRC/Properties/SGResources.Designer.cs @@ -61,7 +61,7 @@ internal class SGResources { } /// - /// Looks up a localized string similar to Type embedding is supported only in C# 8+ compilations.. + /// Looks up a localized string similar to Type embedding is supported only in C# 7+ compilations.. /// internal static string LNG_NOT_SUPPORTED { get { diff --git a/SRC/Properties/SGResources.resx b/SRC/Properties/SGResources.resx index 3c3a1e57..82630ad4 100644 --- a/SRC/Properties/SGResources.resx +++ b/SRC/Properties/SGResources.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Type embedding is supported only in C# 8+ compilations. + Type embedding is supported only in C# 7+ compilations. {0} is not a generator diff --git a/SRC/Public/InvocationContext.cs b/SRC/Public/InvocationContext.cs index 07752c73..b37422ed 100644 --- a/SRC/Public/InvocationContext.cs +++ b/SRC/Public/InvocationContext.cs @@ -5,44 +5,26 @@ ********************************************************************************/ using System; using System.Diagnostics.CodeAnalysis; -using System.Reflection; namespace Solti.Utils.Proxy { - using Internals; - using Properties; - /// - /// Describes the method invocation context. + /// Describes a method invocation context. /// - public class InvocationContext + public class InvocationContext : MethodContext { +#if DEBUG /// /// Creates a new instance. /// - public InvocationContext(object?[] args, Func dispatch) - { - if (args is null) - throw new ArgumentNullException(nameof(args)); - - if (dispatch is null) - throw new ArgumentNullException(nameof(dispatch)); - - if (dispatch.Target is not null) - throw new ArgumentException(Resources.NOT_STATIC, nameof(dispatch)); - - ExtendedMemberInfo memberInfo = MemberInfoExtensions.ExtractFrom(dispatch); - - Member = memberInfo.Member; - Method = memberInfo.Method; - Args = args; - Dispatch = dispatch; - } - + public InvocationContext(object?[] args, Func dispatch): base(dispatch) + => Args = args ?? throw new ArgumentNullException(nameof(args)); +#endif /// - /// The interface method being invoked. + /// Creates a new instance. /// - public MethodInfo Method { get; } + public InvocationContext(object?[] args, MethodContext methodContext): base(methodContext) + => Args = args ?? throw new ArgumentNullException(nameof(args)); /// /// The arguments passed by the caller. @@ -50,15 +32,5 @@ public InvocationContext(object?[] args, Func dispat /// Before the gets called you may use this property to inspect or modify parameters passed by the caller. After it you can read or amend the "by ref" parameters set by the target method. [SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "End user is allowed to modify the argument list.")] public object?[] Args { get; } - - /// - /// The concrete member that is being invoked (e.g.: property or event) - /// - public MemberInfo Member { get; } - - /// - /// Gets the dispatcher function. - /// - public Func Dispatch { get; } } } diff --git a/SRC/Public/MethodContext.cs b/SRC/Public/MethodContext.cs new file mode 100644 index 00000000..e1e373aa --- /dev/null +++ b/SRC/Public/MethodContext.cs @@ -0,0 +1,62 @@ +/******************************************************************************** +* MethodContext.cs * +* * +* Author: Denes Solti * +********************************************************************************/ +using System; +using System.Reflection; + +namespace Solti.Utils.Proxy +{ + using Internals; + + /// + /// Describes a method context. + /// + public class MethodContext + { + /// + /// Creates a new instance. + /// + /// Calling this constructor is time consuming operation. It is strongly advised to cache the created instances. + public MethodContext(Func dispatch) + { + if (dispatch is null) + throw new ArgumentNullException(nameof(dispatch)); + + ExtendedMemberInfo memberInfo = MemberInfoExtensions.ExtractFrom(dispatch); + + Member = memberInfo.Member; + Method = memberInfo.Method; + Dispatch = dispatch; + } + + /// + /// Creates a copy from the given source. + /// + protected MethodContext(MethodContext src) + { + if (src is null) + throw new ArgumentNullException(nameof(src)); + + Member = src.Member; + Method = src.Method; + Dispatch = src.Dispatch; + } + + /// + /// The concrete method behind the . + /// + public MethodInfo Method { get; } + + /// + /// The member (property, event or method) that is being invoked. + /// + public MemberInfo Member { get; } + + /// + /// Gets the dispatcher function. + /// + public Func Dispatch { get; } + } +} diff --git a/TEST/ProxyGen.Tests/BarSrc.txt b/TEST/ProxyGen.Tests/BarSrc.txt index fbd2cf63..52fd3be9 100644 --- a/TEST/ProxyGen.Tests/BarSrc.txt +++ b/TEST/ProxyGen.Tests/BarSrc.txt @@ -1,11 +1,5 @@ void global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Bar() { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Bar(); - return null; - } - global::System.Object[] args = new global::System.Object[0]; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.FBE6746071B49CF0F5B141E37FF16623F)); } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/CallbackSrc.txt b/TEST/ProxyGen.Tests/CallbackSrc.txt index ad5032c1..a87939b7 100644 --- a/TEST/ProxyGen.Tests/CallbackSrc.txt +++ b/TEST/ProxyGen.Tests/CallbackSrc.txt @@ -1,4 +1,4 @@ -static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) +(global::System.Object target, global::System.Object[] args) => { global::System.Int32 _a = (global::System.Int32)args[0]; global::System.String _b; diff --git a/TEST/ProxyGen.Tests/ClsSrcModule.txt b/TEST/ProxyGen.Tests/ClsSrcModule.txt index 9a6ef446..2ba5a14c 100644 --- a/TEST/ProxyGen.Tests/ClsSrcModule.txt +++ b/TEST/ProxyGen.Tests/ClsSrcModule.txt @@ -6,93 +6,87 @@ internal sealed class Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A : global::Solti.Uti this.Proxy = this; } + [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A)); + private static readonly global::Solti.Utils.Proxy.MethodContext FBD8C74C6501C257EC01888B1DE3E00C5 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::System.Int32 _a = (global::System.Int32)args[0]; + global::System.String _b; + TT _c = (TT)args[2]; + global::System.Object result = (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Foo(_a, out _b, ref _c); + args[1] = (global::System.Object)_b; + args[2] = (global::System.Object)_c; + return result; + }); global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _a = (global::System.Int32)args[0]; - global::System.String _b; - TT _c = (TT)args[2]; - global::System.Object result = (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Foo(_a, out _b, ref _c); - args[1] = (global::System.Object)_b; - args[2] = (global::System.Object)_c; - return result; - } - global::System.Object[] args = new global::System.Object[]{a, default(global::System.String), c}; - global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FBD8C74C6501C257EC01888B1DE3E00C5)); b = (global::System.String)args[1]; c = (TT)args[2]; return (global::System.Int32)result; } + private static readonly global::Solti.Utils.Proxy.MethodContext FBE6746071B49CF0F5B141E37FF16623F = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Bar(); + return null; + }); void global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Bar() { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Bar(); - return null; - } - global::System.Object[] args = new global::System.Object[0]; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FBE6746071B49CF0F5B141E37FF16623F)); } - [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] - public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A)); + private static readonly global::Solti.Utils.Proxy.MethodContext F755C2698896018328EFD13B61AFD0E55 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + return (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop; + }); + private static readonly global::Solti.Utils.Proxy.MethodContext FEAC27D4EA67E99044A479C702933F88A = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::System.Int32 _value = (global::System.Int32)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop = _value; + return null; + }); global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Prop { get { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - return (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop; - } - global::System.Object[] args = new global::System.Object[0]; - return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.F755C2698896018328EFD13B61AFD0E55)); } set { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _value = (global::System.Int32)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop = _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FEAC27D4EA67E99044A479C702933F88A)); } } + private static readonly global::Solti.Utils.Proxy.MethodContext FE368ED8AFE215C30F18F06E03592AACA = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event += _value; + return null; + }); + private static readonly global::Solti.Utils.Proxy.MethodContext F9750C1B0E32217DBCD60481B48459A44 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event -= _value; + return null; + }); event global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Event { add { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event += _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FE368ED8AFE215C30F18F06E03592AACA)); } remove { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event -= _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.F9750C1B0E32217DBCD60481B48459A44)); } } } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/ClsSrcUnit.txt b/TEST/ProxyGen.Tests/ClsSrcUnit.txt index 74597522..7b95cc02 100644 --- a/TEST/ProxyGen.Tests/ClsSrcUnit.txt +++ b/TEST/ProxyGen.Tests/ClsSrcUnit.txt @@ -7,93 +7,87 @@ internal sealed class Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A : global::Solti.Uti this.Proxy = this; } + [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A)); + private static readonly global::Solti.Utils.Proxy.MethodContext FBD8C74C6501C257EC01888B1DE3E00C5 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::System.Int32 _a = (global::System.Int32)args[0]; + global::System.String _b; + TT _c = (TT)args[2]; + global::System.Object result = (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Foo(_a, out _b, ref _c); + args[1] = (global::System.Object)_b; + args[2] = (global::System.Object)_c; + return result; + }); global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _a = (global::System.Int32)args[0]; - global::System.String _b; - TT _c = (TT)args[2]; - global::System.Object result = (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Foo(_a, out _b, ref _c); - args[1] = (global::System.Object)_b; - args[2] = (global::System.Object)_c; - return result; - } - global::System.Object[] args = new global::System.Object[]{a, default(global::System.String), c}; - global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FBD8C74C6501C257EC01888B1DE3E00C5)); b = (global::System.String)args[1]; c = (TT)args[2]; return (global::System.Int32)result; } + private static readonly global::Solti.Utils.Proxy.MethodContext FBE6746071B49CF0F5B141E37FF16623F = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Bar(); + return null; + }); void global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Bar() { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Bar(); - return null; - } - global::System.Object[] args = new global::System.Object[0]; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FBE6746071B49CF0F5B141E37FF16623F)); } - [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] - public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A)); + private static readonly global::Solti.Utils.Proxy.MethodContext F755C2698896018328EFD13B61AFD0E55 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + return (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop; + }); + private static readonly global::Solti.Utils.Proxy.MethodContext FEAC27D4EA67E99044A479C702933F88A = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::System.Int32 _value = (global::System.Int32)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop = _value; + return null; + }); global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Prop { get { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - return (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop; - } - global::System.Object[] args = new global::System.Object[0]; - return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.F755C2698896018328EFD13B61AFD0E55)); } set { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _value = (global::System.Int32)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop = _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FEAC27D4EA67E99044A479C702933F88A)); } } + private static readonly global::Solti.Utils.Proxy.MethodContext FE368ED8AFE215C30F18F06E03592AACA = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event += _value; + return null; + }); + private static readonly global::Solti.Utils.Proxy.MethodContext F9750C1B0E32217DBCD60481B48459A44 = new global::Solti.Utils.Proxy.MethodContext((global::System.Object target, global::System.Object[] args) => + { + global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; + ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event -= _value; + return null; + }); event global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Event { add { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event += _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.FE368ED8AFE215C30F18F06E03592AACA)); } remove { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event -= _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Proxy_10FC5DBDBA8C97EBE529724F5CB55A8A.F9750C1B0E32217DBCD60481B48459A44)); } } } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/DuckClsSrc.txt b/TEST/ProxyGen.Tests/DuckClsSrc.txt index 44b09d97..9a43e4e1 100644 --- a/TEST/ProxyGen.Tests/DuckClsSrc.txt +++ b/TEST/ProxyGen.Tests/DuckClsSrc.txt @@ -5,12 +5,12 @@ internal sealed class Duck_2648115D0AA68B747DBE21865A3A6FC2 : global::Solti.Util { } + [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Duck_2648115D0AA68B747DBE21865A3A6FC2)); [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) => this.Target.Foo(a, out b, ref c); [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] void global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Bar() => this.Target.Bar(); - [global::System.Runtime.CompilerServices.ModuleInitializerAttribute] - public static void Initialize() => global::Solti.Utils.Proxy.Internals.GeneratedClass.RegisterInstance(typeof(global::Duck_2648115D0AA68B747DBE21865A3A6FC2)); global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Prop {[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => this.Target.Prop; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] set => this.Target.Prop = value; } diff --git a/TEST/ProxyGen.Tests/EventSrc.txt b/TEST/ProxyGen.Tests/EventSrc.txt index a563a0b4..0f518240 100644 --- a/TEST/ProxyGen.Tests/EventSrc.txt +++ b/TEST/ProxyGen.Tests/EventSrc.txt @@ -2,27 +2,13 @@ event global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.Tes { add { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event += _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.FE368ED8AFE215C30F18F06E03592AACA)); } remove { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate _value = (global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Event -= _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.F9750C1B0E32217DBCD60481B48459A44)); } } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/FooSrc.txt b/TEST/ProxyGen.Tests/FooSrc.txt index b0f158eb..304b9e5b 100644 --- a/TEST/ProxyGen.Tests/FooSrc.txt +++ b/TEST/ProxyGen.Tests/FooSrc.txt @@ -1,18 +1,7 @@ global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _a = (global::System.Int32)args[0]; - global::System.String _b; - TT _c = (TT)args[2]; - global::System.Object result = (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Foo(_a, out _b, ref _c); - args[1] = (global::System.Object)_b; - args[2] = (global::System.Object)_c; - return result; - } - global::System.Object[] args = new global::System.Object[]{a, default(global::System.String), c}; - global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + global::System.Object result = this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.FBD8C74C6501C257EC01888B1DE3E00C5)); b = (global::System.String)args[1]; c = (TT)args[2]; return (global::System.Int32)result; diff --git a/TEST/ProxyGen.Tests/IndexerSrc.txt b/TEST/ProxyGen.Tests/IndexerSrc.txt index f413f3d6..e9dba6ca 100644 --- a/TEST/ProxyGen.Tests/IndexerSrc.txt +++ b/TEST/ProxyGen.Tests/IndexerSrc.txt @@ -2,27 +2,13 @@ global::System.Int32 global::System.Collections.Generic.IList)target)[_index]; - } - global::System.Object[] args = new global::System.Object[]{index}; - return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.FBFF56FABEFCB6BD102F55C5BE5489C64)); } set { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _index = (global::System.Int32)args[0]; - global::System.Int32 _value = (global::System.Int32)args[1]; - ((global::System.Collections.Generic.IList)target)[_index] = _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{index, value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.F4610197BDE6BFC09D39D5B2CE17A10EC)); } } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/PropSrc.txt b/TEST/ProxyGen.Tests/PropSrc.txt index a20cfca0..3ce99fe6 100644 --- a/TEST/ProxyGen.Tests/PropSrc.txt +++ b/TEST/ProxyGen.Tests/PropSrc.txt @@ -2,25 +2,13 @@ global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFacto { get { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - return (global::System.Object)((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop; - } - global::System.Object[] args = new global::System.Object[0]; - return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + return (global::System.Int32)this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.F755C2698896018328EFD13B61AFD0E55)); } set { - static global::System.Object InvokeTarget(global::System.Object target, global::System.Object[] args) - { - global::System.Int32 _value = (global::System.Int32)args[0]; - ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)target).Prop = _value; - return null; - } - global::System.Object[] args = new global::System.Object[]{value}; - this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, InvokeTarget)); + this.Invoke(new global::Solti.Utils.Proxy.InvocationContext(args, global::Dummy.FEAC27D4EA67E99044A479C702933F88A)); } } \ No newline at end of file diff --git a/TEST/ProxyGen.Tests/SyntaxFactories/ClassSyntaxFactoryBase.cs b/TEST/ProxyGen.Tests/SyntaxFactories/ClassSyntaxFactoryBase.cs index 89c8e7aa..2982da1f 100644 --- a/TEST/ProxyGen.Tests/SyntaxFactories/ClassSyntaxFactoryBase.cs +++ b/TEST/ProxyGen.Tests/SyntaxFactories/ClassSyntaxFactoryBase.cs @@ -30,21 +30,21 @@ private sealed class ClassSyntaxFactory : ClassSyntaxFactoryBase protected internal override string ResolveClassName(object context) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveConstructor(object context, IConstructorInfo ctor) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveConstructor(ClassDeclarationSyntax cls, object context, IConstructorInfo ctor) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveConstructors(object context) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveConstructors(ClassDeclarationSyntax cls, object context) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveEvent(object context, IEventInfo evt) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveEvents(object context) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveMethod(object context, IMethodInfo method) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo method) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveMethods(object context) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveProperties(object context) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) => throw new NotImplementedException(); - protected internal override IEnumerable ResolveProperty(object context, IPropertyInfo property) => throw new NotImplementedException(); + protected internal override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo property) => throw new NotImplementedException(); } diff --git a/TEST/ProxyGen.Tests/SyntaxFactories/DuckSyntaxFactory.cs b/TEST/ProxyGen.Tests/SyntaxFactories/DuckSyntaxFactory.cs index 9ed75701..9910b597 100644 --- a/TEST/ProxyGen.Tests/SyntaxFactories/DuckSyntaxFactory.cs +++ b/TEST/ProxyGen.Tests/SyntaxFactories/DuckSyntaxFactory.cs @@ -12,6 +12,9 @@ using System.Threading; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + using NUnit.Framework; namespace Solti.Utils.Proxy.SyntaxFactories.Tests @@ -25,6 +28,8 @@ namespace Solti.Utils.Proxy.SyntaxFactories.Tests [TestFixture, Parallelizable(ParallelScope.All)] public sealed class DuckSyntaxFactoryTests : SyntaxFactoryTestsBase { + private static ClassDeclarationSyntax GetDummyClass() => SyntaxFactory.ClassDeclaration("Dummy"); + public sealed class BadFoo { public int Foo(int a, out string b, TT c) => (b = string.Empty).GetHashCode(); // nincs ref @@ -64,14 +69,14 @@ public void Bar() public void ResolveMethod_ShouldThrowIfTheMethodNotSupported() => Assert.Throws ( - () => CreateGenerator, BadFoo>().ResolveMethods(default).ToList(), + () => CreateGenerator, BadFoo>().ResolveMethods(GetDummyClass(), default), Resources.MISSING_IMPLEMENTATION ); [Test] public void ResolveMethod_ShouldGenerateTheDesiredMethodIfSupported() { - Assert.That(CreateGenerator, GoodFoo>().ResolveMethods(null).Any(m => m.NormalizeWhitespace(eol: "\n").ToFullString().Equals("[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]\nglobal::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) => this.Target.Foo(a, out b, ref c);"))); + Assert.That(CreateGenerator, GoodFoo>().ResolveMethods(GetDummyClass(), null).Members.Any(m => m.NormalizeWhitespace(eol: "\n").ToFullString().Equals("[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]\nglobal::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) => this.Target.Foo(a, out b, ref c);"))); } public class ExplicitFoo : IFoo @@ -89,35 +94,35 @@ public class ExplicitFoo : IFoo [Test] public void ResolveMethod_ShouldHandleExplicitImplementations() { - Assert.That(CreateGenerator, ExplicitFoo>().ResolveMethods(null).Any(m => m.NormalizeWhitespace(eol: "\n").ToFullString().Equals("[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]\nglobal::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) => ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)this.Target).Foo(a, out b, ref c);"))); + Assert.That(CreateGenerator, ExplicitFoo>().ResolveMethods(GetDummyClass(), null).Members.Any(m => m.NormalizeWhitespace(eol: "\n").ToFullString().Equals("[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]\nglobal::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Foo(global::System.Int32 a, out global::System.String b, ref TT c) => ((global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo)this.Target).Foo(a, out b, ref c);"))); } [Test] public void ResolveProperty_ShouldThrowIfThePropertyNotSupported() => Assert.Throws ( - () => CreateGenerator, BadFoo>().ResolveProperties(default).ToList(), + () => CreateGenerator, BadFoo>().ResolveProperties(GetDummyClass(), default), Resources.MISSING_IMPLEMENTATION ); [Test] public void ResolveProperty_ShouldGenerateTheDesiredPropertyIfSupported() { - Assert.That(CreateGenerator, GoodFoo>().ResolveProperties(default).Any(m => m.NormalizeWhitespace(eol: " ").ToFullString().Equals("global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Prop {[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => this.Target.Prop; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] set => this.Target.Prop = value; }"))); + Assert.That(CreateGenerator, GoodFoo>().ResolveProperties(GetDummyClass(), default).Members.Any(m => m.NormalizeWhitespace(eol: " ").ToFullString().Equals("global::System.Int32 global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Prop {[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => this.Target.Prop; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] set => this.Target.Prop = value; }"))); } [Test] public void ResolveEvent_ShouldThrowIfTheEventNotSupported() => Assert.Throws ( - () => CreateGenerator, BadFoo>().ResolveEvents(default).ToList(), + () => CreateGenerator, BadFoo>().ResolveEvents(GetDummyClass(), default), Resources.MISSING_IMPLEMENTATION ); [Test] public void ResolveEvent_ShouldGenerateTheDesiredEventIfSupported() { - Assert.That(CreateGenerator, GoodFoo>().ResolveEvents(null).Any(m => m.NormalizeWhitespace(eol: " ").ToFullString().Equals("event global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Event {[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] add => this.Target.Event += value; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] remove => this.Target.Event -= value; }"))); + Assert.That(CreateGenerator, GoodFoo>().ResolveEvents(GetDummyClass(), null).Members.Any(m => m.NormalizeWhitespace(eol: " ").ToFullString().Equals("event global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.TestDelegate global::Solti.Utils.Proxy.SyntaxFactories.Tests.SyntaxFactoryTestsBase.IFoo.Event {[global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] add => this.Target.Event += value; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] remove => this.Target.Event -= value; }"))); } [Test] @@ -128,7 +133,7 @@ public void ResolveUnit_ShouldGenerateTheDesiredClass() [Test] public void ResolveProperty_ShouldThrowOnAmbiguousImplementation() => - Assert.Throws(() => CreateGenerator, List>().ResolveProperties(default).ToList()); + Assert.Throws(() => CreateGenerator, List>().ResolveProperties(GetDummyClass(), default)); public static IEnumerable RandomInterfaces => Proxy.Tests.RandomInterfaces.Values.Except(new[] { typeof(ITypeLib2), typeof(ITypeInfo2) }); diff --git a/TEST/ProxyGen.Tests/SyntaxFactories/ProxySyntaxFactory.cs b/TEST/ProxyGen.Tests/SyntaxFactories/ProxySyntaxFactory.cs index 8a5d6f4e..01a01893 100644 --- a/TEST/ProxyGen.Tests/SyntaxFactories/ProxySyntaxFactory.cs +++ b/TEST/ProxyGen.Tests/SyntaxFactories/ProxySyntaxFactory.cs @@ -28,6 +28,8 @@ namespace Solti.Utils.Proxy.SyntaxFactories.Tests [TestFixture, Parallelizable(ParallelScope.All)] public sealed class ProxySyntaxFactoryTests : SyntaxFactoryTestsBase { + private static ClassDeclarationSyntax GetDummyClass() => ClassDeclaration("Dummy"); + internal class FooInterceptor : InterfaceInterceptor> // direkt internal { public FooInterceptor(IFoo target) : base(target) @@ -150,43 +152,39 @@ public void ReturnResult_ShouldCreateTheProperExpression((Type Type, string Loca [TestCaseSource(nameof(Methods))] public void ResolveMethod_ShouldGenerateTheProperInterceptor((object Method, string File) para) { - MemberDeclarationSyntax[] methods = CreateGenerator(OutputType.Module).ResolveMethods(null).ToArray(); + SyntaxList methods = CreateGenerator(OutputType.Module).ResolveMethods(GetDummyClass(), null).Members; - Assert.That(methods.Count, Is.EqualTo(3)); Assert.That(methods.Any(member => member.NormalizeWhitespace(eol: "\n").ToFullString().Equals(File.ReadAllText(para.File)))); } [Test] public void ResolveProperty_ShouldGenerateTheProperInterceptor() { - MemberDeclarationSyntax[] props = CreateGenerator(OutputType.Module).ResolveProperties(null).ToArray(); + SyntaxList props = CreateGenerator(OutputType.Module).ResolveProperties(GetDummyClass(), null).Members; - Assert.That(props.Count, Is.EqualTo(1)); Assert.That(props.Any(member => member.NormalizeWhitespace(eol: "\n").ToFullString().Equals(File.ReadAllText("PropSrc.txt")))); } [Test] public void ResolveProperty_ShouldGenerateTheIndexerInterceptor() { - MemberDeclarationSyntax[] props = new ProxySyntaxFactory + SyntaxList props = new ProxySyntaxFactory ( MetadataTypeInfo.CreateFrom(typeof(IList)), MetadataTypeInfo.CreateFrom(typeof(InterfaceInterceptor>)), "cica", OutputType.Module, null - ).ResolveProperties(null).ToArray(); + ).ResolveProperties(GetDummyClass(), null).Members; - Assert.That(props.Count, Is.EqualTo(3)); Assert.That(props.Any(member => member.NormalizeWhitespace(eol: "\n").ToFullString().Equals(File.ReadAllText("IndexerSrc.txt")))); } [Test] public void GenerateProxyEvent_Test() { - MemberDeclarationSyntax[] evts = CreateGenerator(OutputType.Module).ResolveEvents(null).ToArray(); + SyntaxList evts = CreateGenerator(OutputType.Module).ResolveEvents(GetDummyClass(), null).Members; - Assert.That(evts.Count, Is.EqualTo(1)); Assert.That(evts.Any(member => member.NormalizeWhitespace(eol: "\n").ToFullString().Equals(File.ReadAllText("EventSrc.txt")))); }