//protected Type DiscoverFieldType(string value, ChoFileRecordConfiguration config) //{ // bool treatCurrencyAsDecimal = config.TreatCurrencyAsDecimal; // long lresult = 0; // double dresult = 0; // DateTime dtresult; // Decimal decResult = 0; // ChoCurrency currResult = 0; // Guid guidResult; // if (value == null) // return typeof(string); // else if (long.TryParse(value, out lresult)) // return typeof(long); // else if (double.TryParse(value, out dresult)) // return typeof(double); // else if (RecordConfiguration.TypeConverterFormatSpec.DateTimeFormat.IsNullOrWhiteSpace() // && ChoDateTime.TryParseExact(value, RecordConfiguration.TypeConverterFormatSpec.DateTimeFormat, CultureInfo.CurrentCulture, out dtResult)) // return typeof(DateTime); // else if (DateTime.TryParse(value, out dtresult)) // return typeof(DateTime); // else if (Guid.TryParse(value, out guidResult)) // return typeof(Guid); // else if (!treatCurrencyAsDecimal && ChoCurrency.TryParse(value, out currResult)) // return typeof(ChoCurrency); // else if (treatCurrencyAsDecimal && Decimal.TryParse(value, NumberStyles.Currency, CultureInfo.CurrentCulture, out decResult)) // return typeof(Decimal); // else // return typeof(string); //} protected object GetDeclaringRecord(string declaringMember, object rec, ChoFileRecordFieldConfiguration config = null) { if (rec == null) { return(null); } var obj = ChoType.GetDeclaringRecord(declaringMember, rec); if (obj == null) { return(null); } Type recordType = obj.GetType(); if (config != null) { if (config.ArrayIndex != null && config.ArrayIndex.Value >= 0 && obj is IEnumerable && !(obj is ArrayList)) { var item = Enumerable.Skip(((IEnumerable)obj).Cast <object>(), config.ArrayIndex.Value).FirstOrDefault(); if (item == null) { Type itemType = obj.GetType().GetItemType(); item = ChoActivator.CreateInstance(itemType); } if (obj is Array) { if (config.ArrayIndex.Value < ((Array)obj).Length) { ((Array)obj).SetValue(item, config.ArrayIndex.Value); } } else if (obj is IList) { ((IList)obj).Add(item); } return(item); } } return(obj); }
protected object GetDeclaringRecord(string declaringMember, object rec) { return(ChoType.GetDeclaringRecord(declaringMember, rec)); }
protected object GetDeclaringRecord(string declaringMember, object rec, int?arrayIndex = null, List <int> nestedArrayIndex = null) { return(ChoType.GetDeclaringRecord(declaringMember, rec, arrayIndex, nestedArrayIndex)); }