public object ConvertTo(object source, Type type) { if (source == null) { throw new ArgumentNullException(nameof(source)); } Type st = source.GetType(); if (st != ModelType && !st.IsSubclassOf(ModelType)) { throw new ArgumentException("Source type mismatch."); } return(ModelConvert.Convert(source, type, Options)); }
public static IEnumerable <TTarget> Convert <TTarget>(this IEnumerable coll, ModelConvertOptions options) { Type sourceType = coll.GetType(); if (sourceType.IsGenericType) { sourceType = sourceType.GetGenericArguments()[0]; if (options == null) { options = new ModelConvertOptions(); } options.Source(sourceType); } foreach (object obj in coll) { yield return(ModelConvert.Convert <TTarget>(obj, options)); } }
public object ConvertTo(Type type) { return(ModelConvert.Convert(Value, type, Options)); }