/// <summary>Gathers persitent fields for a type.</summary> /// <param name="type">A type of to gather persistent fields for.</param> /// <param name="needStatic">Specifies if static fields need to be returned.</param> /// <param name="needInstance">Specifies if non-static fields need to be returned.</param> /// <param name="group">A filter group for the persitent fields. Note that group is ignored for /// the inner fields of a compound type.</param> /// <returns>List of persitent fields.</returns> public static List <PersistentField> GetPersistentFields( Type type, bool needStatic, bool needInstance, string group) { var result = new List <PersistentField>(); var fieldsInfo = FindAnnotatedFields(type, needStatic, needInstance, group); foreach (var fieldInfo in fieldsInfo) { var fieldAttr = fieldInfo.GetCustomAttributes(typeof(BasePersistentFieldAttribute), true).First() as PersistentFieldAttribute; try { var persistentField = new PersistentField(fieldInfo, fieldAttr); result.Add(persistentField); } catch (Exception ex) { DebugEx.Error( "Ignoring field {0}.{1}: {2}\n{3}", type.FullName, fieldInfo.Name, ex.Message, ex.StackTrace); } } // Sort by config path to ensure the most top level nodes are handled before the children. result = result.OrderBy(x => string.Join("/", x.cfgPath)).ToList(); return(result); }
/// <param name="persistentField">A persitent field descriptor.</param> /// <param name="valueType">A type to handle. If field is a collection then this type is a type of /// the collection's item.</param> /// <param name="simpleTypeProtoType">A proto that handles (de)serializing (in)to a simple string. /// if this proto cannot handle <paramref name="valueType"/> then the type will be attempted to be /// handled as a complex type.</param> internal OrdinaryFieldHandler( PersistentField persistentField, Type valueType, Type simpleTypeProtoType) { this.persistentField = persistentField; this.valueType = valueType; this.simpleTypeProto = Activator.CreateInstance(simpleTypeProtoType) as AbstractOrdinaryValueTypeProto; }
/// <param name="persistentField">A descriptor of persistent field which holds the value.</param> /// <param name="collectionType">A type of the collection this handler will be handling.</param> /// <param name="collectionProtoType">A proto type that can work with the collection.</param> internal CollectionFieldHandler( PersistentField persistentField, Type collectionType, Type collectionProtoType) { this.collectionType = collectionType; this.persistentField = persistentField; this.collectionProto = Activator.CreateInstance(collectionProtoType, new[] { collectionType }) as AbstractCollectionTypeProto; if (this.collectionProto == null) { throw new ArgumentException(string.Format("Bad collection proto {0}", collectionProtoType)); } }