private bool TryConvert(out IEnumerable <T> result, out Exception exception) { List <T> convertedValues = new List <T>(); object convertedValue; { // foreach(var value in GetValuesToConvert()) var __enumerator1 = (GetValuesToConvert()).GetEnumerator(); while (__enumerator1.MoveNext()) { var value = (object)__enumerator1.Current; { if (value == null && mIgnoreNullElements) { continue; } if (!value.TryConvert(mDestinationType, out convertedValue, Culture, mConversionOptions)) { if (mIgnoreNonConvertibleElements) { continue; } result = null; exception = new InvalidConversionException(value, mDestinationType); return(false); } convertedValues.Add((T)convertedValue); } } } result = convertedValues; exception = null; return(true); }
private bool TryCreate(Type destinationType, IDictionary <string, object> propertyValues, CultureInfo culture, out object newInstance, out Exception exception) { if (propertyValues == null || propertyValues.Count == 0) { newInstance = destinationType.DefaultValue(); exception = new InvalidOperationException("The property value dictionary is null or empty."); return(false); } if (destinationType.IsPrimitive) { if (propertyValues.Count == 1) { if (TryConvert(propertyValues.Values.First(), destinationType, out newInstance, culture)) { exception = null; return(true); } exception = new InvalidConversionException(propertyValues.Values.First(), destinationType); return(false); } newInstance = destinationType.DefaultValue(); exception = new InvalidOperationException($"More than one value was given but {destinationType} is primitive and needs exactly one property value."); return(false); } Dictionary <string, object> ciDictionary; if (propertyValues is Dictionary <string, object> pvDic && (Equals(pvDic.Comparer, StringComparer.OrdinalIgnoreCase) || Equals(pvDic.Comparer, StringComparer.CurrentCultureIgnoreCase) || Equals(pvDic.Comparer, StringComparer.InvariantCultureIgnoreCase))) { ciDictionary = pvDic; }