PropertyInformation 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含配置中的个别属性的元数据信息。 无法继承此类型。
public ref class PropertyInformation sealedpublic sealed class PropertyInformationtype PropertyInformation = classPublic NotInheritable Class PropertyInformation- 继承
- 
				PropertyInformation
示例
下面的代码示例演示如何使用 PropertyInformation 类型。
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;
#endregion
namespace Samples.ConfigurationExamples
{
  class UsingPropertyInformation
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";
        // Get the Web application configuration object.
        Configuration config = 
          WebConfigurationManager.OpenWebConfiguration(configPath);
        // Get the section related object.
        AnonymousIdentificationSection configSection =
          (AnonymousIdentificationSection)config.GetSection
          ("system.web/anonymousIdentification");
        // Display title.
        Console.WriteLine("Configuration PropertyInformation");
        Console.WriteLine("Section: anonymousIdentification");
        // Instantiate a new PropertyInformationCollection object.
        PropertyInformationCollection propCollection =
          configSection.ElementInformation.Properties;
        // Display Collection Count.
        Console.WriteLine("Collection Count: {0}", 
          propCollection.Count);
        // Display properties of elements 
        // of the PropertyInformationCollection.
        foreach (PropertyInformation propertyItem in propCollection)
        {
          Console.WriteLine();
          Console.WriteLine("Property Details:");
          // Display the Name property.
          Console.WriteLine("Name: {0}", propertyItem.Name);
          // Display the Value property.
          Console.WriteLine("Value: {0}", propertyItem.Value);
          // Display the DefaultValue property.
          Console.WriteLine("DefaultValue: {0}", 
            propertyItem.DefaultValue);
          // Display the Type property.
          Console.WriteLine("Type: {0}", propertyItem.Type);
          // Display the IsKey property.
          Console.WriteLine("IsKey: {0}", propertyItem.IsKey);
          // Display the IsLocked property.
          Console.WriteLine("IsLocked: {0}", propertyItem.IsLocked);
          // Display the IsModified property.
          Console.WriteLine("IsModified: {0}", propertyItem.IsModified);
          // Display the IsRequired property.
          Console.WriteLine("IsRequired: {0}", propertyItem.IsRequired);
          // Display the LineNumber property.
          Console.WriteLine("LineNumber: {0}", propertyItem.LineNumber);
          // Display the Source property.
          Console.WriteLine("Source: {0}", propertyItem.Source);
          // Display the Validator property.
          Console.WriteLine("Validator: {0}", propertyItem.Validator);
          // Display the ValueOrigin property.
          Console.WriteLine("ValueOrigin: {0}", propertyItem.ValueOrigin);
        }
        Console.WriteLine("");
        Console.WriteLine("Configuration - Accessing an Attribute");
        // Create EllementInformation object.
        ElementInformation elementInfo =
          configSection.ElementInformation;
        // Create a PropertyInformationCollection object.
        PropertyInformationCollection propertyInfoCollection =
          elementInfo.Properties;
        // Create a PropertyInformation object.
        PropertyInformation myPropertyInfo =
          propertyInfoCollection["enabled"];
        // Display the property value.
        Console.WriteLine
          ("anonymousIdentification Section - Enabled: {0}",
          myPropertyInfo.Value);
      }
      catch (Exception e)
      {
        // Error.
        Console.WriteLine(e.ToString());
      }
      // Display and wait.
      Console.ReadLine();
    }
  }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Namespace Samples.ConfigurationExamples
  Class UsingPropertyInformation
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""
        ' Get the Web application configuration object.
        Dim config As Configuration = _
          WebConfigurationManager.OpenWebConfiguration(configPath)
        ' Get the section related object.
        Dim configSection As AnonymousIdentificationSection = _
        CType(config.GetSection("system.web/anonymousIdentification"), _
        AnonymousIdentificationSection)
        ' Display title.
        Console.WriteLine("Configuration PropertyInformation")
        Console.WriteLine("Section: anonymousIdentification")
        ' Instantiate a new PropertyInformationCollection object.
        Dim propCollection As PropertyInformationCollection = _
         configSection.ElementInformation.Properties()
        ' Display Collection Count.
        Console.WriteLine("Collection Count: {0}", _
          propCollection.Count)
        ' Display properties of elements 
        ' of the PropertyInformationCollection.
        For Each propertyItem As PropertyInformation In propCollection
          Console.WriteLine()
          Console.WriteLine("Property Details:")
          ' Display the Name property.
          Console.WriteLine("Name: {0}", propertyItem.Name)
          ' Display the Value property.
          Console.WriteLine("Value: {0}", propertyItem.Value)
          ' Display the DefaultValue property.
          Console.WriteLine("DefaultValue: {0}", _
            propertyItem.DefaultValue) _
          ' Display the Type property.
          Console.WriteLine("Type: {0}", propertyItem.Type)
          ' Display the IsKey property.
          Console.WriteLine("IsKey: {0}", propertyItem.IsKey)
          ' Display the IsLocked property.
          Console.WriteLine("IsLocked: {0}", propertyItem.IsLocked)
          ' Display the IsModified property.
          Console.WriteLine("IsModified: {0}", propertyItem.IsModified)
          ' Display the IsRequired property.
          Console.WriteLine("IsRequired: {0}", propertyItem.IsRequired)
          ' Display the LineNumber property.
          Console.WriteLine("LineNumber: {0}", propertyItem.LineNumber)
          ' Display the Source property.
          Console.WriteLine("Source: {0}", propertyItem.Source)
          ' Display the Validator property.
          Console.WriteLine("Validator: {0}", propertyItem.Validator)
          ' Display the ValueOrigin property.
          Console.WriteLine("ValueOrigin: {0}", propertyItem.ValueOrigin)
        Next
        Console.WriteLine("")
        Console.WriteLine("Configuration - Accessing an Attribute")
        ' Create EllementInformation object.
        Dim elementInfo As ElementInformation = _
        configSection.ElementInformation()
        ' Create a PropertyInformationCollection object.
        Dim propertyInfoCollection As PropertyInformationCollection = _
        elementInfo.Properties()
        ' Create a PropertyInformation object.
        Dim myPropertyInfo As PropertyInformation = _
          propertyInfoCollection("enabled")
        ' Display the property value.
        Console.WriteLine _
          ("anonymousIdentification Section - Enabled: {0}", _
          myPropertyInfo.Value)
      Catch e As Exception
        ' Error.
        Console.WriteLine("Error: {0}", _
          e.Message.ToString())
      End Try
      ' Display and wait.
      Console.ReadLine()
    End Sub
  End Class
