public TimeSpanConfigurationProperty(string name, TimeSpan defaultValue, TimeSpanSerializedFormat format, TimeSpanPropertyFlags tsflags, ConfigurationPropertyOptions flags) : base(name, typeof(TimeSpan), defaultValue, flags) { _format = format; _tsflags = tsflags; }
private void ConstructorInit(string name, System.Type type, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator, TypeConverter converter) { if (typeof(ConfigurationSection).IsAssignableFrom(type)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_properties_may_not_be_derived_from_configuration_section", new object[] { name })); } this._providedName = name; if (((options & ConfigurationPropertyOptions.IsDefaultCollection) != ConfigurationPropertyOptions.None) && string.IsNullOrEmpty(name)) { name = DefaultCollectionPropertyName; } else { this.ValidatePropertyName(name); } this._name = name; this._type = type; this._options = options; this._validator = validator; this._converter = converter; if (this._validator == null) { this._validator = DefaultValidatorInstance; } else if (!this._validator.CanValidate(this._type)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Validator_does_not_support_prop_type", new object[] { this._name })); } }
public ConfigurationProperty ( string name, Type type, object default_value, TypeConverter converter, ConfigurationValidatorBase validation, ConfigurationPropertyOptions flags) : this (name, type, default_value, converter, validation, flags, null) { }
public IntegerConfigurationProperty(string name, int defaultValue, int minimumValue, int maximumValue, ConfigurationPropertyOptions flags) : base(name, typeof(int), defaultValue, flags) { _min = minimumValue; _max = maximumValue; }
public ConfigurationProperty(String name, Type type, Object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options) : this(name, type, defaultValue, typeConverter, validator, options, null) { }
public ConfigurationProperty( string name, Type type, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options) : this(name, type, defaultValue, typeConverter, validator, options, null) { }
public ConfigurationProperty( string name, Type type, object default_value, TypeConverter converter, ConfigurationValidatorBase validation, ConfigurationPropertyOptions flags) : this(name, type, default_value, converter, validation, flags, null) { }
protected internal static ConfigurationProperty Register( string name, Type type, Type declaringType, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options) => ConfigurationElement.Register(declaringType, new ConfigurationProperty(name, type, defaultValue, typeConverter, validator, options, null));
public static ConfigurationProperty Item(string name, ConfigurationPropertyOptions options) { return(new ConfigurationProperty(name, typeof(T), null, new ConfigurationConverter <T>(), new ConfigurationValidator <T>(), options)); }
public ConfigurationProperty(String name, Type type, Object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description) { ConstructorInit(name, type, options, validator, typeConverter); SetDefaultValue(defaultValue); }
public ConfigurationProperty(string name, Type type, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description) { ConstructorInit(name, type, options, validator, typeConverter); SetDefaultValue(defaultValue); }
protected internal static ConfigurationProperty Register( string name, Type type, Type declaringType, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description) { return(Register(declaringType, new ConfigurationProperty(name, type, defaultValue, typeConverter, validator, options, description))); }
public static void AddStringProperty( this ConfigurationPropertyCollection properties, string name, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options = ConfigurationPropertyOptions.IsRequired) { // http://stackoverflow.com/questions/3744953/why-does-configurationvalidator-validate-the-default-value-of-a-configurationprop properties.Add(new ConfigurationProperty( name: name, type: typeof(string), defaultValue: null, typeConverter: null, validator: validator, options: options)); }
public ListenerElement(bool allowReferences) : base(typeof(TraceListener)) { this._allowReferences = allowReferences; ConfigurationPropertyOptions none = ConfigurationPropertyOptions.None; if (!this._allowReferences) { none |= ConfigurationPropertyOptions.IsRequired; } this._propListenerTypeName = new ConfigurationProperty("type", typeof(string), null, none); base._properties.Remove("type"); base._properties.Add(this._propListenerTypeName); base._properties.Add(_propFilter); base._properties.Add(_propName); base._properties.Add(_propOutputOpts); }
private void ConstructorInit( string name, Type type, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator, TypeConverter converter, string description) { if (typeof(ConfigurationSection).IsAssignableFrom(type)) { throw new ConfigurationErrorsException( SR.Format(SR.Config_properties_may_not_be_derived_from_configuration_section, name)); } // save the provided name so we can check for default collection names ProvidedName = name; if (((options & ConfigurationPropertyOptions.IsDefaultCollection) != 0) && string.IsNullOrEmpty(name)) { name = DefaultCollectionPropertyName; } else { ValidatePropertyName(name); } Name = name; Description = description; Type = type; _options = options; Validator = validator; _converter = converter; // Use the default validator if none was supplied if (Validator == null) { Validator = s_defaultValidatorInstance; } else { // Make sure the supplied validator supports the type of this property if (!Validator.CanValidate(Type)) { throw new ConfigurationErrorsException(SR.Format(SR.Validator_does_not_support_prop_type, Name)); } } }
public ConfigurationProperty( string name, Type type, object defaultValue, TypeConverter converter, ConfigurationValidatorBase validation, ConfigurationPropertyOptions flags, string description) { Name = name; Converter = converter ?? TypeDescriptor.GetConverter(type); if (defaultValue != null) { if (defaultValue == NoDefaultValue) { switch (Type.GetTypeCode(type)) { case TypeCode.Object: defaultValue = null; break; case TypeCode.String: defaultValue = string.Empty; break; default: defaultValue = Activator.CreateInstance(type); break; } } else if (!type.GetTypeInfo().IsAssignableFrom(defaultValue.GetType())) { if (!Converter.CanConvertFrom(defaultValue.GetType())) { throw new ConfigurationErrorsException( string.Format( "The default value for property '{0}' has a different type than the one of the property itself: expected {1} but was {2}", name, type, defaultValue.GetType())); } defaultValue = Converter.ConvertFrom(defaultValue); } } DefaultValue = defaultValue; _flags = flags; Type = type; Validator = validation ?? new DefaultValidator(); Description = description; }
public ConfigurationProperty( string name, Type type, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description) { this.name = name; this.converter = typeConverter != null ? typeConverter : TypeDescriptor.GetConverter(type); if (defaultValue != null) { if (defaultValue == NoDefaultValue) { switch (Type.GetTypeCode(type)) { case TypeCode.Object: defaultValue = null; break; case TypeCode.String: defaultValue = String.Empty; break; default: defaultValue = Activator.CreateInstance(type); break; } } else if (!type.IsAssignableFrom(defaultValue.GetType())) { if (!this.converter.CanConvertFrom(defaultValue.GetType())) { throw new ConfigurationErrorsException(String.Format("The default value for property '{0}' has a different type than the one of the property itself: expected {1} but was {2}", name, type, defaultValue.GetType())); } defaultValue = this.converter.ConvertFrom(defaultValue); } } this.default_value = defaultValue; this.flags = options; this.type = type; this.validation = validator != null ? validator : new DefaultValidator(); this.description = description; }
public ListenerElement(bool allowReferences) : base(typeof(TraceListener)) { _allowReferences = allowReferences; ConfigurationPropertyOptions flags = ConfigurationPropertyOptions.None; if (!_allowReferences) { flags |= ConfigurationPropertyOptions.IsRequired; } _propListenerTypeName = new ConfigurationProperty("type", typeof(string), null, flags); _properties.Remove("type"); _properties.Add(_propListenerTypeName); _properties.Add(_propFilter); _properties.Add(_propName); _properties.Add(_propOutputOpts); }
public ConfigurationProperty ( string name, Type type, object default_value, TypeConverter converter, ConfigurationValidatorBase validation, ConfigurationPropertyOptions flags, string description) { this.name = name; this.converter = converter != null ? converter : TypeDescriptor.GetConverter (type); if (default_value != null) { if (default_value == NoDefaultValue) { switch (Type.GetTypeCode (type)) { case TypeCode.Object: default_value = null; break; case TypeCode.String: default_value = String.Empty; break; default: default_value = Activator.CreateInstance (type); break; } } else if (!type.IsAssignableFrom (default_value.GetType ())) { if (!this.converter.CanConvertFrom (default_value.GetType ())) throw new ConfigurationErrorsException (String.Format ("The default value for property '{0}' has a different type than the one of the property itself: expected {1} but was {2}", name, type, default_value.GetType ())); default_value = this.converter.ConvertFrom (default_value); } } this.default_value = default_value; this.flags = flags; this.type = type; this.validation = validation != null ? validation : new DefaultValidator (); this.description = description; }
public IntegerConfigurationProperty (string name, int defaultValue, ConfigurationPropertyOptions flags) : base (name, typeof(int), defaultValue, flags) { min = int.MinValue; max = int.MaxValue; }
protected internal virtual ConfigurationProperty CreateNameConfigurationProperty(object defaultValue, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator) { return(new ConfigurationProperty(this.NamePropertyName, typeof(string), defaultValue, null, validator, options)); }
protected internal virtual ConfigurationProperty CreateNameConfigurationProperty(object defaultValue, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator) { return new ConfigurationProperty(this.NamePropertyName, typeof(string), defaultValue, null, validator, options); }
public ConfigurationProperty(String name, Type type, Object defaultValue, ConfigurationPropertyOptions options) { throw new NotImplementedException(); }
public ConfigurationProperty( string name, Type type, object default_value, ConfigurationPropertyOptions flags) : this(name, type, default_value, TypeDescriptor.GetConverter(type), new DefaultValidator(), flags, null) { }
public ConfigurationProperty(string name, Type type, object defaultValue, System.ComponentModel.TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options) { }
// Constructors public ConfigurationProperty(string name, Type type, object defaultValue, ConfigurationPropertyOptions options) {}
protected internal static ConfigurationProperty Register(string name, Type type, Type declaringType, object defaultValue, ConfigurationPropertyOptions options) => ConfigurationElement.Register(declaringType, new ConfigurationProperty(name, type, defaultValue, options));
private void ConstructorInit(string name, Type type, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator, TypeConverter converter) { if (typeof(ConfigurationSection).IsAssignableFrom(type)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_properties_may_not_be_derived_from_configuration_section, name)); } _providedName = name; // save the provided name so we can check for default collection names if ((options & ConfigurationPropertyOptions.IsDefaultCollection) != 0 && String.IsNullOrEmpty(name)) { name = DefaultCollectionPropertyName; } else { ValidatePropertyName(name); } _name = name; _type = type; _options = options; _validator = validator; _converter = converter; // Use the default validator if none was supplied if (_validator == null) { _validator = DefaultValidatorInstance; } else { // Make sure the supplied validator supports the type of this property if (!_validator.CanValidate(_type)) { throw new ConfigurationErrorsException(SR.GetString(SR.Validator_does_not_support_prop_type, _name)); } } }
public ConfigurationProperty(String name, Type type, Object defaultValue, ConfigurationPropertyOptions options) : this(name, type, defaultValue, null, null, options) { }
public ConfigurationProperty(string name, Type type, object defaultValue, System.ComponentModel.TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description) {}
public IntegerConfigurationProperty(string name, int defaultValue, ConfigurationPropertyOptions flags) : base(name, typeof(int), defaultValue, flags) { _min = int.MinValue; _max = int.MaxValue; }
public TimeSpanConfigurationProperty (string name, TimeSpan defaultValue, ConfigurationPropertyOptions flags) : base (name, typeof(TimeSpan), defaultValue, flags) { }
public TimeSpanConfigurationProperty (string name, TimeSpan defaultValue, TimeSpanSerializedFormat format, TimeSpanPropertyFlags tsflags, ConfigurationPropertyOptions flags) : base (name, typeof(TimeSpan), defaultValue, flags) { _format = format; _tsflags = tsflags; }
public IntegerConfigurationProperty (string name, int defaultValue, int minimumValue, int maximumValue, ConfigurationPropertyOptions flags) : base (name, typeof(int), defaultValue, flags) { min = minimumValue; max = maximumValue; }
public ConfigurationProperty ( string name, Type type, object default_value, ConfigurationPropertyOptions flags) :this (name, type, default_value, TypeDescriptor.GetConverter (type), new DefaultValidator(), flags, null) { }
// Constructors public ConfigurationProperty(string name, Type type, object defaultValue, ConfigurationPropertyOptions options) { }
public ConfigurationProperty(string name, System.Type type, object defaultValue, ConfigurationPropertyOptions options) : this(name, type, defaultValue, null, null, options) { }
public NonEmptyStringConfigurationProperty(string name, string defaultValue, ConfigurationPropertyOptions flags, NonEmptyStringFlags nonEmptyStringFlags) : base(name, typeof(string), defaultValue, flags) { stringFlags = nonEmptyStringFlags; }
private void ConstructorInit(string name, System.Type type, ConfigurationPropertyOptions options, ConfigurationValidatorBase validator, TypeConverter converter) { if (typeof(ConfigurationSection).IsAssignableFrom(type)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_properties_may_not_be_derived_from_configuration_section", new object[] { name })); } this._providedName = name; if (((options & ConfigurationPropertyOptions.IsDefaultCollection) != ConfigurationPropertyOptions.None) && string.IsNullOrEmpty(name)) { name = DefaultCollectionPropertyName; } else { this.ValidatePropertyName(name); } this._name = name; this._type = type; this._options = options; this._validator = validator; this._converter = converter; if (this._validator == null) { this._validator = DefaultValidatorInstance; } else if (!this._validator.CanValidate(this._type)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Validator_does_not_support_prop_type", new object[] { this._name })); } }
public TimeSpanConfigurationProperty(string name, TimeSpan defaultValue, ConfigurationPropertyOptions flags) : base(name, typeof(TimeSpan), defaultValue, flags) { }
public NonEmptyStringConfigurationProperty (string name, string defaultValue, ConfigurationPropertyOptions flags, NonEmptyStringFlags nonEmptyStringFlags) : base (name, typeof(string), defaultValue, flags) { stringFlags = nonEmptyStringFlags; }
public ConfigSection() { if (_configSectionLoaded == false) { foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { if (ConfigManager.ExcludedTypes.Contains(fieldInfo.FieldType)) { continue; } string fieldName = fieldInfo.Name; fieldName = Char.ToLower(fieldName[0]) + fieldName.Substring(1); if (fieldInfo.FieldType.IsSubclassOf(typeof(ConfigElement)) || fieldInfo.FieldType.IsSubclassOf(typeof(ConfigurationElementCollection))) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString(), fieldInfo.FieldType)); foreach (Machine machine in ConfigManager.Machines) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machine.MachineName, fieldInfo.FieldType)); } foreach (WebHost webHost in ConfigManager.WebHosts) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + webHost.WebHostPart, fieldInfo.FieldType, null)); } foreach (Application application in ConfigManager.Applications) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + application.ApplicationName, fieldInfo.FieldType, null)); } foreach (string machineType in Enum.GetNames(typeof(RightPoint.MachineType))) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machineType, fieldInfo.FieldType)); } } else { ConfigurationPropertyOptions options = ConfigurationPropertyOptions.None; if (fieldInfo.GetCustomAttributes(typeof(OptionalAttribute), true).Length == 0) { options = ConfigurationPropertyOptions.IsRequired; } this.Properties.Add(new ConfigurationProperty(fieldName.ToString(), fieldInfo.FieldType, fieldInfo.GetValue(this), options)); foreach (Machine machine in ConfigManager.Machines) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machine.MachineName, fieldInfo.FieldType, null)); } foreach (WebHost webHost in ConfigManager.WebHosts) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + webHost.WebHostPart, fieldInfo.FieldType, null)); } foreach (Application application in ConfigManager.Applications) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + application.ApplicationName, fieldInfo.FieldType, null)); } foreach (string machineType in Enum.GetNames(typeof(RightPoint.MachineType))) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machineType, fieldInfo.FieldType, null)); } } } } _configSectionLoaded = true; }
public ConfigurationProperty(string name, Type type, object defaultValue, ConfigurationPropertyOptions options) : this(name, type, defaultValue, null, null, options) { }
public ConfigurationProperty(String name, Type type, Object defaultValue, ConfigurationPropertyOptions options) { throw new NotImplementedException(); }
public ConfigElement() { string keyFieldName = null; if (this is ConfigElementCollectionItem) { FieldInfo customKeyFieldInfo = null; foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { if (fieldInfo.GetCustomAttributes(typeof(CustomKeyAttribute), true).Length > 0) { customKeyFieldInfo = fieldInfo; break; } } if (customKeyFieldInfo != null) { keyFieldName = customKeyFieldInfo.Name; } else { keyFieldName = "Key"; } keyFieldName = Char.ToLower(keyFieldName[0]) + keyFieldName.Substring(1); this.Properties.Add(new ConfigurationProperty(keyFieldName, typeof(string), null, ConfigurationPropertyOptions.IsKey)); } foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { if (ConfigManager.ExcludedTypes.Contains(fieldInfo.FieldType)) { continue; } string fieldName = fieldInfo.Name; fieldName = Char.ToLower(fieldName[0]) + fieldName.Substring(1); if (keyFieldName == fieldName || fieldInfo.FieldType == typeof(Regex)) { continue; } ConfigurationPropertyOptions options = ConfigurationPropertyOptions.None; if (fieldInfo.GetCustomAttributes(typeof(OptionalAttribute), true).Length == 0) { options = ConfigurationPropertyOptions.IsRequired; } if (fieldInfo.GetCustomAttributes(typeof(CDataAttribute), true).Length > 0) { if (_cdataFieldNames.Count > 0) { throw new Exception(@"Only one property may have the CData attribute assigned."); } _cdataFieldNames.Add(fieldName); foreach (Machine machine in ConfigManager.Machines) { _cdataFieldNames.Add(fieldName.ToString() + "_" + machine.MachineName); } foreach (WebHost webHost in ConfigManager.WebHosts) { _cdataFieldNames.Add(fieldName.ToString() + "_" + webHost.WebHostPart); } foreach (Application application in ConfigManager.Applications) { _cdataFieldNames.Add(fieldName.ToString() + "_" + application.ApplicationName); } foreach (string machineType in Enum.GetNames(typeof(RightPoint.MachineType))) { _cdataFieldNames.Add(fieldName.ToString() + "_" + machineType); } } this.Properties.Add(new ConfigurationProperty(fieldName.ToString(), fieldInfo.FieldType, fieldInfo.GetValue(this), options)); foreach (Machine machine in ConfigManager.Machines) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machine.MachineName, fieldInfo.FieldType, null)); } foreach (WebHost webHost in ConfigManager.WebHosts) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + webHost.WebHostPart, fieldInfo.FieldType, null)); } foreach (Application application in ConfigManager.Applications) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + application.ApplicationName, fieldInfo.FieldType, null)); } foreach (string machineType in Enum.GetNames(typeof(RightPoint.MachineType))) { this.Properties.Add(new ConfigurationProperty(fieldName.ToString() + "_" + machineType, fieldInfo.FieldType, null)); } } }