Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用反射获取类的方法的代码(不包括系统方法,如ToString()、Equals、Hasvalue等)_C#_Wsdl_System.reflection - Fatal编程技术网

C# 使用反射获取类的方法的代码(不包括系统方法,如ToString()、Equals、Hasvalue等)

C# 使用反射获取类的方法的代码(不包括系统方法,如ToString()、Equals、Hasvalue等),c#,wsdl,system.reflection,C#,Wsdl,System.reflection,我正在开发一个wcf代理生成器,它使用c#动态生成所有方法。我将获得以下方法,其中我只需要选择前两个 反射中的GetMethods()返回我不需要的所有方法(包括ToString、Hasvalue、Equals等)(即我定义的实际类型) 提前感谢如果我理解正确,您需要以下方法: 不是用于属性的getter/setter方法 是在实际类型而不是基类型上定义的 没有返回类型void var proxyType = proxyinstance.GetType(); var methods = pro

我正在开发一个wcf代理生成器,它使用c#动态生成所有方法。我将获得以下方法,其中我只需要选择前两个

反射中的GetMethods()返回我不需要的所有方法(包括ToString、Hasvalue、Equals等)(即我定义的实际类型)


提前感谢

如果我理解正确,您需要以下方法:

  • 不是用于属性的getter/setter方法
  • 是在实际类型而不是基类型上定义的
  • 没有返回类型
    void

    var proxyType = proxyinstance.GetType();
    var methods = proxyType.GetMethods()
        .Where(x => !x.IsSpecialName) // excludes property backing methods
        .Where(x => x.DeclaringType == proxyType) // excludes methods declared on base types
        .Where(x => x.ReturnType != typeof(void)); // excludes methods which return void
    
所有这些条件也可以组合成一个
调用,其中
调用:

var methods = proxyType.GetMethods().Where(x => 
    !x.IsSpecialName && 
    x.DeclaringType == proxyType && 
    x.ReturnType != typeof(void)
);

请澄清选择方法的标准(调试窗口中可见的前两个方法不是很有用)。谢谢,这正是我需要的