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 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)); }