public override object FormatValueFromDirectory(DirectoryAttribute value, string dn) { string str; if (value != null && value.Count > 0 && (str = value[0] as string) != null && !str.IsNullOrEmpty()) { try { if (DirectoryValueMappings != null && DirectoryValueMappings.ContainsKey(str)) { return(DirectoryValueMappings[str]); } var dateTime = _isFileTimeFormat ? DateTime.FromFileTime(long.Parse(str)) : str.FormatLdapDateTime(_dateFormat); return(dateTime); } catch (Exception ex) { ThrowMappingException(value, dn, ex); } } if (DirectoryValueMappings != null && DirectoryValueMappings.ContainsKey(string.Empty)) { return(DirectoryValueMappings[string.Empty]); } AssertNullable(dn); return(null); }
public override object FormatValueFromDirectory(DirectoryAttribute value, string dn) { if (value != null) { try { var strings = Array.ConvertAll(value.GetValues(typeof(string)), obj => obj.ToString()); if (_isNullable) { var dates = new DateTime?[strings.Length]; for (int i = 0; i < strings.Length; i++) { var str = strings[i]; var dateTime = _isFileTimeFormat ? DateTime.FromFileTime(long.Parse(str)) : str.FormatLdapDateTime(_dateFormat); dates[i] = dateTime; } return(dates); } else { var dates = new DateTime[strings.Length]; for (int i = 0; i < strings.Length; i++) { var str = strings[i]; var dateTime = _isFileTimeFormat ? DateTime.FromFileTime(long.Parse(str)) : str.FormatLdapDateTime(_dateFormat); dates[i] = dateTime; } return(dates); } } catch (Exception ex) { ThrowMappingException(value, dn, ex); } } if (DirectoryValueMappings != null && DirectoryValueMappings.ContainsKey(string.Empty)) { return(DirectoryValueMappings[string.Empty]); } AssertNullable(dn); return(null); }
public override object FormatValueFromDirectory(DirectoryAttribute value, string dn) { if (value != null) { try { var strings = Array.ConvertAll(value.GetValues(typeof(string)), obj => obj.ToString()); if (_isNullable) { var dates = new List <DateTime?>(strings.Length); dates.AddRange(strings.Select(str => new DateTime?(_isFileTimeFormat ? DateTime.FromFileTime(long.Parse(str)) : str.FormatLdapDateTime(_dateFormat)))); return(new Collection <DateTime?>(dates)); } else { var dates = new List <DateTime>(strings.Length); dates.AddRange(strings.Select(str => _isFileTimeFormat ? DateTime.FromFileTime(long.Parse(str)) : str.FormatLdapDateTime(_dateFormat))); return(new Collection <DateTime>(dates)); } } catch (Exception ex) { ThrowMappingException(value, dn, ex); } } if (DirectoryValueMappings != null && DirectoryValueMappings.ContainsKey(string.Empty)) { return(DirectoryValueMappings[string.Empty]); } AssertNullable(dn); return(null); }