internal SimpleDeserializer( IDataTypeMapper dataTypeMapper, ISerializerFactory serializerFactory, ICalendarComponentFactory componentFactory) { _dataTypeMapper = dataTypeMapper; _serializerFactory = serializerFactory; _componentFactory = componentFactory; }
public Caster(IDataTypeMapper dataTypeMapper , ICastEditor castEditor) { _dataTypeMapper = dataTypeMapper; _castEditor = castEditor; //PropertyTypesディレクトリから全てのPropertyType.dllをロードする this.LoadAllPropertyTypes(); }
private readonly IDataService _service; // Data service for accessing DataTypes #endregion Fields #region Constructors /// <summary> /// Ctor: Accepts injected dataservice /// </summary> /// <param name="dataService">The DataService instance being injected</param> /// <param name="dataTypeMapper">The mapper instance</param> public DatatypeController(IDataService dataService, IDataTypeMapper dataTypeMapper, IDataTypeLinkGenerator generator) { if (dataService == null) throw new ArgumentNullException("dataService", "No valid dataservice supplied to the controller."); if (dataTypeMapper == null) throw new ArgumentNullException("dataTypeMapper", "No valid mapper class supplied to the controller."); if (generator == null) throw new ArgumentNullException("generator", "No valid link generator supplied to the controller."); _service = dataService; _mapper = dataTypeMapper; _generator = generator; }
protected IStringSerializer GetMappedSerializer() { ISerializerFactory sf = GetService <ISerializerFactory>(); IDataTypeMapper mapper = GetService <IDataTypeMapper>(); if (sf != null && mapper != null) { object obj = SerializationContext.Peek(); // Get the data type for this object Type type = mapper.GetPropertyMapping(obj); if (type != null) { return(sf.Build(type, SerializationContext) as IStringSerializer); } else { return(new StringSerializer(SerializationContext)); } } return(null); }
public override string SerializeToString(object obj) { ICalendarProperty prop = obj as ICalendarProperty; if (prop != null && prop.Value != null) { // Don't serialize the property if the value is null // Push this object on the serialization context. SerializationContext.Push(prop); IDataTypeMapper mapper = GetService <IDataTypeMapper>(); Type serializedType = mapper.GetPropertyMapping(prop); // Build a list of values that are to be serialized. List <object> objs = new List <object>(); if (!(prop.Value is string) && !(typeof(IEnumerable <string>).IsAssignableFrom(serializedType)) && prop.Value is IEnumerable) { foreach (object v in (IEnumerable)prop.Value) { objs.Add(v); } } else { objs.Add(prop.Value); } // Get a serializer factory that we can use to serialize // the property and parameter values ISerializerFactory sf = GetService <ISerializerFactory>(); StringBuilder result = new StringBuilder(); foreach (object v in objs) { // Get a serializer to serialize the property's value. // If we can't serialize the property's value, the next step is worthless anyway. IStringSerializer valueSerializer = sf.Build(v.GetType(), SerializationContext) as IStringSerializer; if (valueSerializer != null) { // Iterate through each value to be serialized, // and give it a property (with parameters). // FIXME: this isn't always the way this is accomplished. // Multiple values can often be serialized within the // same property. How should we fix this? // NOTE: // We Serialize the property's value first, as during // serialization it may modify our parameters. // FIXME: the "parameter modification" operation should // be separated from serialization. Perhaps something // like PreSerialize(), etc. string value = valueSerializer.SerializeToString(v); // Get the list of parameters we'll be serializing ICalendarParameterList parameterList = prop.Parameters; if (v is ICalendarDataType) { parameterList = ((ICalendarDataType)v).Parameters; } StringBuilder sb = new StringBuilder(prop.Name); if (parameterList.Count > 0) { // Get a serializer for parameters IStringSerializer parameterSerializer = sf.Build(typeof(ICalendarParameter), SerializationContext) as IStringSerializer; if (parameterSerializer != null) { // Serialize each parameter List <string> parameters = new List <string>(); foreach (ICalendarParameter param in parameterList) { parameters.Add(parameterSerializer.SerializeToString(param)); } // Separate parameters with semicolons sb.Append(";"); sb.Append(string.Join(";", parameters.ToArray())); } } sb.Append(":"); sb.Append(value); result.Append(TextUtil.WrapLines(sb.ToString())); } } // Pop the object off the serialization context. SerializationContext.Pop(); return(result.ToString()); } return(null); }
public override string SerializeToString(object obj) { ICalendarProperty prop = obj as ICalendarProperty; if (prop != null) { // Don't serialize the property if the value is null // Push this object on the serialization context. SerializationContext.Push(prop); IDataTypeMapper mapper = GetService <IDataTypeMapper>(); Type serializedType = mapper.GetPropertyMapping(prop); // Get a serializer factory that we can use to serialize // the property and parameter values ISerializerFactory sf = GetService <ISerializerFactory>(); StringBuilder result = new StringBuilder(); if (prop.Values != null && prop.Values.Any()) { foreach (object v in prop.Values) { // Only serialize the value to a string if it // is non-null. if (v != null) { var valueType = v.GetType(); // Use the determined type of the value if the property // mapping didn't yield any results. if (serializedType == null) { serializedType = valueType; } var genericListOfSerializedType = typeof(IEnumerable <>).MakeGenericType(new Type[] { serializedType }); if (genericListOfSerializedType.IsAssignableFrom(valueType)) { // Serialize an enumerable list of properties foreach (object value in (IEnumerable)v) { SerializeValue(sf, prop, serializedType, value, result); } } else { // Serialize an individual value SerializeValue(sf, prop, valueType, v, result); } } } } else { // If there was no value, then we need to preserve an 'empty' value result.Append(TextUtil.WrapLines(prop.Name + ":")); } // Pop the object off the serialization context. SerializationContext.Pop(); return(result.ToString()); } return(null); }
public static void RegisterMapper(Type forType, IDataTypeMapper mapper) => m_mappers.AddOrUpdate(forType, mapper, (key, oldValue) => mapper);
public static bool TryGetMapper(Type forType, out IDataTypeMapper mapper) => m_mappers.TryGetValue(forType, out mapper);