.NET:GetDeclaredProperty()和GetProperty()有什么区别?

Isi*_* O. 2 .net c# reflection

我提到了MSDN库,但仍然感到困惑.那两种方法有什么区别?谁能举个例子?

Thx提前.:)

Dav*_*Yaw 12

GetDeclaredProperty将仅返回在当前类型上声明的属性.GetProperty也将返回在父类上定义的属性.

此外,GetProperty具有重载,因此您可以指定是仅需要私有属性还是公共属性,实例还是静态属性等.

调用GetDeclaredProperty等同于调用:

GetProperty(name, 
    BindingFlags.NonPublic | 
    BindingFlags.Public | 
    BindingFlags.Static | 
    BindingFlags.Instance | 
    BindingFlags.DeclaredOnly);
Run Code Online (Sandbox Code Playgroud)