private void InitializeGet() { var getMethod = ContainedProperty.GetGetMethod(); if (getMethod == null) { return; } var instance = Expression.Parameter(typeof(object), "instance"); var instanceCast = ContainedProperty.DeclaringType.IsValueType ? Expression.Convert(instance, ContainedProperty.DeclaringType) : Expression.TypeAs(instance, ContainedProperty.DeclaringType); getDelegate = Expression.Lambda <Func <object, object> >(Expression.TypeAs(Expression.Call(instanceCast, getMethod), typeof(object)), instance).Compile(); }
private void InitializeSet() { var setMethod = ContainedProperty.GetSetMethod(); if (setMethod == null) { return; } var instance = Expression.Parameter(typeof(object), "instance"); var value = Expression.Parameter(typeof(object), "value"); var instanceCast = ContainedProperty.DeclaringType.IsValueType ? Expression.Convert(instance, ContainedProperty.DeclaringType) : Expression.TypeAs(instance, ContainedProperty.DeclaringType); var valueCast = PropertyType.IsValueType ? Expression.Convert(value, PropertyType) : Expression.TypeAs(value, PropertyType); setDelegate = Expression.Lambda <Action <object, object> >(Expression.Call(instanceCast, setMethod, valueCast), new[] { instance, value }).Compile(); }
/// <summary> /// Returns an array containing all the custom attributes /// </summary> public object[] GetCustomAttributes(bool inherit) { return(ContainedProperty.GetCustomAttributes(inherit)); }