From eb84beaa4f8f89b2931e82706973dde476c96505 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 00:24:28 +0100 Subject: [PATCH 01/11] Fix: Throw on generic context GetTypeArgument --- .../Signatures/GenericContext.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index 79571b830..e20c1d0bb 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -4,7 +4,7 @@ namespace AsmResolver.DotNet.Signatures { /// - /// Provides a context within a generic instantiation, including the type arguments of the enclosing type and method. + /// Provides a context within a generic instantiation, including the type arguments of the enclosing type and method. /// public readonly struct GenericContext { @@ -18,9 +18,9 @@ public GenericContext(IGenericArgumentsProvider? type, IGenericArgumentsProvider Type = type; Method = method; } - + /// - /// Gets the object responsible for providing type arguments defined by the current generic type instantiation. + /// Gets the object responsible for providing type arguments defined by the current generic type instantiation. /// public IGenericArgumentsProvider? Type { @@ -28,7 +28,7 @@ public IGenericArgumentsProvider? Type } /// - /// Gets the object responsible for providing type arguments defined by the current generic method instantiation. + /// Gets the object responsible for providing type arguments defined by the current generic method instantiation. /// public IGenericArgumentsProvider? Method { @@ -36,14 +36,14 @@ public IGenericArgumentsProvider? Method } /// - /// Enters a new generic context with a new type providing type arguments. + /// Enters a new generic context with a new type providing type arguments. /// /// The new type providing the type arguments. /// The new generic context. public GenericContext WithType(IGenericArgumentsProvider type) => new GenericContext(type, Method); - + /// - /// Enters a new generic context with a new method providing type arguments. + /// Enters a new generic context with a new method providing type arguments. /// /// The new method providing the type arguments. /// The new generic context. @@ -62,9 +62,9 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) GenericParameterType.Method => Method, _ => throw new ArgumentOutOfRangeException() }; - + if (argumentProvider is null) - throw new ArgumentOutOfRangeException(); + return parameter; if (parameter.Index >= 0 && parameter.Index < argumentProvider.TypeArguments.Count) return argumentProvider.TypeArguments[parameter.Index]; From 2a3834ef57e66edfc5439e64b102b45cfa1725f0 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 00:43:59 +0100 Subject: [PATCH 02/11] Fix: Generic context tests --- .../Signatures/GenericContextTest.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index 73c2de250..578e5e0df 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -20,22 +20,22 @@ public GenericContextTest() [Theory] [InlineData(GenericParameterType.Type)] [InlineData(GenericParameterType.Method)] - public void ResolveGenericParameterWithEmptyTypeShouldThrow(GenericParameterType parameterType) + public void ResolveGenericParameterWithEmptyType(GenericParameterType parameterType) { var context = new GenericContext(); var parameter = new GenericParameterSignature(parameterType, 0); - Assert.Throws(() => context.GetTypeArgument(parameter)); + Assert.Equal(parameter, context.GetTypeArgument(parameter)); } - + [Fact] public void ResolveMethodGenericParameterWithMethod() { var genericInstance = new GenericInstanceMethodSignature(); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var context = new GenericContext(null, genericInstance); - + var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName); } @@ -45,9 +45,9 @@ public void ResolveTypeGenericParameterWithType() { var genericInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var context = new GenericContext(genericInstance, null); - + var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName); } @@ -57,12 +57,12 @@ public void ResolveTypeGenericParameterWithTypeAndMethod() { var genericType = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); genericType.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var genericMethod = new GenericInstanceMethodSignature(); genericMethod.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); - + var context = new GenericContext(genericType, genericMethod); - + var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName); } @@ -72,38 +72,38 @@ public void ResolveMethodGenericParameterWithTypeAndMethod() { var genericType = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); genericType.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var genericMethod = new GenericInstanceMethodSignature(); genericMethod.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); - + var context = new GenericContext(genericType, genericMethod); - + var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); Assert.Equal("System.Int32", context.GetTypeArgument(parameter).FullName); } [Fact] - public void ResolveTypeGenericParameterWithOnlyMethodShouldThrow() + public void ResolveTypeGenericParameterWithOnlyMethod() { var genericInstance = new GenericInstanceMethodSignature(); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var context = new GenericContext(null, genericInstance); - + var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); - Assert.Throws(() => context.GetTypeArgument(parameter)); + Assert.Equal(parameter,context.GetTypeArgument(parameter)); } [Fact] - public void ResolveMethodGenericParameterWithOnlyTypeShouldThrow() + public void ResolveMethodGenericParameterWithOnlyType() { var genericInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); - + var context = new GenericContext(genericInstance, null); - + var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); - Assert.Throws(() => context.GetTypeArgument(parameter)); + Assert.Equal(parameter, context.GetTypeArgument(parameter)); } } -} \ No newline at end of file +} From 0032d7a7b22f6ac6eed53db53f151f8ff1812709 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 15:06:20 +0100 Subject: [PATCH 03/11] Add: Helper generic context parsers --- .../Signatures/GenericContext.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index e20c1d0bb..abfcbf5bd 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -71,5 +71,47 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) throw new ArgumentOutOfRangeException(); } + + + /// + /// Tries to get type generic context from . + /// + /// Type specification to get generic context from. + /// Generic context. + public static GenericContext? FromTypeSpecification(TypeSpecification type) => type.Signature switch + { + GenericInstanceTypeSignature typeSig => new GenericContext(typeSig, null), + _ => null + }; + + /// + /// Tries to get method and/or type generic context from . + /// + /// Method specification to get generic context from. + /// Generic context. + public static GenericContext? FromMethodSpecification(MethodSpecification method) => + (method.DeclaringType, method.Signature) switch + { + (TypeSpecification {Signature: GenericInstanceTypeSignature typeSig}, { } methodSig) => + new GenericContext(typeSig, methodSig), + (_, { } methodSig) => new GenericContext(null, methodSig), + (TypeSpecification typeSpec, _) => FromTypeSpecification(typeSpec), + _ => null + }; + + /// + /// Tries to get method and/or type generic context from . + /// + /// Member to get generic context from. + /// Generic context + public static GenericContext? FromMember(IMemberDescriptor member) => + (member.DeclaringType, member) switch + { + (_, TypeSpecification typeSpec) => FromTypeSpecification(typeSpec), + (_, MethodSpecification methodSpec) => FromMethodSpecification(methodSpec), + (_, GenericInstanceTypeSignature typeSig) => new GenericContext(typeSig, null), + ({ } declaringType, _) => FromMember(declaringType), + _ => null + }; } } From f1349bfc79b4462d1696deba935a1895087ef0b0 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 15:09:09 +0100 Subject: [PATCH 04/11] Fix: GetTypeArgument Xmldoc --- src/AsmResolver.DotNet/Signatures/GenericContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index abfcbf5bd..5564150d4 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -51,6 +51,7 @@ public IGenericArgumentsProvider? Method /// /// Resolves a type parameter to a type argument, based on the current generic context. + /// If generic argument provider is not initialised for type parameter, than it will return itself. /// /// The parameter to get the argument value for. /// The argument type. From 84259a2898ccb5853d2742b928683ab514121db1 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 16:04:35 +0100 Subject: [PATCH 05/11] Remove FromMember and add unit tests --- .../Signatures/GenericContext.cs | 15 --- .../Signatures/GenericContextTest.cs | 104 ++++++++++++++++++ 2 files changed, 104 insertions(+), 15 deletions(-) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index 5564150d4..5b0838df4 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -99,20 +99,5 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) (TypeSpecification typeSpec, _) => FromTypeSpecification(typeSpec), _ => null }; - - /// - /// Tries to get method and/or type generic context from . - /// - /// Member to get generic context from. - /// Generic context - public static GenericContext? FromMember(IMemberDescriptor member) => - (member.DeclaringType, member) switch - { - (_, TypeSpecification typeSpec) => FromTypeSpecification(typeSpec), - (_, MethodSpecification methodSpec) => FromMethodSpecification(methodSpec), - (_, GenericInstanceTypeSignature typeSig) => new GenericContext(typeSig, null), - ({ } declaringType, _) => FromMember(declaringType), - _ => null - }; } } diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index 578e5e0df..ae11bab70 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using AsmResolver.DotNet.Signatures; using AsmResolver.DotNet.Signatures.Types; +using AsmResolver.PE.DotNet.Metadata.Tables.Rows; using Xunit; using Xunit.Sdk; @@ -105,5 +106,108 @@ public void ResolveMethodGenericParameterWithOnlyType() var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); Assert.Equal(parameter, context.GetTypeArgument(parameter)); } + + [Fact] + public void ParseGenericFromTypeSpecification() + { + var genericInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericInstance); + + var context = GenericContext.FromTypeSpecification(typeSpecification); + + Assert.True(context.HasValue); + Assert.Equal(genericInstance, context.Value.Type); + Assert.Null(context.Value.Method); + } + + [Fact] + public void ParseGenericFromMethodSpecification() + { + var genericParameter = new GenericParameterSignature(GenericParameterType.Method, 0); + var method = new MethodDefinition("TestMethod", MethodAttributes.Private, + MethodSignature.CreateStatic(genericParameter)); + var genericInstance = new GenericInstanceMethodSignature(); + genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); + var methodSpecification = new MethodSpecification(method, genericInstance); + + var context = GenericContext.FromMethodSpecification(methodSpecification); + + Assert.True(context.HasValue); + Assert.Null(context.Value.Type); + Assert.Equal(genericInstance, context.Value.Method); + } + + [Fact] + public void ParseGenericFromMethodSpecificationWithTypeSpecification() + { + var genericTypeInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericTypeInstance); + + var genericParameter = new GenericParameterSignature(GenericParameterType.Method, 0); + var method = new MemberReference(typeSpecification, "TestMethod", + MethodSignature.CreateStatic(genericParameter)); + + var genericMethodInstance = new GenericInstanceMethodSignature(); + genericMethodInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); + var methodSpecification = new MethodSpecification(method, genericMethodInstance); + + + var context = GenericContext.FromMethodSpecification(methodSpecification); + + Assert.True(context.HasValue); + Assert.Equal(genericTypeInstance, context.Value.Type); + Assert.Equal(genericMethodInstance, context.Value.Method); + } + + [Fact] + public void ParseGenericFromNotGenericTypeSpecification() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var typeSpecification = new TypeSpecification(notGenericSignature); + + var context = GenericContext.FromTypeSpecification(typeSpecification); + + Assert.False(context.HasValue); + } + + [Fact] + public void ParseGenericFromNotGenericMethodSpecification() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var method = new MethodDefinition("TestMethod", MethodAttributes.Private, + MethodSignature.CreateStatic(notGenericSignature)); + var methodSpecification = new MethodSpecification(method, null); + + var context = GenericContext.FromMethodSpecification(methodSpecification); + + Assert.False(context.HasValue); + } + + [Fact] + public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() + { + var genericTypeInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericTypeInstance); + + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var method = new MemberReference(typeSpecification, "TestMethod", + MethodSignature.CreateStatic(notGenericSignature)); + var methodSpecification = new MethodSpecification(method, null); + + var context = GenericContext.FromMethodSpecification(methodSpecification); + + Assert.True(context.HasValue); + Assert.Equal(genericTypeInstance, context.Value.Type); + Assert.Null(context.Value.Method); + } } } From 958670605ab95254ca6a57e81de875dd92606106 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 16:55:02 +0100 Subject: [PATCH 06/11] Add: More GenericContext From methods --- .../Signatures/GenericContext.cs | 90 +++++++++++++++++-- .../Signatures/GenericContextTest.cs | 40 ++++----- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index 5b0838df4..43e329868 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using AsmResolver.DotNet.Signatures.Types; namespace AsmResolver.DotNet.Signatures @@ -35,6 +36,11 @@ public IGenericArgumentsProvider? Method get; } + /// + /// Returns true if both Type and Method providers are null + /// + public bool IsEmpty => Type is null && Method is null; + /// /// Enters a new generic context with a new type providing type arguments. /// @@ -75,29 +81,99 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) /// - /// Tries to get type generic context from . + /// Gets type generic context from . /// /// Type specification to get generic context from. /// Generic context. - public static GenericContext? FromTypeSpecification(TypeSpecification type) => type.Signature switch + public static GenericContext FromType(TypeSpecification type) => type.Signature switch { GenericInstanceTypeSignature typeSig => new GenericContext(typeSig, null), - _ => null + _ => default }; /// - /// Tries to get method and/or type generic context from . + /// Gets type generic context from . + /// + /// Generic type signature to get generic context from. + /// Generic context. + public static GenericContext FromType(GenericInstanceTypeSignature type) => new(type, null); + + /// + /// Gets type generic context from . + /// + /// Type to get generic context from. + /// Generic context. + public static GenericContext FromType(ITypeDescriptor type) => type switch + { + TypeSpecification typeSpecification => FromType(typeSpecification), + GenericInstanceTypeSignature typeSig => FromType(typeSig), + _ => default + }; + + /// + /// Gets method and/or type generic context from . /// /// Method specification to get generic context from. /// Generic context. - public static GenericContext? FromMethodSpecification(MethodSpecification method) => + public static GenericContext FromMethod(MethodSpecification method) => (method.DeclaringType, method.Signature) switch { (TypeSpecification {Signature: GenericInstanceTypeSignature typeSig}, { } methodSig) => new GenericContext(typeSig, methodSig), (_, { } methodSig) => new GenericContext(null, methodSig), - (TypeSpecification typeSpec, _) => FromTypeSpecification(typeSpec), - _ => null + (TypeSpecification typeSpec, _) => FromType(typeSpec), + _ => default + }; + + /// + /// Gets method and/or type generic context from . + /// + /// Method to get generic context from. + /// Generic context. + public static GenericContext FromMethod(IMethodDescriptor method) => + method switch + { + MethodSpecification methodSpecification => FromMethod(methodSpecification), + MemberReference member => FromMember(member), + _ => default + }; + + /// + /// Gets type generic context from . + /// + /// Field to get generic context from. + /// Generic context. + public static GenericContext FromField(IFieldDescriptor field) => + field switch + { + MemberReference member => FromMember(member), + _ => default + }; + + /// + /// Gets type generic context from . + /// + /// Member reference to get generic context from. + /// Generic context. + public static GenericContext FromMember(MemberReference member) => + member.DeclaringType switch + { + TypeSpecification type => FromType(type), + _ => default + }; + + /// + /// Gets type generic context from . + /// + /// Metadata member to get generic context from. + /// Generic context. + public static GenericContext FromMember(IMetadataMember member) => + member switch + { + IMethodDescriptor method => FromMethod(method), + IFieldDescriptor field => FromField(field), + ITypeDescriptor type => FromType(type), + _ => default }; } } diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index ae11bab70..10e221999 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -114,11 +114,11 @@ public void ParseGenericFromTypeSpecification() genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var typeSpecification = new TypeSpecification(genericInstance); - var context = GenericContext.FromTypeSpecification(typeSpecification); + var context = GenericContext.FromType(typeSpecification); - Assert.True(context.HasValue); - Assert.Equal(genericInstance, context.Value.Type); - Assert.Null(context.Value.Method); + Assert.False(context.IsEmpty); + Assert.Equal(genericInstance, context.Type); + Assert.Null(context.Method); } [Fact] @@ -131,11 +131,11 @@ public void ParseGenericFromMethodSpecification() genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); var methodSpecification = new MethodSpecification(method, genericInstance); - var context = GenericContext.FromMethodSpecification(methodSpecification); + var context = GenericContext.FromMethod(methodSpecification); - Assert.True(context.HasValue); - Assert.Null(context.Value.Type); - Assert.Equal(genericInstance, context.Value.Method); + Assert.False(context.IsEmpty); + Assert.Null(context.Type); + Assert.Equal(genericInstance, context.Method); } [Fact] @@ -154,11 +154,11 @@ public void ParseGenericFromMethodSpecificationWithTypeSpecification() var methodSpecification = new MethodSpecification(method, genericMethodInstance); - var context = GenericContext.FromMethodSpecification(methodSpecification); + var context = GenericContext.FromMethod(methodSpecification); - Assert.True(context.HasValue); - Assert.Equal(genericTypeInstance, context.Value.Type); - Assert.Equal(genericMethodInstance, context.Value.Method); + Assert.False(context.IsEmpty); + Assert.Equal(genericTypeInstance, context.Type); + Assert.Equal(genericMethodInstance, context.Method); } [Fact] @@ -169,9 +169,9 @@ public void ParseGenericFromNotGenericTypeSpecification() var typeSpecification = new TypeSpecification(notGenericSignature); - var context = GenericContext.FromTypeSpecification(typeSpecification); + var context = GenericContext.FromType(typeSpecification); - Assert.False(context.HasValue); + Assert.True(context.IsEmpty); } [Fact] @@ -184,9 +184,9 @@ public void ParseGenericFromNotGenericMethodSpecification() MethodSignature.CreateStatic(notGenericSignature)); var methodSpecification = new MethodSpecification(method, null); - var context = GenericContext.FromMethodSpecification(methodSpecification); + var context = GenericContext.FromMethod(methodSpecification); - Assert.False(context.HasValue); + Assert.True(context.IsEmpty); } [Fact] @@ -203,11 +203,11 @@ public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() MethodSignature.CreateStatic(notGenericSignature)); var methodSpecification = new MethodSpecification(method, null); - var context = GenericContext.FromMethodSpecification(methodSpecification); + var context = GenericContext.FromMethod(methodSpecification); - Assert.True(context.HasValue); - Assert.Equal(genericTypeInstance, context.Value.Type); - Assert.Null(context.Value.Method); + Assert.False(context.IsEmpty); + Assert.Equal(genericTypeInstance, context.Type); + Assert.Null(context.Method); } } } From 5905aaf6b6eb974dd6689291841c207149ce613c Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 17:35:39 +0100 Subject: [PATCH 07/11] Add: Unit tests --- .../Signatures/GenericContextTest.cs | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index 10e221999..846fd5872 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -115,7 +115,9 @@ public void ParseGenericFromTypeSpecification() var typeSpecification = new TypeSpecification(genericInstance); var context = GenericContext.FromType(typeSpecification); + var context2 = GenericContext.FromMember(typeSpecification); + Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericInstance, context.Type); Assert.Null(context.Method); @@ -132,7 +134,9 @@ public void ParseGenericFromMethodSpecification() var methodSpecification = new MethodSpecification(method, genericInstance); var context = GenericContext.FromMethod(methodSpecification); + var context2 = GenericContext.FromMember(methodSpecification); + Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Null(context.Type); Assert.Equal(genericInstance, context.Method); @@ -155,7 +159,9 @@ public void ParseGenericFromMethodSpecificationWithTypeSpecification() var context = GenericContext.FromMethod(methodSpecification); + var context2 = GenericContext.FromMember(methodSpecification); + Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericTypeInstance, context.Type); Assert.Equal(genericMethodInstance, context.Method); @@ -170,7 +176,9 @@ public void ParseGenericFromNotGenericTypeSpecification() var typeSpecification = new TypeSpecification(notGenericSignature); var context = GenericContext.FromType(typeSpecification); + var context2 = GenericContext.FromMember(typeSpecification); + Assert.Equal(context, context2); Assert.True(context.IsEmpty); } @@ -185,7 +193,9 @@ public void ParseGenericFromNotGenericMethodSpecification() var methodSpecification = new MethodSpecification(method, null); var context = GenericContext.FromMethod(methodSpecification); + var context2 = GenericContext.FromMember(methodSpecification); + Assert.Equal(context, context2); Assert.True(context.IsEmpty); } @@ -204,10 +214,136 @@ public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() var methodSpecification = new MethodSpecification(method, null); var context = GenericContext.FromMethod(methodSpecification); + var context2 = GenericContext.FromMember(methodSpecification); + Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericTypeInstance, context.Type); Assert.Null(context.Method); } + + [Fact] + public void ParseGenericFromField() + { + var genericTypeInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericTypeInstance); + + var genericParameter = new GenericParameterSignature(GenericParameterType.Type, 0); + + var field = new FieldDefinition("Field", FieldAttributes.Private, + FieldSignature.CreateStatic(genericParameter)); + + var member = new MemberReference(typeSpecification, field.Name, field.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.False(context.IsEmpty); + Assert.Equal(genericTypeInstance, context.Type); + Assert.Null(context.Method); + } + + [Fact] + public void ParseGenericFromNotGenericField() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var field = new FieldDefinition("Field", FieldAttributes.Private, + FieldSignature.CreateStatic(notGenericSignature)); + + var member = new MemberReference(type, field.Name, field.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.True(context.IsEmpty); + } + + [Fact] + public void ParseGenericFromMethod() + { + var genericTypeInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericTypeInstance); + + var genericParameter = new GenericParameterSignature(GenericParameterType.Type, 0); + + var method = new MethodDefinition("Method", MethodAttributes.Private, + MethodSignature.CreateStatic(genericParameter)); + + var member = new MemberReference(typeSpecification, method.Name, method.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.False(context.IsEmpty); + Assert.Equal(genericTypeInstance, context.Type); + Assert.Null(context.Method); + } + + [Fact] + public void ParseGenericFromNotGenericMethod() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var method = new MethodDefinition("Method", MethodAttributes.Private, + MethodSignature.CreateStatic(notGenericSignature)); + + var member = new MemberReference(type, method.Name, method.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.True(context.IsEmpty); + } + + [Fact] + public void ParseGenericFromProperty() + { + var genericTypeInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + var typeSpecification = new TypeSpecification(genericTypeInstance); + + var genericParameter = new GenericParameterSignature(GenericParameterType.Type, 0); + + var property = new PropertyDefinition("Property", PropertyAttributes.None, + PropertySignature.CreateStatic(genericParameter)); + + var member = new MemberReference(typeSpecification, property.Name, property.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.False(context.IsEmpty); + Assert.Equal(genericTypeInstance, context.Type); + Assert.Null(context.Method); + } + + [Fact] + public void ParseGenericFromNotGenericProperty() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var property = new PropertyDefinition("Property", PropertyAttributes.None, + PropertySignature.CreateStatic(notGenericSignature)); + + var member = new MemberReference(type, property.Name, property.Signature); + + var context = GenericContext.FromField(member); + var context2 = GenericContext.FromMember(member); + + Assert.Equal(context, context2); + Assert.True(context.IsEmpty); + } + } } From aa4d7dd9e48b6fe8f41383a6891cd0e01134e188 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 17:42:29 +0100 Subject: [PATCH 08/11] Add: Unit tests --- .../Signatures/GenericContext.cs | 6 ++-- .../Signatures/GenericContextTest.cs | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index 43e329868..7edb242fe 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -163,11 +163,11 @@ public static GenericContext FromMember(MemberReference member) => }; /// - /// Gets type generic context from . + /// Gets type generic context from . /// - /// Metadata member to get generic context from. + /// Member to get generic context from. /// Generic context. - public static GenericContext FromMember(IMetadataMember member) => + public static GenericContext FromMember(IMemberDescriptor member) => member switch { IMethodDescriptor method => FromMethod(method), diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index 846fd5872..dfd5fd518 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -107,6 +107,35 @@ public void ResolveMethodGenericParameterWithOnlyType() Assert.Equal(parameter, context.GetTypeArgument(parameter)); } + + [Fact] + public void ParseGenericFromTypeSignature() + { + var genericInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List<>)), false); + genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); + + var context = GenericContext.FromType(genericInstance); + var context2 = GenericContext.FromMember(genericInstance); + + Assert.Equal(context, context2); + Assert.False(context.IsEmpty); + Assert.Equal(genericInstance, context.Type); + Assert.Null(context.Method); + } + + [Fact] + public void ParseGenericFromNonGenericTypeSignature() + { + var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var notGenericSignature = new TypeDefOrRefSignature(type); + + var context = GenericContext.FromType(notGenericSignature); + var context2 = GenericContext.FromMember(notGenericSignature); + + Assert.Equal(context, context2); + Assert.True(context.IsEmpty); + } + [Fact] public void ParseGenericFromTypeSpecification() { From bf92f6c00d4b1f12244fb0203144608d0abad298 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 17:58:16 +0100 Subject: [PATCH 09/11] Fix: Unit tests --- .../Signatures/GenericContextTest.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index dfd5fd518..2b4a7983f 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -116,7 +116,9 @@ public void ParseGenericFromTypeSignature() var context = GenericContext.FromType(genericInstance); var context2 = GenericContext.FromMember(genericInstance); + var context3 = GenericContext.FromType((ITypeDescriptor)genericInstance); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericInstance, context.Type); @@ -145,7 +147,9 @@ public void ParseGenericFromTypeSpecification() var context = GenericContext.FromType(typeSpecification); var context2 = GenericContext.FromMember(typeSpecification); + var context3 = GenericContext.FromType((ITypeDescriptor)typeSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericInstance, context.Type); @@ -164,7 +168,9 @@ public void ParseGenericFromMethodSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Null(context.Type); @@ -189,7 +195,9 @@ public void ParseGenericFromMethodSpecificationWithTypeSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericTypeInstance, context.Type); @@ -206,7 +214,9 @@ public void ParseGenericFromNotGenericTypeSpecification() var context = GenericContext.FromType(typeSpecification); var context2 = GenericContext.FromMember(typeSpecification); + var context3 = GenericContext.FromType((ITypeDescriptor)typeSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.True(context.IsEmpty); } @@ -223,7 +233,9 @@ public void ParseGenericFromNotGenericMethodSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.True(context.IsEmpty); } @@ -244,7 +256,9 @@ public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + Assert.Equal(context, context3); Assert.Equal(context, context2); Assert.False(context.IsEmpty); Assert.Equal(genericTypeInstance, context.Type); @@ -306,7 +320,7 @@ public void ParseGenericFromMethod() var member = new MemberReference(typeSpecification, method.Name, method.Signature); - var context = GenericContext.FromField(member); + var context = GenericContext.FromMethod(member); var context2 = GenericContext.FromMember(member); Assert.Equal(context, context2); @@ -326,7 +340,7 @@ public void ParseGenericFromNotGenericMethod() var member = new MemberReference(type, method.Name, method.Signature); - var context = GenericContext.FromField(member); + var context = GenericContext.FromMethod(member); var context2 = GenericContext.FromMember(member); Assert.Equal(context, context2); @@ -347,7 +361,7 @@ public void ParseGenericFromProperty() var member = new MemberReference(typeSpecification, property.Name, property.Signature); - var context = GenericContext.FromField(member); + var context = GenericContext.FromMethod(member); var context2 = GenericContext.FromMember(member); Assert.Equal(context, context2); @@ -367,7 +381,7 @@ public void ParseGenericFromNotGenericProperty() var member = new MemberReference(type, property.Name, property.Signature); - var context = GenericContext.FromField(member); + var context = GenericContext.FromMethod(member); var context2 = GenericContext.FromMember(member); Assert.Equal(context, context2); From a1944b5b307a42c972a0acd3b589f6e099f3e4d0 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 21:16:32 +0100 Subject: [PATCH 10/11] Fix: GenericContext --- .../Signatures/GenericContext.cs | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/AsmResolver.DotNet/Signatures/GenericContext.cs b/src/AsmResolver.DotNet/Signatures/GenericContext.cs index 7edb242fe..65b435eee 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericContext.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericContext.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using AsmResolver.DotNet.Signatures.Types; namespace AsmResolver.DotNet.Signatures @@ -57,8 +58,12 @@ public IGenericArgumentsProvider? Method /// /// Resolves a type parameter to a type argument, based on the current generic context. - /// If generic argument provider is not initialised for type parameter, than it will return itself. /// + /// + /// If a type parameter within the signature references a parameter that is not captured by the context + /// (i.e. the corresponding generic argument provider is set to null), + /// then this type parameter will not be substituted. + /// /// The parameter to get the argument value for. /// The argument type. public TypeSignature GetTypeArgument(GenericParameterSignature parameter) @@ -81,9 +86,9 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Type specification to get generic context from. + /// Type specification to get the generic context from. /// Generic context. public static GenericContext FromType(TypeSpecification type) => type.Signature switch { @@ -92,16 +97,16 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) }; /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Generic type signature to get generic context from. + /// Generic type signature to get the generic context from. /// Generic context. public static GenericContext FromType(GenericInstanceTypeSignature type) => new(type, null); /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Type to get generic context from. + /// Type to get the generic context from. /// Generic context. public static GenericContext FromType(ITypeDescriptor type) => type switch { @@ -111,24 +116,21 @@ public TypeSignature GetTypeArgument(GenericParameterSignature parameter) }; /// - /// Gets method and/or type generic context from . + /// Gets a method and/or type generic context from . /// - /// Method specification to get generic context from. + /// Method specification to get the generic context from. /// Generic context. - public static GenericContext FromMethod(MethodSpecification method) => - (method.DeclaringType, method.Signature) switch - { - (TypeSpecification {Signature: GenericInstanceTypeSignature typeSig}, { } methodSig) => - new GenericContext(typeSig, methodSig), - (_, { } methodSig) => new GenericContext(null, methodSig), - (TypeSpecification typeSpec, _) => FromType(typeSpec), - _ => default - }; + public static GenericContext FromMethod(MethodSpecification method) + { + return method.DeclaringType is TypeSpecification {Signature: GenericInstanceTypeSignature typeSig} + ? new GenericContext(typeSig, method.Signature) + : new GenericContext(null, method.Signature); + } /// - /// Gets method and/or type generic context from . + /// Gets a method and/or type generic context from . /// - /// Method to get generic context from. + /// Method to get the generic context from. /// Generic context. public static GenericContext FromMethod(IMethodDescriptor method) => method switch @@ -139,9 +141,9 @@ public static GenericContext FromMethod(IMethodDescriptor method) => }; /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Field to get generic context from. + /// Field to get the generic context from. /// Generic context. public static GenericContext FromField(IFieldDescriptor field) => field switch @@ -151,9 +153,9 @@ public static GenericContext FromField(IFieldDescriptor field) => }; /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Member reference to get generic context from. + /// Member reference to get the generic context from. /// Generic context. public static GenericContext FromMember(MemberReference member) => member.DeclaringType switch @@ -163,9 +165,9 @@ public static GenericContext FromMember(MemberReference member) => }; /// - /// Gets type generic context from . + /// Gets a type generic context from . /// - /// Member to get generic context from. + /// Member to get the generic context from. /// Generic context. public static GenericContext FromMember(IMemberDescriptor member) => member switch From 88e9385900790305fb993883a3170d184645c423 Mon Sep 17 00:00:00 2001 From: JPaja Date: Sun, 28 Nov 2021 21:19:56 +0100 Subject: [PATCH 11/11] Fix: GenericContext Tests formatting --- .../Signatures/GenericContextTest.cs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs index 2b4a7983f..aa9a55beb 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/GenericContextTest.cs @@ -1,16 +1,14 @@ -using System; using System.Collections.Generic; using AsmResolver.DotNet.Signatures; using AsmResolver.DotNet.Signatures.Types; using AsmResolver.PE.DotNet.Metadata.Tables.Rows; using Xunit; -using Xunit.Sdk; namespace AsmResolver.DotNet.Tests.Signatures { public class GenericContextTest { - private ReferenceImporter _importer; + private readonly ReferenceImporter _importer; public GenericContextTest() { @@ -92,7 +90,7 @@ public void ResolveTypeGenericParameterWithOnlyMethod() var context = new GenericContext(null, genericInstance); var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); - Assert.Equal(parameter,context.GetTypeArgument(parameter)); + Assert.Equal(parameter, context.GetTypeArgument(parameter)); } [Fact] @@ -116,7 +114,7 @@ public void ParseGenericFromTypeSignature() var context = GenericContext.FromType(genericInstance); var context2 = GenericContext.FromMember(genericInstance); - var context3 = GenericContext.FromType((ITypeDescriptor)genericInstance); + var context3 = GenericContext.FromType((ITypeDescriptor) genericInstance); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -128,7 +126,7 @@ public void ParseGenericFromTypeSignature() [Fact] public void ParseGenericFromNonGenericTypeSignature() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var context = GenericContext.FromType(notGenericSignature); @@ -147,7 +145,7 @@ public void ParseGenericFromTypeSpecification() var context = GenericContext.FromType(typeSpecification); var context2 = GenericContext.FromMember(typeSpecification); - var context3 = GenericContext.FromType((ITypeDescriptor)typeSpecification); + var context3 = GenericContext.FromType((ITypeDescriptor) typeSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -168,7 +166,7 @@ public void ParseGenericFromMethodSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); - var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor) methodSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -195,7 +193,7 @@ public void ParseGenericFromMethodSpecificationWithTypeSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); - var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor) methodSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -207,14 +205,14 @@ public void ParseGenericFromMethodSpecificationWithTypeSpecification() [Fact] public void ParseGenericFromNotGenericTypeSpecification() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var typeSpecification = new TypeSpecification(notGenericSignature); var context = GenericContext.FromType(typeSpecification); var context2 = GenericContext.FromMember(typeSpecification); - var context3 = GenericContext.FromType((ITypeDescriptor)typeSpecification); + var context3 = GenericContext.FromType((ITypeDescriptor) typeSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -224,7 +222,7 @@ public void ParseGenericFromNotGenericTypeSpecification() [Fact] public void ParseGenericFromNotGenericMethodSpecification() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var method = new MethodDefinition("TestMethod", MethodAttributes.Private, @@ -233,7 +231,7 @@ public void ParseGenericFromNotGenericMethodSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); - var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor) methodSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -247,7 +245,7 @@ public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() genericTypeInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var typeSpecification = new TypeSpecification(genericTypeInstance); - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var method = new MemberReference(typeSpecification, "TestMethod", @@ -256,7 +254,7 @@ public void ParseGenericFromNotGenericMethodSpecificationWithTypeSpecification() var context = GenericContext.FromMethod(methodSpecification); var context2 = GenericContext.FromMember(methodSpecification); - var context3 = GenericContext.FromMethod((IMethodDescriptor)methodSpecification); + var context3 = GenericContext.FromMethod((IMethodDescriptor) methodSpecification); Assert.Equal(context, context3); Assert.Equal(context, context2); @@ -291,7 +289,7 @@ public void ParseGenericFromField() [Fact] public void ParseGenericFromNotGenericField() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var field = new FieldDefinition("Field", FieldAttributes.Private, @@ -332,7 +330,7 @@ public void ParseGenericFromMethod() [Fact] public void ParseGenericFromNotGenericMethod() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var method = new MethodDefinition("Method", MethodAttributes.Private, @@ -373,7 +371,7 @@ public void ParseGenericFromProperty() [Fact] public void ParseGenericFromNotGenericProperty() { - var type = new TypeDefinition("","Test type", TypeAttributes.Public); + var type = new TypeDefinition("", "Test type", TypeAttributes.Public); var notGenericSignature = new TypeDefOrRefSignature(type); var property = new PropertyDefinition("Property", PropertyAttributes.None, @@ -387,6 +385,5 @@ public void ParseGenericFromNotGenericProperty() Assert.Equal(context, context2); Assert.True(context.IsEmpty); } - } }