Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between GetGetMethod method and GetMethod property?

.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?

like image 343
nawfal Avatar asked May 12 '13 09:05

nawfal


1 Answers

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!

like image 98
Carsten Avatar answered Sep 20 '22 06:09

Carsten