.Net 4.5 has PropertyInfo.GetMethod as a property on PropertyInfo
class. Is it doing anything different from PropertyInfo.GetGetMethod
method? The documentation page is virtually blank. The only difference I can find is GetGetMethod
by default returns only public getter while GetMethod
returns even non-public getter (the same is achieved by GetGetMethod(true)
).
Similarly there is GetSetMethod
method and SetMethod
property in .NET 4.5. Why was it introduced in .NET?
There is no difference. The property GetMethod
calls GetGetMethod
to get the getter. 1 Here's what ILSpy tells me about the property implementation:
// System.Reflection.PropertyInfo
[__DynamicallyInvokable]
public virtual MethodInfo GetMethod
{
[__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
get
{
return this.GetGetMethod(true);
}
}
The property GetMethod
is simply easier to use, because it does not relate on an parameter.
1Never thought I could use the word get so many times in just one sentence!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With