/// <summary> /// Registers a type with a serialization surrogate. /// </summary> /// <param name="type">Type that the surrogate is for.</param> /// <param name="surrogate">Surrogate to serialize and deserialize the type.</param> public int RegisterType(Type type, IFudgeSerializationSurrogate surrogate) { int id = typeDataList.Count; var entry = new TypeData { Surrogate = surrogate, Type = type }; typeDataList.Add(entry); typeMap.Add(type, id); return(id); }
/// <summary> /// Creates a surrogate for a given type. /// </summary> /// <param name="type">Type for which to get surrogate.</param> /// <param name="fieldNameConvention">Convention for mapping .net property names to serialized field names.</param> /// <returns>Surrogate for the type.</returns> /// <exception cref="FudgeRuntimeException">Thrown if no surrogate can be automatically created.</exception> public virtual IFudgeSerializationSurrogate GetSurrogate(Type type, FudgeFieldNameConvention fieldNameConvention) { var typeData = typeDataCache.GetTypeData(type, fieldNameConvention); foreach (var selector in selectors) { IFudgeSerializationSurrogate surrogate = selector(context, typeData); if (surrogate != null) { return(surrogate); } } throw new FudgeRuntimeException("Cannot automatically determine surrogate for type " + type.FullName); }
/// <summary> /// Registers a type with a serialization surrogate. /// </summary> /// <param name="type">Type that the surrogate is for.</param> /// <param name="surrogate">Surrogate to serialize and deserialize the type.</param> public int RegisterType(Type type, IFudgeSerializationSurrogate surrogate) { int id = typeDataList.Count; var entry = new TypeData { Surrogate = surrogate, Type = type }; typeDataList.Add(entry); typeMap.Add(type, id); return id; }