.NET反射中的转换

Joh*_*ohn 1 .net c# reflection

我在哪里可以找到转换方法,如

    public static implicit operator MyType(OtherType d)
    public static implicit operator OtherType(MyType d)
Run Code Online (Sandbox Code Playgroud)

Type对象?

Jon*_*eet 5

如果你问一个类型的方法,你会找到运算符.方法的IsSpecialName属性将返回true.例如:

using System;

public class Foo
{
    public static implicit operator int(Foo input)
    {
        return 0;
    }
}

class Test
{
    static void Main(string[] args)
    {
        foreach (var method in typeof(Foo).GetMethods())
        {
            Console.WriteLine(method + ": " + method.IsSpecialName);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)