Esempio n. 1
0
        /// <summary>
        /// Gets the property writer.
        /// </summary>
        private static IDelegatePropertyWriter GetPropertyWriter(PropertyInfo property, TypeMetaData context)
        {
            IDelegatePropertyWriter actualWriter = DelegatePropertyFactory.CreatePropertyWriter(property);

            if (actualWriter != null)
            {
                context.PropertyWriters.Add(property, actualWriter);
            }
            return(actualWriter);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the wrapper object property wrapper.
        /// </summary>
        private static PropertyDescriptor CreateWrapperObjectPropertyWrapper(TypeMetaData context, PropertyInfo property)
        {
            IDelegatePropertyReader actualReader = GetPropertyReader(property, context);
            IDelegatePropertyWriter actualWriter = GetPropertyWriter(property, context);

            Func <object, object>   reader = property.CanRead ? new Func <object, object>(o => actualReader.GetValue(o)) : null;
            Action <object, object> writer = property.CanWrite ? new Action <object, object>((o, v) => actualWriter.SetValue(o, v)) : null;

            DelegatePropertyDescriptor descriptor = new DelegatePropertyDescriptor(
                property.Name,
                property.DeclaringType,
                property.PropertyType,
                reader,
                writer
                );

            return(descriptor);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates the property writer.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns></returns>
 public static IDelegatePropertyWriter CreatePropertyWriter(PropertyInfo property)
 {
     IDelegatePropertyWriter writer = null;
     if (property != null)
     {
         Type delegateWriterType = typeof(Action<,>).MakeGenericType(property.DeclaringType, property.PropertyType);
         Type writerType = typeof(DelegatePropertyWriter<,>).MakeGenericType(property.DeclaringType, property.PropertyType);
         if (property.CanWrite)
         {
             MethodInfo propertySetterMethodInfo = property.GetSetMethod();
             Delegate propertySetterDelegate = Delegate.CreateDelegate(
                 delegateWriterType,
                 propertySetterMethodInfo);
             writer = (IDelegatePropertyWriter)Activator.CreateInstance(writerType, propertySetterDelegate);
         }
     }
     return writer;
 }