Пример #1
0
        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)
            });
        }
Пример #2
0
        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);
        }
Пример #3
0
        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));
        }
Пример #4
0
        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");
        }
Пример #5
0
        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);
        }
Пример #6
0
        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");
        }
Пример #7
0
        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)
            });
        }
Пример #8
0
        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)
            });
        }
Пример #9
0
 public static void Varargs_method_parameters_not_supported()
 {
     Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("void Foo::Bar(...)", P));
 }
Пример #10
0
 public static void Vararg_calling_convention_is_not_supported()
 {
     Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("vararg void Bar()", P));
 }
Пример #11
0
 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));
 }
Пример #12
0
 public static void Default_calling_convention_may_be_specified()
 {
     ILAsmParser.ParseMethodReference("default void Foo::Bar()", P);
 }
Пример #13
0
 public static void Method_reference_without_type_spec_is_not_supported()
 {
     Should.Throw <NotSupportedException>(() => ILAsmParser.ParseMethodReference("void Bar()", P));
 }
Пример #14
0
 public static void ParseMethodReference_should_throw_FormatException_for_invalid_character()
 {
     Should.Throw <FormatException>(() => ILAsmParser.ParseMethodReference("/", P));
 }
Пример #15
0
        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");
        }