ConfigurationProperty Klas
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Vertegenwoordigt een kenmerk of een onderliggend element van een configuratie-element. Deze klasse kan niet worden overgenomen.
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken.
public ref class ConfigurationProperty sealed
public sealed class ConfigurationProperty
type ConfigurationProperty = class
Public NotInheritable Class ConfigurationProperty
- Overname
-
ConfigurationProperty
Voorbeelden
- In het volgende codevoorbeeld ziet u hoe u de ConfigurationProperty sectie gebruikt wanneer u een aangepaste sectie maakt.
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
namespace ConfigurationPropertyExample
{
// Define a custom section.
// Shows how to use the ConfigurationProperty
// class when defining a custom section.
public sealed class CustomSection : ConfigurationSection
{
// The collection (property bag) that contains
// the section properties.
private static ConfigurationPropertyCollection _Properties;
// The FileName property.
private static ConfigurationProperty _FileName;
// The Alias property.
private static ConfigurationProperty _Alias;
// The MaxUsers property.
private static ConfigurationProperty _MaxUsers;
// The MaxIdleTime property.
private static ConfigurationProperty _MaxIdleTime;
// CustomSection constructor.
static CustomSection()
{
// Initialize the _FileName property
_FileName =
new ConfigurationProperty("fileName",
typeof(string), "default.txt");
// Initialize the _MaxUsers property
_MaxUsers =
new ConfigurationProperty("maxUsers",
typeof(long), (long)1000,
ConfigurationPropertyOptions.None);
// Initialize the _MaxIdleTime property
TimeSpan minTime = TimeSpan.FromSeconds(30);
TimeSpan maxTime = TimeSpan.FromMinutes(5);
ConfigurationValidatorBase _TimeSpanValidator =
new TimeSpanValidator(minTime, maxTime, false);
_MaxIdleTime =
new ConfigurationProperty("maxIdleTime",
typeof(TimeSpan), TimeSpan.FromMinutes(5),
TypeDescriptor.GetConverter(typeof(TimeSpan)),
_TimeSpanValidator,
ConfigurationPropertyOptions.IsRequired,
"[Description:This is the max idle time.]");
// Initialize the _Alias property
_Alias =
new ConfigurationProperty("alias",
typeof(string), "alias.txt");
// Initialize the Property collection.
_Properties = new ConfigurationPropertyCollection();
_Properties.Add(_FileName);
_Properties.Add(_Alias);
_Properties.Add(_MaxUsers);
_Properties.Add(_MaxIdleTime);
}
// Return the initialized property bag
// for the configuration element.
protected override ConfigurationPropertyCollection Properties
{
get
{
return _Properties;
}
}
// Clear the property.
public void ClearCollection()
{
Properties.Clear();
}
// Remove an element from the property collection.
public void RemoveCollectionElement(string elName)
{
Properties.Remove(elName);
}
// Get the property collection enumerator.
public IEnumerator GetCollectionEnumerator()
{
return (Properties.GetEnumerator());
}
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
MinLength = 1, MaxLength = 60)]
public string FileName
{
get
{
return (string)this["fileName"];
}
set
{
this["fileName"] = value;
}
}
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
MinLength = 1, MaxLength = 60)]
public string Alias
{
get
{
return (string)this["alias"];
}
set
{
this["alias"] = value;
}
}
[LongValidator(MinValue = 1, MaxValue = 1000000,
ExcludeRange = false)]
public long MaxUsers
{
get
{
return (long)this["maxUsers"];
}
set
{
this["maxUsers"] = value;
}
}
public TimeSpan MaxIdleTime
{
get
{
return (TimeSpan)this["maxIdleTime"];
}
set
{
this["maxIdleTime"] = value;
}
}
}
}
Imports System.Configuration
Imports System.Collections
Imports System.ComponentModel
' Define a custom section.
' Shows how to use the ConfigurationProperty
' class when defining a custom section.
Public NotInheritable Class CustomSection
Inherits ConfigurationSection
' The collection (property bag) that contains
' the section properties.
Private Shared _Properties As ConfigurationPropertyCollection
' The FileName property.
Private Shared _FileName As ConfigurationProperty
' The Alias property.
Private Shared _Alias As ConfigurationProperty
' The MasUsers property.
Private Shared _MaxUsers As ConfigurationProperty
' The MaxIdleTime property.
Private Shared _MaxIdleTime As ConfigurationProperty
' CustomSection constructor.
Shared Sub New()
' Initialize the _FileName property
_FileName = New ConfigurationProperty( _
"fileName", GetType(String), "default.txt")
' Initialize the _MaxUsers property
_MaxUsers = New ConfigurationProperty( _
"maxUsers", GetType(Long), 1000L, _
ConfigurationPropertyOptions.None)
' Initialize the _MaxIdleTime property
Dim minTime As TimeSpan = TimeSpan.FromSeconds(30)
Dim maxTime As TimeSpan = TimeSpan.FromMinutes(5)
Dim _TimeSpanValidator = _
New TimeSpanValidator(minTime, maxTime, False)
_MaxIdleTime = New ConfigurationProperty( _
"maxIdleTime", GetType(TimeSpan), _
TimeSpan.FromMinutes(5), _
TypeDescriptor.GetConverter(GetType(TimeSpan)), _
_TimeSpanValidator, _
ConfigurationPropertyOptions.IsRequired, _
"[Description:This is the max idle time.]")
' Initialize the _Alias property
_Alias = New ConfigurationProperty( _
"alias", GetType(String), "alias.txt")
' Property collection initialization.
' The collection (property bag) that contains
' the properties is declared as:
' ConfigurationPropertyCollection _Properties;
_Properties = New ConfigurationPropertyCollection()
_Properties.Add(_FileName)
_Properties.Add(_Alias)
_Properties.Add(_MaxUsers)
_Properties.Add(_MaxIdleTime)
End Sub
' Return the initialized property bag
' for the configuration element.
Protected Overrides ReadOnly Property Properties() _
As ConfigurationPropertyCollection
Get
Return _Properties
End Get
End Property
<StringValidator(InvalidCharacters:= _
" ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, _
MaxLength:=60)> _
Public Property FileName() As String
Get
Return CStr(Me("fileName"))
End Get
Set(ByVal value As String)
Me("fileName") = value
End Set
End Property
<StringValidator(InvalidCharacters:= _
" ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, _
MaxLength:=60)> _
Public Property [Alias]() As String
Get
Return CStr(Me("alias"))
End Get
Set(ByVal value As String)
Me("alias") = value
End Set
End Property
<LongValidator(MinValue:=1, _
MaxValue:=1000000, ExcludeRange:=False)> _
Public Property MaxUsers() As Long
Get
Return Fix(Me("maxUsers"))
End Get
Set(ByVal value As Long)
Me("maxUsers") = value
End Set
End Property
Public Property MaxIdleTime() As TimeSpan
Get
Return CType(Me("maxIdleTime"), TimeSpan)
End Get
Set(ByVal value As TimeSpan)
Me("maxIdleTime") = value
End Set
End Property
End Class
Hier volgt een fragment van het configuratiebestand dat wordt gebruikt door de code in het vorige voorbeeld.
<configuration>
<configSections>
<section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample"
allowDefinition="Everywhere" allowExeDefinition="MachineToApplication"
restartOnExternalChanges="true" />
</configSections>
<CustomSection fileName="override.txt" alias="alias.txt"
maxUsers="1000" maxIdleTime="00:05:00" />
</configuration>
In het volgende voorbeeld ziet u hoe u de vorige sectie in code maakt.
// Define a custom section programmatically.
static void CreateSection()
{
try
{
CustomSection customSection;
// Get the current configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Create the section entry
// in the <configSections> and the
// related target section in <configuration>.
// Call it "CustomSection2" since the file in this
// example already has "CustomSection".
if (config.Sections["CustomSection"] == null)
{
customSection = new CustomSection();
config.Sections.Add("CustomSection2", customSection);
customSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
' Create a custom section.
Shared Sub CreateSection()
Try
Dim customSection As CustomSection
' Get the current configuration file.
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Create the section entry
' in the <configSections> and the
' related target section in <configuration>.
' Since the config file already has "CustomSection",
' call this one "CustomSection2".
If config.Sections("CustomSection") Is Nothing Then
customSection = New CustomSection()
config.Sections.Add("CustomSection", customSection)
customSection.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
End If
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
Opmerkingen
In het geval van een eenvoudige ConfigurationElement, zoals in het CustomSection volgende voorbeeld, vertegenwoordigen de ConfigurationProperty objecten kenmerken zoals fileName.
In het geval van complexere configuratie-elementen, zoals een sectie met subsecties, kunnen de objecten bijvoorbeeld authenticationobjecten en kenmerken vertegenwoordigenConfigurationElement.ConfigurationProperty
De ConfigurationPropertyCollection klasse vertegenwoordigt de verzameling van de ConfigurationProperty objecten die kenmerken of ConfigurationElement objecten van een configuratie-element kunnen zijn.
De ConfigurationProperty klasse vertegenwoordigt een afzonderlijke configuratie-instelling. Met deze klasse kunt u de naam, het type en de standaardwaarde voor een bepaalde configuratie-entiteit (kenmerk of element) ophalen of instellen en opgeven of het kenmerk vereist is, een elementsleutel is of een standaardelementverzameling vertegenwoordigt.
Notities voor overnemers
Elk ConfigurationElement object maakt een interne ConfigurationPropertyCollection verzameling ConfigurationProperty objecten die de elementkenmerken of een verzameling onderliggende elementen vertegenwoordigt.
Niet-aanpasbare informatie en functionaliteit zijn opgenomen in een ElementInformation object dat door de ElementInformation eigenschap wordt geleverd.
U kunt een programmatisch of een declaratief (toegeschreven) coderingsmodel gebruiken om een aangepast configuratie-element te maken.
Programmatisch model. Voor dit model moet u een eigenschap maken voor elk elementkenmerk om de waarde op te halen en/of in te stellen en deze toe te voegen aan de interne eigenschappenverzameling van de onderliggende ConfigurationElement basisklasse.
Declaratief model. Met dit eenvoudigere model, ook wel toegeschreven model genoemd, kunt u een elementkenmerk definiëren met behulp van een eigenschap en deze versieren met kenmerken. Met deze kenmerken wordt het ASP.NET configuratiesysteem geïnstrueerd over de eigenschapstypen en de bijbehorende standaardwaarden. Met deze informatie, verkregen via weerspiegeling, maakt het ASP.NET configuratiesysteem de elementeigenschapsobjecten voor u en voert de vereiste initialisatie uit.
Constructors
| Name | Description |
|---|---|
| ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Initialiseert een nieuw exemplaar van de ConfigurationProperty klasse. |
| ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Initialiseert een nieuw exemplaar van de ConfigurationProperty klasse. |
| ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Initialiseert een nieuw exemplaar van de ConfigurationProperty klasse. |
| ConfigurationProperty(String, Type, Object) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Initialiseert een nieuw exemplaar van de ConfigurationProperty klasse. |
| ConfigurationProperty(String, Type) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Initialiseert een nieuw exemplaar van de ConfigurationProperty klasse. |
Eigenschappen
| Name | Description |
|---|---|
| Converter |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de TypeConverter gebruikte om dit ConfigurationProperty te converteren naar een XML-weergave voor schrijven naar het configuratiebestand. |
| DefaultValue |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de standaardwaarde voor deze ConfigurationProperty eigenschap op. |
| Description |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de beschrijving op die is gekoppeld aan de ConfigurationProperty. |
| IsAssemblyStringTransformationRequired |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Geeft aan of de assemblynaam voor de configuratie-eigenschap transformatie vereist wanneer deze wordt geserialiseerd voor een eerdere versie van het .NET Framework. |
| IsDefaultCollection |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee wordt een waarde opgehaald die aangeeft of de eigenschap de standaardverzameling van een element is. |
| IsKey |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee wordt een waarde opgehaald die aangeeft of dit ConfigurationProperty de sleutel is voor het bijbehorende ConfigurationElement object. |
| IsRequired |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee wordt een waarde opgehaald die aangeeft of dit ConfigurationProperty vereist is. |
| IsTypeStringTransformationRequired |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Geeft aan of de typenaam voor de configuratie-eigenschap transformatie vereist wanneer deze wordt geserialiseerd voor een eerdere versie van het .NET Framework. |
| IsVersionCheckRequired |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Geeft aan of de bovenliggende configuratiesectie van de configuratie-eigenschap wordt opgevraagd tijdens serialisatie om te bepalen of de configuratie-eigenschap moet worden geserialiseerd in XML. |
| Name |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de naam van deze ConfigurationPropertyop. |
| Type |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u het type van dit ConfigurationProperty object op. |
| Validator |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de ConfigurationValidatorAttribute, die wordt gebruikt om dit ConfigurationProperty object te valideren. |
Methoden
| Name | Description |
|---|---|
| Equals(Object) |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Bepaalt of het opgegeven object gelijk is aan het huidige object. (Overgenomen van Object) |
| GetHashCode() |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Fungeert als de standaardhashfunctie. (Overgenomen van Object) |
| GetType() |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee haalt u de Type huidige instantie op. (Overgenomen van Object) |
| MemberwiseClone() |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Hiermee maakt u een ondiepe kopie van de huidige Object. (Overgenomen van Object) |
| ToString() |
Deze API ondersteunt de productinfrastructuur en is niet bedoeld om rechtstreeks vanuit de code te gebruiken. Retourneert een tekenreeks die het huidige object vertegenwoordigt. (Overgenomen van Object) |