End Namespace
注解
对象 PropertyInformation 包含配置中单个属性的元信息。 验证和更改单个属性的属性时,可以使用此对象。
对象 PropertyInformation 派生自关联的 PropertyInformationCollection 对象。 对象 PropertyInformationCollection 派生自关联的 ElementInformation 对象。
属性
| Converter | 获取与配置特性相关的 TypeConverter 对象。 | 
| DefaultValue | 获取一个对象,该对象包含与配置特性相关的默认值。 | 
| Description | 获取与配置特性相对应的对象的说明。 | 
| IsKey | 获取指定配置特性是否为键的值。 | 
| IsLocked | 获取指定配置特性是否锁定的值。 | 
| IsModified | 获取指定配置特性是否已修改的值。 | 
| IsRequired | 获取指定是否需要配置特性的值。 | 
| LineNumber | 获取与配置特性相关的配置文件中的行号。 | 
| Name | 获取与配置特性相对应的对象的名称。 | 
| Source | 获取与配置特性相对应的源文件。 | 
| Type | 获取与配置特性相对应的对象的 Type。 | 
| Validator | 获取与配置特性相关的 ConfigurationValidatorBase 对象。 | 
| Value | 获取或设置包含与配置特性相关的值的对象。 | 
| ValueOrigin | 获取与配置特性相关的 PropertyValueOrigin 对象。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |