Creating Property Accessor Delegates

When the PropertyInfo instance has been obtained, it is used to create a delegate for the get and set accessors. For this the Delegate.CreateDelegate method is used, via a custom PropertyInfo extension method called CreateGetter, in the PropertyUtility class. Within the CreateGetter method, the type argument, required by the Delegate.CreateDelegate method, is generated using the Expression.GetFuncType method. If the property is of type string, for example, a type representing a Func<string> is produced. See the following excerpt:

public static Func<TProperty> CreateGetter<TProperty>(    this PropertyInfo propertyInfo, object owner){    ArgumentValidator.AssertNotNull(propertyInfo, ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.