internal protected override object GetMapData(object[] attributes, string scope) { DataType itemDataType = null; Type itemType = null; ItemPropertyAttribute at = FindPropertyAttribute(attributes, scope + "/*"); if (at != null) { itemType = at.ValueType; if (itemType == null) { itemType = handler.GetItemType(); } if (at.SerializationDataType != null) { itemDataType = (DataType)Activator.CreateInstance(at.SerializationDataType, new object[] { itemType }); } } if (itemType == null) { itemType = handler.GetItemType(); } if (itemDataType == null) { itemDataType = Context.GetConfigurationDataType(itemType); } object itemMapData = itemDataType.GetMapData(attributes, scope + "/*"); if (at == null && itemMapData == null) { return(null); } MapData data = new MapData(); data.ItemType = itemDataType; data.ItemName = (at != null && at.Name != null) ? at.Name : itemDataType.Name; data.ItemMapData = itemMapData; return(data); }
void AddProperty(object member, string name, Type memberType) { // Using inherit=false because if a base class already has an ItemProperty applied to the property // then that property will already have been added while copying props from the base class. object[] ats = Context.AttributeProvider.GetCustomAttributes(member, typeof(Attribute), false); ItemPropertyAttribute at = FindPropertyAttribute(ats, ""); if (at == null) { return; } ItemProperty prop = new ItemProperty(); prop.Name = (at.Name != null) ? at.Name : name; prop.ExpandedCollection = Context.AttributeProvider.IsDefined(member, typeof(ExpandedCollectionAttribute), true); prop.DefaultValue = at.DefaultValue; prop.IsExternal = at.IsExternal; prop.SkipEmpty = at.SkipEmpty; prop.ReadOnly = at.ReadOnly; prop.WriteOnly = at.WriteOnly; if (prop.ExpandedCollection) { ICollectionHandler handler = Context.GetCollectionHandler(memberType); if (handler == null) { throw new InvalidOperationException("ExpandedCollectionAttribute can't be applied to property '" + prop.Name + "' in type '" + ValueType + "' becuase it is not a valid collection."); } memberType = handler.GetItemType(); prop.ExpandedCollectionHandler = handler; } if (at.ValueType != null) { prop.PropertyType = at.ValueType; } else { prop.PropertyType = memberType; } if (at.SerializationDataType != null) { try { prop.DataType = (DataType)Activator.CreateInstance(at.SerializationDataType, new object[] { prop.PropertyType }); } catch (MissingMethodException ex) { throw new InvalidOperationException("Constructor not found for custom data type: " + at.SerializationDataType.Name + " (Type propertyType);", ex); } } if (member is MemberInfo) { prop.Member = (MemberInfo)member; AddProperty(prop); } else { prop.InitValue = ((ItemMember)member).InitValue; AddProperty(prop, ((ItemMember)member).InsertBefore); } prop.Initialize(ats, ""); if (prop.ExpandedCollection && prop.DataType.IsSimpleType) { throw new InvalidOperationException("ExpandedCollectionAttribute is not allowed in collections of simple types"); } }