public static void Array_and_generic_method_parameters() { var method = ILAsmParser.ParseMethodReference("void Foo::Bar(bool[,][,], class Foo<bool, int32>, bool)", P); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); method.DeclaringType.ShouldBe(P.GetTypeFromReference(null, null, "", "Foo")); method.MethodName.ShouldBe("Bar"); method.Parameters.ShouldBe(new[] { P.GetArrayType( P.GetArrayType( P.GetPrimitiveType(PrimitiveTypeCode.Boolean), rank: 2), rank: 2), P.GetGenericInstantiation( P.GetTypeFromReference(false, null, "", "Foo"), new[] { P.GetPrimitiveType(PrimitiveTypeCode.Boolean), P.GetPrimitiveType(PrimitiveTypeCode.Int32) }), P.GetPrimitiveType(PrimitiveTypeCode.Boolean) }); }
public MethodReference GetMethodReference(string ilasmSyntax) { var result = ILAsmParser.ParseMethodReference(ilasmSyntax, typeProvider); var method = new MethodReference(result.MethodName, result.ReturnType, result.DeclaringType) { HasThis = result.Instance, ExplicitThis = result.InstanceExplicit }; foreach (var parameter in result.Parameters) { method.Parameters.Add(new ParameterDefinition(parameter)); } if (!result.GenericArguments.Any()) { return(method); } var genericInstantiation = new GenericInstanceMethod(method); foreach (var argument in result.GenericArguments) { genericInstantiation.GenericArguments.Add(argument); } return(genericInstantiation); }
public static void Instance_explicit_method() { var method = ILAsmParser.ParseMethodReference("instance explicit void Foo::Bar()", P); method.Instance.ShouldBeTrue(); method.InstanceExplicit.ShouldBeTrue(); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); }
public static void Special_method_names([Values(".ctor", ".cctor")] string specialName) { var method = ILAsmParser.ParseMethodReference("void Foo::" + specialName + "()", P); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); method.DeclaringType.ShouldBe(P.GetTypeFromReference(null, null, "", "Foo")); method.MethodName.ShouldBe(specialName); }
public static void Field_reference_with_type_reference() { var field = ILAsmParser.ParseFieldReference("bool class ClassName::FieldName", P); field.FieldType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Boolean)); field.DeclaringType.ShouldBe(P.GetTypeFromReference(false, null, "", "ClassName")); field.FieldName.ShouldBe("FieldName"); }
public static void Dotted_method_name() { var method = ILAsmParser.ParseMethodReference("void Foo::This.Is.Legal()", P); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); method.DeclaringType.ShouldBe(P.GetTypeFromReference(null, null, "", "Foo")); method.MethodName.ShouldBe("This.Is.Legal"); }
public static void Method_reference_with_type_reference() { var method = ILAsmParser.ParseMethodReference("void class Foo::Bar()", P); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); method.DeclaringType.ShouldBe(P.GetTypeFromReference(false, null, "", "Foo")); method.MethodName.ShouldBe("Bar"); }
public static void Single_method_parameter() { var method = ILAsmParser.ParseMethodReference("void Foo::Bar(bool)", P); method.ReturnType.ShouldBe(P.GetPrimitiveType(PrimitiveTypeCode.Void)); method.DeclaringType.ShouldBe(P.GetTypeFromReference(null, null, "", "Foo")); method.MethodName.ShouldBe("Bar"); method.Parameters.ShouldBe(new[] { P.GetPrimitiveType(PrimitiveTypeCode.Boolean) }); }
public static void Field_reference_with_array_return_and_assemblies() { var field = ILAsmParser.ParseFieldReference("class [a] Foo[] class [a]Bar::FieldName", P); field.FieldType.ShouldBe( P.GetArrayType( P.GetTypeFromReference(false, "a", "", "Foo"), rank: 1)); field.DeclaringType.ShouldBe(P.GetTypeFromReference(false, "a", "", "Bar")); field.FieldName.ShouldBe("FieldName"); }
public static void Field_reference_with_nested_classes() { var field = ILAsmParser.ParseFieldReference("class A.B.C/D.E.F/G H.I.J/K.L.M/N::FieldName", P); field.FieldType.ShouldBe(P.GetTypeFromReference( isValueType: false, assemblyName: null, namespaceName: "A.B", topLevelTypeName: "C", nestedTypeNames: new[] { "D.E.F", "G" })); field.DeclaringType.ShouldBe(P.GetTypeFromReference( isValueType: null, assemblyName: null, namespaceName: "H.I", topLevelTypeName: "J", nestedTypeNames: new[] { "K.L.M", "N" })); field.FieldName.ShouldBe("FieldName"); }
public static void Generic_method_instantiation() { var method = ILAsmParser.ParseMethodReference("class Foo`1/Bar`1<!0, !1> class Foo`1/Bar`1<bool, int32>::MethodName<!1, string>(!0, !1, !!0)", P); method.ReturnType.ShouldBe( P.GetGenericInstantiation( P.GetTypeFromReference(false, null, "", "Foo`1", new[] { "Bar`1" }), new[] { P.GetGenericTypeParameter(0), P.GetGenericTypeParameter(1) })); method.DeclaringType.ShouldBe( P.GetGenericInstantiation( P.GetTypeFromReference(false, null, "", "Foo`1", new[] { "Bar`1" }), new[] { P.GetPrimitiveType(PrimitiveTypeCode.Boolean), P.GetPrimitiveType(PrimitiveTypeCode.Int32) })); method.MethodName.ShouldBe("MethodName"); method.GenericArguments.ShouldBe(new[] { P.GetGenericTypeParameter(1), P.GetPrimitiveType(PrimitiveTypeCode.String) }); method.Parameters.ShouldBe(new[] { P.GetGenericTypeParameter(0), P.GetGenericTypeParameter(1), P.GetGenericMethodParameter(0) }); }
public static void Field_reference_with_generics() { var field = ILAsmParser.ParseFieldReference("class Foo`1/Bar`1<!0, !1> class Foo`1/Bar`1<bool, int32>::FieldName", P); field.FieldType.ShouldBe( P.GetGenericInstantiation( P.GetTypeFromReference(false, null, "", "Foo`1", nestedTypeNames: new[] { "Bar`1" }), new[] { P.GetGenericTypeParameter(0), P.GetGenericTypeParameter(1) })); field.DeclaringType.ShouldBe( P.GetGenericInstantiation( P.GetTypeFromReference(false, null, "", "Foo`1", nestedTypeNames: new[] { "Bar`1" }), new[] { P.GetPrimitiveType(PrimitiveTypeCode.Boolean), P.GetPrimitiveType(PrimitiveTypeCode.Int32) })); field.FieldName.ShouldBe("FieldName"); }
public static void Varargs_method_parameters_not_supported() { Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("void Foo::Bar(...)", P)); }
public static void Vararg_calling_convention_is_not_supported() { Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("vararg void Bar()", P)); }
public static void Unmanaged_calling_convention_is_not_supported([Values("cdecl", "fastcall", "stdcall", "thiscall")] string unmanagedConvention) { Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("unmanaged " + unmanagedConvention + " void Bar()", P)); }
private static T AssertException <T>(string syntax) where T : Exception { return(Should.Throw <T>(() => ILAsmParser.ParseType(syntax, P))); }
public FieldReference GetFieldReference(string ilasmSyntax) { var field = ILAsmParser.ParseFieldReference(ilasmSyntax, typeProvider); return(new FieldReference(field.FieldName, field.FieldType, field.DeclaringType)); }
public static void ParseMethodReference_should_throw_FormatException_for_invalid_character() { Should.Throw <FormatException>(() => ILAsmParser.ParseMethodReference("/", P)); }
public static void ParseMethodReference_should_throw_ArgumentException_for_whitespace([Values(null, "", " ")] string whitespace) { var ex = Should.Throw <ArgumentException>(() => ILAsmParser.ParseMethodReference(whitespace, P)); ex.ParamName.ShouldBe("methodReferenceSyntax"); }
public TypeReference GetTypeReference(string ilasmSyntax) { return(ILAsmParser.ParseType(ilasmSyntax, typeProvider)); }
public static void Method_reference_without_type_spec_is_not_supported() { Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("void Bar()", P)); }
public static void Default_calling_convention_may_be_specified() { ILAsmParser.ParseMethodReference("default void Foo::Bar()", P); }
private static void AssertCallTree(string syntax, string expected) { ILAsmParser.ParseType(syntax, P).ShouldBe(expected); }