private ICompositeStorage TrySerializeInternal(object input, ISerializerContext context) { Ensure.NotNull(input, "input"); Ensure.NotNull(context, "context"); ICompositeModel model = input as ICompositeModel; if (model == null) { return(null); } ICompositeStorage storage = storageFactory.Create(); if (!typeNameMapper.TryGet(model.GetType(), out string typeName)) { return(null); } storage.Add(Name.TypeName, typeName); ICompositeStorage childStorage = storage.Add(Name.Payload); model.Save(childStorage); return(storage); }
/// <summary> /// Gets a <see cref="string"/> for <paramref name="type"/>. /// </summary> /// <param name="provider">A mapping provider.</param> /// <param name="type">A <see cref="Type"/>.</param> /// <returns>An associated <see cref="string"/> with <paramref name="type"/>.</returns> public static string Get(this ITypeNameMapper provider, Type type) { Ensure.NotNull(provider, "provider"); if (provider.TryGet(type, out string typeName)) { return(typeName); } throw new MissingTypeNameMappingException(type); }