Afficher en anglais

Partage via


PropertyInformation Classe

Définition

Contient des méta-informations sur une propriété individuelle de la configuration. Ce type ne peut pas être hérité.

C#
public sealed class PropertyInformation
Héritage
PropertyInformation

Exemples

L’exemple de code suivant montre comment utiliser le PropertyInformation type .

C#
#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();
    }
  }
}

Remarques

L’objet PropertyInformation contient les méta-informations d’une propriété individuelle dans la configuration. Cet objet peut être utilisé lors de la validation et de la modification des propriétés d’un attribut individuel.

L’objet PropertyInformation est dérivé de l’objet associé PropertyInformationCollection . L’objet PropertyInformationCollection est dérivé de l’objet associé ElementInformation .

Propriétés

Converter

Obtient l'objet TypeConverter associé à l'attribut de configuration.

DefaultValue

Obtient un objet contenant la valeur par défaut associée à un attribut de configuration.

Description

Obtient la description de l'objet qui correspond à un attribut de configuration.

IsKey

Obtient une valeur spécifiant si l'attribut de configuration est une clé.

IsLocked

Obtient une valeur spécifiant si l'attribut de configuration est verrouillé.

IsModified

Obtient une valeur indiquant si l'attribut de configuration a été modifié.

IsRequired

Obtient une valeur spécifiant si l'attribut de configuration est requis.

LineNumber

Obtient le numéro de ligne dans le fichier de configuration associé à l'attribut de configuration.

Name

Obtient le nom de l'objet qui correspond à un attribut de configuration.

Source

Obtient le fichier source qui correspond à un attribut de configuration.

Type

Obtient le Type de l'objet qui correspond à un attribut de configuration.

Validator

Obtient un objet ConfigurationValidatorBase associé à l'attribut de configuration.

Value

Obtient ou définit un objet contenant la valeur associée à un attribut de configuration.

ValueOrigin

Obtient un objet PropertyValueOrigin associé à l'attribut de configuration.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à

Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Voir aussi