private void CreateAttrTypeDictionary() { mAttrTypeDictionary = new Dictionary <string, Type>(); Assembly assembly = typeof(IParamProperty).Assembly; var actionParamPropertyAttributeTypes = from type in assembly.GetTypes() where typeof(IParamProperty).IsAssignableFrom(type) && type.IsInterface == false select type; foreach (Type t in actionParamPropertyAttributeTypes) { IParamProperty attr = (IParamProperty)Activator.CreateInstance(t); mAttrTypeDictionary.Add(attr.PropertyName, t); } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value == null) { serializer.Serialize(writer, null); return; } List <Attribute> attrs = (List <Attribute>)value; if (attrs.Count == 0) { serializer.Serialize(writer, null); return; } writer.WriteStartArray(); foreach (Attribute attr in attrs) { var properties = attr.GetType().GetProperties(); writer.WriteStartObject(); // First write property name so it will be first in the list writer.WritePropertyName("Property"); IParamProperty actionParamProperty = (IParamProperty)attr; string propertyName = actionParamProperty.PropertyName; serializer.Serialize(writer, propertyName); foreach (var property in properties) { if (property.Name == nameof(Attribute.TypeId) || property.Name == nameof(IParamProperty.PropertyName)) { continue; } // write property name writer.WritePropertyName(property.Name); serializer.Serialize(writer, property.GetValue(attr, null)); } writer.WriteEndObject(); } writer.WriteEndArray(); }