private static CommandPropertySpec BuildPropertySpecForType(Type t) { int length = GetLengthFromAttribute(t); var props = new List <PropertySpec>(); var rawProps = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(prop => prop.GetCustomAttribute <NoSerializeAttribute>() == null); foreach (PropertyInfo prop in rawProps) { SerializeAttribute attr = prop.GetCustomAttribute <SerializeAttribute>(); if (attr == null) // This means the property shouldnt be serialized { continue; } SerializableAttributeBase serAttr = prop.GetCustomAttribute <SerializableAttributeBase>(); if (serAttr == null) { throw new SerializationException(t.Name, "Missing serialization definition on property {0}", prop.Name); } MethodInfo tmpSetter = prop.CanWrite ? prop.GetSetMethod(true) : null; MethodInfo tmpGetter = prop.GetGetMethod(true); Delegate setter = tmpSetter != null?Delegate.CreateDelegate(Expression.GetActionType(t, prop.PropertyType), tmpSetter) : null; Delegate getter = tmpGetter != null?Delegate.CreateDelegate(Expression.GetFuncType(t, prop.PropertyType), tmpGetter) : null; bool isCommandId = prop.GetCustomAttribute <CommandIdAttribute>() != null; props.Add(new PropertySpec(setter, getter, serAttr, attr, prop, isCommandId)); } return(_propertySpecCache[t] = new CommandPropertySpec(length, props)); }
public PropertySpec(Delegate setter, Delegate getter, SerializableAttributeBase serAttr, SerializeAttribute attr, PropertyInfo propInfo, bool isCommandId) { Setter = setter; Getter = getter; SerAttr = serAttr; Attr = attr; PropInfo = propInfo; IsCommandId = isCommandId; }