10

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

0

1 Answer 1

21

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.

1 Never thought I could use the word get so many times in just one sentence!

1
  • 14
    +1 for making me laugh with the sentence The property GetMethod calls GetGetMethod to get the getter.
    – theyetiman
    Nov 27, 2013 at 11:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.