public static object Unstage(StageItem item, Type targetType) { if (item is StageNull) { return(null); } IStager stager = SerializationMaster.GetStager(targetType); if (stager != null) { return(stager.UnstageValue(item, targetType)); } StageValue stageValue = item as StageValue; if (stageValue == null) { StageElement stageElement = item as StageElement; if (stageElement == null) { throw new SerializationException(string.Concat("Unable to unstage, the element is not supported: ", targetType.Name)); } return(SerializationMaster.ReflectIn(stageElement)); } IValueConverter converter = SerializationMaster.GetConverter(targetType); if (converter == null) { throw new SerializationException(string.Concat("Unable to unstage, no converter or stager was found for type: ", targetType.Name)); } return(converter.FromString(stageValue.@value, targetType)); }
public static StageItem Stage(string name, object value) { if (value == null) { return(new StageNull(name)); } Type type = value.GetType(); IPrepareForSerialization prepareForSerialization = value as IPrepareForSerialization; if (prepareForSerialization != null) { prepareForSerialization.Prepare(); } IStager stager = SerializationMaster.GetStager(type); if (stager != null) { return(stager.StageValue(name, value)); } IValueConverter converter = SerializationMaster.GetConverter(type); if (converter == null) { return(SerializationMaster.ReflectOut(name, value)); } return(new StageValue(name, converter.ToString(value), type == SerializationMaster._stringType)); }
public static string ToString(object value) { if (value == null) { return(null); } IValueConverter converter = SerializationMaster.GetConverter(value.GetType()); if (converter == null) { throw new ArgumentException(string.Concat("No converter was found for type ", value.GetType())); } return(converter.ToString(value)); }
public static T FromString <T>(string value) { if (value == null) { return(default(T)); } Type type = typeof(T); IValueConverter converter = SerializationMaster.GetConverter(type); if (converter == null) { throw new ArgumentException(string.Concat("No converter was found for type ", type.Name)); } return((T)converter.FromString(value, type)); }