public ChoObjectDataReaderProperty(string memberName, Type memberType) { ChoGuard.ArgumentNotNullOrEmpty(memberName, "MemberName"); //ChoGuard.ArgumentNotNullOrEmpty(memberType, "MemberType"); MemberName = memberName; ProperyType = memberType == null ? typeof(string) : memberType.GetUnderlyingType(); IsNullable = memberType == null ? true : memberType.IsNullableType() || memberType == typeof(string); ChoDataTableColumnTypeAttribute dtColumnType = ChoType.GetAttribute <ChoDataTableColumnTypeAttribute>(ProperyType); if (dtColumnType != null && dtColumnType.Type != null) { ProperyType = dtColumnType.Type; } }
public static bool IsValidFor(this object @this, string mn, out Exception aggEx) { ChoGuard.ArgumentNotNullOrEmpty(mn, "MemberName"); aggEx = null; MemberInfo mi = ChoType.GetMemberInfo(@this.GetType(), mn); if (mi != null) { return(IsValidFor(@this, mi, out aggEx)); } else { return(true); } }
public ChoXmlReader(string filePath, string defaultNamespace, ChoXmlRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); Configuration = configuration; Init(); if (!defaultNamespace.IsNullOrWhiteSpace()) { Configuration.NamespaceManager.AddNamespace("", defaultNamespace); } _sr = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize); //InitXml(); _closeStreamOnDispose = true; }
public static bool Contains(Type type) { ChoGuard.ArgumentNotNullOrEmpty(type, nameof(type)); var contains = Contains(type.Name); if (contains) { return(true); } lock (_padLock) { return(Get(type) != null); } }
public static JsonConverter Get(string name) { ChoGuard.ArgumentNotNullOrEmpty(name, nameof(name)); lock (_padLock) { if (_convertersCache.ContainsKey(name)) { return(_convertersCache[name]); } else { return(null); } } }
public static PropertyDescriptor GetProperty <T>(Type type, string propName) where T : Attribute { ChoGuard.ArgumentNotNull(type, "Type"); ChoGuard.ArgumentNotNullOrEmpty(propName, "PropName"); Init(type); lock (_pdDictLock) { return(_pdDict[type].Where(pd => pd.Name == propName && pd.Attributes.OfType <T>().Any()).FirstOrDefault()); } //return _pdDict[type].Where(pd => // pd.Name == propName && pd.Attributes.OfType<T>().Any()).FirstOrDefault(); }
private ChoIniFile(string iniFilePath, string sectionName = null) { ChoGuard.ArgumentNotNullOrEmpty(iniFilePath, "IniFilePath"); _iniFilePath = GetFullPath(iniFilePath); if (!_iniFilePath.EndsWith(".ini", StringComparison.InvariantCultureIgnoreCase)) { _iniFilePath = _iniFilePath + ".ini"; } _padLock = GetIniFileLockObject(_iniFilePath); _sectionName = sectionName; LoadIniFile(); Key = IniFileKey(_iniFilePath, sectionName); }
public ChoXmlReader(string filePath, ChoXmlRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); Configuration = configuration; Init(); _sr = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize); _xmlReader = XmlReader.Create(_sr, new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null }, new XmlParserContext(null, Configuration.NamespaceManager, null, XmlSpace.None)); _closeStreamOnDispose = true; }
public static T GetPropetyAttribute <T>(Type type, string propName) where T : Attribute { ChoGuard.ArgumentNotNull(type, "Type"); ChoGuard.ArgumentNotNullOrEmpty(propName, "PropName"); PropertyDescriptor pd = TypeDescriptor.GetProperties(type).AsTypedEnumerable <PropertyDescriptor>().Where(pd1 => pd1.Attributes.OfType <T>().Any()).FirstOrDefault(); if (pd == null) { return(null); } else { return(GetPropetyAttribute <T>(pd)); } }
public static JsonConverter Get(Type type) { ChoGuard.ArgumentNotNullOrEmpty(type, nameof(type)); var conv = Get(type.Name); if (conv != null) { return(conv); } lock (_padLock) { var convs = _convertersCache.Values.ToArray(); return(convs.Where(c => c.CanConvert(type)).FirstOrDefault()); } }
public ChoRecordFieldConfiguration(string name, ChoRecordFieldAttribute attr = null) { ChoGuard.ArgumentNotNullOrEmpty(name, "Name"); Name = name.NTrim(); if (!ChoETLFrxBootstrap.IsSandboxEnvironment) { Initialize(); } //FieldType = typeof(string); if (attr != null) { ErrorMode = attr.ErrorModeInternal; IgnoreFieldValueMode = attr.IgnoreFieldValueModeInternal; FieldType = attr.FieldType; } }
public void SetValue(string key, string value) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); if (value == null) { value = String.Empty; } if (!_keyValues.ContainsKey(key)) { _keyValues.Add(key, value); Save(); } else if (String.Compare(_keyValues[key], value, true) != 0) { _keyValues[key] = value; Save(); } }
public static void SetValue(string key, string value) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); if (value == null) { value = String.Empty; } if (Configuation.AppSettings.Settings[key] == null) { Configuation.AppSettings.Settings.Add(key, value); Save(); } else { Configuation.AppSettings.Settings[key].Value = value; Save(); } }
public static string[] ReadAllLines(string filePath) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); filePath = ChoPath.GetFullPath(filePath); if (File.Exists(filePath)) { return(File.ReadAllLines(filePath)); } else { try { File.CreateText(filePath); } catch { } return(new string[] {}); } }
public static IEnumerable <T> GetPropetyAttributes <T>(Type type, string propName) where T : Attribute { ChoGuard.ArgumentNotNull(type, "Type"); ChoGuard.ArgumentNotNullOrEmpty(propName, "PropName"); Init(type); PropertyDescriptor pd = _pdDict[type].Where(pd1 => pd1.Name == propName && pd1.Attributes.OfType <T>().Any()).FirstOrDefault(); if (pd == null) { return(Enumerable.Empty <T>()); } else { return(GetPropetyAttributes <T>(pd)); } }
public static ChoIntSequenceService NewService(string name, int seed = 0) { ChoGuard.ArgumentNotNullOrEmpty(name, "Name"); if (_counterDict.ContainsKey(name)) { throw new ApplicationException("'{0}' sequence service already exists.".FormatString(name)); } lock (_factoryLock) { if (_counterDict.ContainsKey(name)) { throw new ApplicationException("'{0}' sequence service already exists.".FormatString(name)); } _counterDict.Add(name, new ChoIntSequenceService(seed)); return(_counterDict[name]); } }
public static ChoSequenceGenerator GetSequenceGenerator(string name, int seed = 1, int step = 1) { ChoGuard.ArgumentNotNullOrEmpty(name, "Name"); if (_seqGenDict.ContainsKey(name)) { return(_seqGenDict[name]); } lock (_padLock) { if (_seqGenDict.ContainsKey(name)) { return(_seqGenDict[name]); } _seqGenDict.Add(name, new ChoSequenceGenerator(seed, step)); return(_seqGenDict[name]); } }
public static void Add(string name, JsonConverter converter) { ChoGuard.ArgumentNotNullOrEmpty(name, nameof(name)); if (converter == null) { return; } lock (_padLock) { if (_convertersCache.Value.ContainsKey(name)) { _convertersCache.Value.Add(name, converter); } else { _convertersCache.Value[name] = converter; } } }
public object this[string key] { get { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); return(_properties.ContainsKey(key) ? _properties[key] : null); } set { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); if (_properties.ContainsKey(key)) { _properties[key] = value; } else { _properties.Add(key, value); } } }
public static string GetValue(string key, string defaultValue = null, bool saveDefaultValue = false) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); if (Configuation.AppSettings.Settings[key] == null) { //_appConfig.AppSettings.Settings.Add(key, defaultValue == null ? String.Empty : defaultValue); Configuation.AppSettings.Settings.Add(key, saveDefaultValue ? defaultValue : String.Empty); if (saveDefaultValue) { Save(); } } //else if (_appConfig.AppSettings.Settings[key].Value.IsNullOrEmpty()) //{ // _appConfig.AppSettings.Settings[key].Value = defaultValue == null ? String.Empty : defaultValue; // Save(); //} return(Configuation.AppSettings.Settings[key].Value.IsNullOrWhiteSpace() ? defaultValue : Configuation.AppSettings.Settings[key].Value); }
public string GetValue(string key, string defaultValue = null, bool saveDefaultValue = false) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); if (!_keyValues.ContainsKey(key)) { if (!saveDefaultValue) { _keyValues.Add(key, null); } else { _keyValues.Add(key, defaultValue); } Save(); } //if (!saveDefaultValue) EventHandler <ChoIniKeyValueArgs> iniKeyValueResolve = IniKeyValueOverride; if (iniKeyValueResolve != null) { ChoIniKeyValueArgs a = new ChoIniKeyValueArgs() { IniFilePath = FilePath, SectionName = SectionName, IniKey = key, IniValue = _keyValues[key].IsNullOrEmpty() ? defaultValue : _keyValues[key] }; iniKeyValueResolve(this, a); return(a.IniValue); } else { return(_keyValues[key].IsNullOrEmpty() ? defaultValue : _keyValues[key]); } //else // return _keyValues[key]; }
public static bool IsValidFor(this object @this, PropertyDescriptor mi, out Exception aggEx) { aggEx = null; ChoGuard.ArgumentNotNullOrEmpty(@this, "Target"); if (@this == null) { return(true); } var results = new List <ValidationResult>(); object surrObj = ChoMetadataObjectCache.Default.GetMetadataObject(@this); bool result = false; if (surrObj is IChoValidatable) { result = ((IChoValidatable)surrObj).TryValidateFor(@this, mi.Name, results); } else { var context = new ValidationContext(@this, null, null); context.MemberName = mi.Name; result = Validator.TryValidateValue(mi.GetValue(@this), context, results, ChoTypeDescriptor.GetPropetyAttributes <ValidationAttribute>(ChoTypeDescriptor.GetProperty <ValidationAttribute>(@this.GetType(), mi.Name))); } if (!result) { if (results.Count > 0) { aggEx = new ValidationException("Failed to validate '{0}' member. {2}{1}".FormatString(mi.Name, ToString(results), Environment.NewLine)); } else { aggEx = new ValidationException("Failed to valudate."); } } return(result); }
public ChoObjectDataReaderProperty(MemberInfo info) { ChoGuard.ArgumentNotNullOrEmpty(info, "MemberInfo"); MemberInfo = info; ProperyType = ChoType.GetMemberType(MemberInfo).GetUnderlyingType(); var t = ChoType.GetMemberType(MemberInfo); var ra = ChoType.GetAttribute <RequiredAttribute>(info); var na = ChoType.GetAttribute <ChoIsNullableAttribute>(info); if (ra != null) { IsNullable = false; } else if (na != null) { IsNullable = na.Flag; } else { IsNullable = t.IsNullableType() || t == typeof(string) || t.IsClass(); } }
public ChoFixedLengthReader(string filePath, ChoFixedLengthRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); Configuration = configuration; Init(); _textReader = new Lazy <TextReader>(() => { if (Configuration.LiteParsing && !Configuration.TurnOffMemoryMappedFile) { _memoryMappedFile = MemoryMappedFile.CreateFromFile(filePath); return(new StreamReader(_memoryMappedFile.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))); } else { return(new StreamReader(filePath, Configuration.GetEncoding(filePath), false, Configuration.BufferSize)); } }); _closeStreamOnDispose = true; }
public static bool IsValidFor(this object @this, MemberInfo mi, out Exception aggEx) { aggEx = null; ChoGuard.ArgumentNotNullOrEmpty(@this, "Target"); if (@this == null) { return(true); } var results = new List <ValidationResult>(); object surrObj = ChoSurrogateObjectCache.Default.GetSurrogateObject(@this); if (surrObj is IChoValidatable) { ((IChoValidatable)surrObj).TryValidateFor(@this, mi.Name, results); } else { //if (ChoObjectMemberMetaDataCache.Default.IsRequired(mi) && ChoType.GetMemberValue(@this, mi) == null) // results.Add(new ValidationResult("Null value found for {0} member.".FormatString(mi.Name))); var context = new ValidationContext(@this, null, null); context.MemberName = mi.Name; Validator.TryValidateValue(ChoType.GetMemberValue(@this, mi), context, results, ChoTypeDescriptor.GetPropetyAttributes <ValidationAttribute>(ChoTypeDescriptor.GetProperty <ValidationAttribute>(@this.GetType(), mi.Name))); } if (results.Count > 0) { aggEx = new ApplicationException("Failed to validate '{0}' member. {2}{1}".FormatString(mi.Name, ToString(results), Environment.NewLine)); return(false); } else { return(true); } }
public static ChoIniFile New(string iniFilePath, string sectionName = null) { ChoGuard.ArgumentNotNullOrEmpty(iniFilePath, "IniFilePath"); string key = IniFileKey(iniFilePath, sectionName); if (_iniFiles.ContainsKey(key)) { return(_iniFiles[key]); } lock (_iniFileLockObjDictLock) { if (_iniFiles.ContainsKey(key)) { return(_iniFiles[key]); } ChoIniFile iniFile = new ChoIniFile(iniFilePath, sectionName); _iniFiles.Add(key, iniFile); return(_iniFiles[key]); } }
public static char Next(string chars) { ChoGuard.ArgumentNotNullOrEmpty(chars, "Chars"); return(ChoStringRandom.Next(chars, 1)[0]); }
public static T JsonDeserialize <T>(string JsonString, Encoding encoding = null) { ChoGuard.ArgumentNotNullOrEmpty(JsonString, "JsonString"); return((T)JsonDeserialize(JsonString, typeof(T), encoding)); }
public bool Contains(string key) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); return(_keyValues.ContainsKey(key)); }
public static bool Contains(string key) { ChoGuard.ArgumentNotNullOrEmpty(key, "Key"); return(Configuation.AppSettings.Settings.AllKeys.Contains(key)); }