protected override void Init(Type recordType) { base.Init(recordType); if (recordType == null) { return; } var pd = ChoTypeDescriptor.GetTypeAttribute <ChoJSONPathAttribute>(recordType); if (pd != null) { JSONPath = pd.JSONPath; AllowComplexJSONPath = pd.AllowComplexJSONPath; } ChoJSONRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoJSONRecordObjectAttribute>(recordType); if (recObjAttr != null) { } if (JSONRecordFieldConfigurations.Count == 0) { MapRecordFields(); // DiscoverRecordFields(recordType, false); } }
public static T CreateInstance <T>() where T : class { Type configObjType = typeof(T); if (typeof(ContextBoundObject).IsAssignableFrom(configObjType)) { return(ChoSingleton <T> .GetInstance(SingletonTypeValidationRules.AllowAll)); } else { if (!ChoObjectManagementFactory.IsCached(configObjType)) { //Load config file and assign values to object memebers ChoConfigurationSectionAttribute configurationElement = ChoType.GetAttribute(configObjType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configurationElement == null || configurationElement.GetMe(configObjType) == null) { throw new ChoConfigurationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1001, configObjType.Name)); } return((T)configurationElement.GetMe(configObjType).Construct(configObjType)); } else { return((T)ChoObjectManagementFactory.GetObject(configObjType)); } } }
protected override void Init(Type recordType) { base.Init(recordType); ChoFileRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoFileRecordObjectAttribute>(recordType); if (recObjAttr != null) { if (recObjAttr.BufferSize > 0) { BufferSize = recObjAttr.BufferSize; } if (recObjAttr.Comments.IsNullOrWhiteSpace()) { Comments = new string[] { } } ; else { Comments = recObjAttr.Comments.SplitNTrim(','); } Culture = recObjAttr.Culture; EOLDelimiter = recObjAttr.EOLDelimiter; IgnoreEmptyLine = recObjAttr.IgnoreEmptyLine; ColumnCountStrict = recObjAttr.ColumnCountStrict; ColumnOrderStrict = recObjAttr.ColumnOrderStrict; QuoteChar = recObjAttr.QuoteChar; QuoteAllFields = recObjAttr.QuoteAllFields; StringSplitOptions = recObjAttr.StringSplitOptions; if (!recObjAttr.Encoding.IsNullOrWhiteSpace()) { Encoding = Encoding.GetEncoding(recObjAttr.Encoding); } } }
public static object GetConfigOnly(Type type, XmlNode node) { //XmlSerializer serializer = new XmlSerializer(type); XmlSerializer serializer = XmlSerializer.FromTypes(new[] { type }).GetNValue(0); XmlRootAttribute xmlRootAttribute = ChoType.GetAttribute <XmlRootAttribute>(type); if (xmlRootAttribute == null) { throw new NullReferenceException(String.Format("Missing XmlRootAttribute in {0} type.", type.FullName)); } if (String.IsNullOrEmpty(xmlRootAttribute.ElementName)) { throw new NullReferenceException(String.Format("Missing XmlRootAttribute(ElementName) in {0} type.", type.FullName)); } node = node.SelectSingleNode(String.Format("//{0}", xmlRootAttribute.ElementName)); object configObject = null; if (node != null) { configObject = serializer.Deserialize(new XmlNodeReader(node)); } else { configObject = Activator.CreateInstance(type); } return(configObject); }
public static string GetHelpText(Type configObjectType) { if (configObjectType == null) { return(null); } if (!typeof(ChoConfigurableObject).IsAssignableFrom(configObjectType)) { return(null); } ChoConfigurationSectionAttribute configurationElementAttribute = ChoType.GetAttribute(configObjectType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configurationElementAttribute == null) { return(null); } ChoBaseConfigurationElement ele = configurationElementAttribute.GetMe(configObjectType); if (ele == null) { return(null); } return(ele.GetHelpText(configObjectType)); }
public static object GetConfig(Type type, XmlNode node) { XmlSerializer serializer = new XmlSerializer(type); XmlRootAttribute xmlRootAttribute = ChoType.GetAttribute <XmlRootAttribute>(type); if (xmlRootAttribute == null) { throw new NullReferenceException(String.Format("Missing XmlRootAttribute in {0} type.", type.FullName)); } if (String.IsNullOrEmpty(xmlRootAttribute.ElementName)) { throw new NullReferenceException(String.Format("Missing XmlRootAttribute(ElementName) in {0} type.", type.FullName)); } node = node.SelectSingleNode(String.Format("//{0}", xmlRootAttribute.ElementName)); object configObject = null; if (node != null) { configObject = serializer.Deserialize(new XmlNodeReader(node)); } else { configObject = ChoObjectManagementFactory.CreateInstance(type); } ChoObjectInitializer.Initialize(configObject); return(configObject); }
public static Type GetType(string registryKey, out ChoRegistrySectionAttribute1 registrySectionAttribute) { registrySectionAttribute = null; Type[] types = ChoType.GetTypes(typeof(ChoRegistrySectionAttribute1)); if (types == null || types.Length == 0) { return(null); } foreach (Type type in types) { if (type == null) { continue; } ChoRegistrySectionAttribute1 lRegistrySectionAttribute = ChoType.GetAttribute(type, typeof(ChoRegistrySectionAttribute1)) as ChoRegistrySectionAttribute1; if (lRegistrySectionAttribute == null) { continue; } if (String.Compare(lRegistrySectionAttribute.RegistryKey, registryKey, true) == 0) { registrySectionAttribute = lRegistrySectionAttribute; return(type); } } return(null); }
private static string GetDisplayName(PropertyInfo pi, string defaultValue = null) { if (pi != null) { DisplayNameAttribute dnAttr = ChoType.GetAttribute <DisplayNameAttribute>(pi); if (dnAttr != null && !dnAttr.DisplayName.IsNullOrWhiteSpace()) { return(dnAttr.DisplayName.Trim()); } else { DisplayAttribute dpAttr = ChoType.GetAttribute <DisplayAttribute>(pi); if (dpAttr != null) { if (!dpAttr.ShortName.IsNullOrWhiteSpace()) { return(dpAttr.ShortName.Trim()); } else if (!dpAttr.Name.IsNullOrWhiteSpace()) { return(dpAttr.Name.Trim()); } } } return(defaultValue == null ? pi.Name : defaultValue); } else { return(defaultValue); } }
public virtual ChoPlugIn CreatePlugIn() { ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(GetType()); if (plugInAttribute == null) { throw new ChoPlugInException("Missing ChoPlugInAttribute decorated for '{0}' plugin builder.".FormatString(GetType().Name)); } Type type = plugInAttribute.PlugInType; if (type == null) { throw new ChoPlugInException("Can't find plugin for '{0}' plugin builder.".FormatString(GetType().Name)); } ChoPlugIn p = ChoActivator.CreateInstance(type) as ChoPlugIn; if (p == null) { throw new ChoPlugInException("Can't find plugin for '{0}' plugin builder.".FormatString(GetType().Name)); } InitPlugIn(p); return(p); }
private static void DoObjectMemberValidation(object target) { if (target == null) { return; } if (target.GetType().IsPrimitive || target is string || target is Enum ) { } else { //Call the initialize to all members foreach (FieldInfo fieldInfo in ChoType.GetFields(target.GetType())) { if (fieldInfo.IsReadOnly()) { continue; } object fieldValue = ChoType.GetFieldValue(target, fieldInfo.Name); if (fieldValue == null) { continue; } if (!(fieldValue is string) && fieldValue is IEnumerable) { foreach (object fieldItemValue in (IEnumerable)fieldValue) { DoObjectMemberValidation(fieldItemValue); } } else { DoObjectMemberValidation(fieldValue); } } } if (target != null && !(target is ChoRealProxy)) { //Do Validate ChoDoObjectValidationAfterInitializationAttribute doObjectValidationAfterInitializationAttribute = ChoType.GetAttribute <ChoDoObjectValidationAfterInitializationAttribute>(target.GetType()); if (doObjectValidationAfterInitializationAttribute != null && doObjectValidationAfterInitializationAttribute.DoObjectValidation) { ChoValidationResults validationResults = ChoValidation.Validate(target); if (validationResults != null && validationResults.Count > 0) { throw new ChoValidationException("Failed to validate object.", validationResults); } } } }
public ChoSingletonObject() { _singletonAttribute = ChoType.GetAttribute(GetType(), typeof(ChoSingletonAttribute)) as ChoSingletonAttribute; if (_singletonAttribute == null) { throw new ChoFatalApplicationException("Missing singleton attribute defined for '{0}' type.".FormatString(GetType().Name)); } }
static ChoMetadataTypesRegister() { foreach (Type type in ChoType.GetTypes(typeof(MetadataTypeAttribute))) { MetadataTypeAttribute attrib = ChoType.GetAttribute <MetadataTypeAttribute>(type); TypeDescriptor.AddProviderTransparent( new AssociatedMetadataTypeTypeDescriptionProvider(type, attrib.MetadataClassType), type); } }
private static ChoObjectValidationMode GetValidationMode(object value) { if (value == null) { return(ChoObjectValidationMode.Off); } ChoObjectAttribute attr = ChoType.GetAttribute <ChoObjectAttribute>(value.GetType()); return(attr != null ? attr.ObjectValidationMode : ChoObjectValidationMode.Off); }
private static PropertyInfo[] GetPropertyInfos <T>() { PropertyInfo[] props = null; if (!_propInfoCache.TryGetValue(typeof(T), out props)) { props = ChoType.GetProperties(typeof(T)).OrderBy(pi => ChoType.GetAttribute <ColumnAttribute>(pi) == null ? 0 : ChoType.GetAttribute <ColumnAttribute>(pi).Order).ToArray(); _propInfoCache.AddOrUpdate(typeof(T), props); } return(props); }
public virtual void SetParams(string cmdParams) { foreach (Tuple <string, string> tuple in ChoStringEx.ToKeyValuePairs(cmdParams, ';', '=')) { MemberInfo memberInfo = ChoType.GetMemberInfo(this.GetType(), tuple.Item1); if (memberInfo != (MemberInfo)null && ChoType.GetAttribute <BrowsableAttribute>(memberInfo, false) == null) { ChoType.ConvertNSetMemberValue((object)this, tuple.Item1, (object)DenormalizeString(tuple.Item2)); } } }
private static bool HasFormatterSpecified(object target) { if (target == null) { return(false); } ChoTypeFormatterAttribute objectFormatter = ChoType.GetAttribute(target.GetType(), typeof(ChoTypeFormatterAttribute)) as ChoTypeFormatterAttribute; return(objectFormatter == null ? false : objectFormatter.HasFormatSpecified); }
internal static string GetPlugInName(Type plugInBuilderType) { ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(plugInBuilderType); if (plugInAttribute == null) { throw new ChoPlugInException("Missing ChoPlugInAttribute decorated for '{0}' plugin builder.".FormatString(plugInBuilderType.Name)); } return(plugInAttribute.Name); }
protected virtual void Init(Type recordType) { ChoRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoRecordObjectAttribute>(recordType); if (recObjAttr != null) { ErrorMode = recObjAttr.ErrorMode; IgnoreFieldValueMode = recObjAttr.IgnoreFieldValueMode; ThrowAndStopOnMissingField = recObjAttr.ThrowAndStopOnMissingField; ObjectValidationMode = recObjAttr.ObjectValidationMode; } }
protected override void Init(Type recordType) { base.Init(recordType); ChoXmlRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoXmlRecordObjectAttribute>(recordType); if (recObjAttr != null) { } DiscoverRecordFields(recordType); }
protected override void Init(Type recordType) { base.Init(recordType); ChoCSVRecordObjectAttribute recObjAttr = ChoType.GetAttribute<ChoCSVRecordObjectAttribute>(recordType); if (recObjAttr != null) { Delimiter = recObjAttr.Delimiter; HasExcelSeparator = recObjAttr._hasExcelSeparator; } DiscoverRecordFields(recordType); }
private void Init(Type recordType) { ChoFileHeaderAttribute recObjAttr = ChoType.GetAttribute <ChoFileHeaderAttribute>(recordType); if (recObjAttr != null) { HasHeaderRecord = true; IgnoreCase = recObjAttr.IgnoreCase; FillChar = recObjAttr.FillChar == '\0' ? ' ' : recObjAttr.FillChar; Justification = recObjAttr.Justification; TrimOption = recObjAttr.TrimOption; } }
protected override void Init(Type recordType) { base.Init(recordType); ChoFixedLengthRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoFixedLengthRecordObjectAttribute>(recordType); if (recObjAttr != null) { RecordLength = recObjAttr.RecordLength; } DiscoverRecordFields(recordType); }
public static void RefreshConfig(object configObject) { ChoGuard.ArgumentNotNull(configObject, "Config Object."); ChoConfigurationSectionAttribute configurationElementAttribute = ChoType.GetAttribute(configObject.GetType(), typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configurationElementAttribute == null) { return; } configurationElementAttribute.GetMe(configObject.GetType()).Refresh(true); }
public ChoObjectDataReaderProperty(string memberName, Type memberType) { ChoGuard.ArgumentNotNullOrEmpty(memberName, "MemberName"); //ChoGuard.ArgumentNotNullOrEmpty(memberType, "MemberType"); MemberName = memberName; ProperyType = memberType == null ? typeof(string) : memberType.GetUnderlyingType(); ChoDataTableColumnTypeAttribute dtColumnType = ChoType.GetAttribute <ChoDataTableColumnTypeAttribute>(ProperyType); if (dtColumnType != null && dtColumnType.Type != null) { ProperyType = dtColumnType.Type; } }
public override object DoObjectInitialize(object target) { base.DoObjectInitialize(target); Type objType = target.GetType(); ChoCommandLineArgObjectAttribute commandLineArgumentsObjectAttribute = ChoType.GetAttribute(objType, typeof(ChoCommandLineArgObjectAttribute)) as ChoCommandLineArgObjectAttribute; if (commandLineArgumentsObjectAttribute == null || commandLineArgumentsObjectAttribute.GetMe(objType) == null) { throw new ApplicationException("Missing ChoCommandLineArgumentsObjectAttribute attribute in {0} type.".FormatString(objType.FullName)); } return(commandLineArgumentsObjectAttribute.GetMe(objType).Construct(target)); }
public override object DoObjectInitialize(object target) { base.DoObjectInitialize(target); Type configObjType = target.GetType(); ChoConfigurationSectionAttribute configurationElement = ChoType.GetAttribute(configObjType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configurationElement == null || configurationElement.GetMe(configObjType) == null) { throw new ChoConfigurationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1001, configObjType.Name)); } return(configurationElement.GetMe(configObjType).Construct(target)); }
protected override void Init(Type recordType) { base.Init(recordType); if (recordType == null) return; ChoJSONRecordObjectAttribute recObjAttr = ChoType.GetAttribute<ChoJSONRecordObjectAttribute>(recordType); if (recObjAttr != null) { } if (JSONRecordFieldConfigurations.Count == 0) DiscoverRecordFields(recordType, false); }
public ChoObjectDataReaderProperty(string memberName, Type memberType, bool isSimpleType = false) { ChoGuard.ArgumentNotNullOrEmpty(memberName, "MemberName"); //ChoGuard.ArgumentNotNullOrEmpty(memberType, "MemberType"); _isSimpleType = isSimpleType; MemberName = memberName; ProperyType = memberType == null ? typeof(string) : memberType.GetUnderlyingType(); IsNullable = true; // memberType == null ? true : memberType.IsNullableType() || memberType == typeof(string) || !memberType.IsValueType; ChoDataTableColumnTypeAttribute dtColumnType = ChoType.GetAttribute <ChoDataTableColumnTypeAttribute>(ProperyType); if (dtColumnType != null && dtColumnType.Type != null) { ProperyType = dtColumnType.Type; } }
protected override void Init(Type recordType) { base.Init(recordType); ChoXmlRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoXmlRecordObjectAttribute>(recordType); if (recObjAttr != null) { } if (XmlRecordFieldConfigurations.Count == 0) { DiscoverRecordFields(recordType); } }
protected override void Init(Type recordType) { base.Init(recordType); ChoKVPRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoKVPRecordObjectAttribute>(recordType); if (recObjAttr != null) { Separator = recObjAttr.Separator; RecordStart = recObjAttr.RecordStart; RecordEnd = recObjAttr.RecordEnd; LineContinuationChars = recObjAttr.LineContinuationChars; } DiscoverRecordFields(recordType); }