ElementInformation.Source 属性

定义

获取产生关联的 ConfigurationElement 对象的源文件。

public:
 property System::String ^ Source { System::String ^ get(); };
public string Source { get; }
member this.Source : string
Public ReadOnly Property Source As String

属性值

产生关联的 ConfigurationElement 对象的源文件。

示例

下面的示例演示如何使用 Source 属性。

static public void GetElementSource()
{
    // Get the current configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

    // Get the section.
    UrlsSection section =
        (UrlsSection)config.GetSection("MyUrls");

    // Get the element.
    UrlConfigElement url = section.Simple;

    // Get the element source file.
    string sourceFile =
        url.ElementInformation.Source;

    Console.WriteLine("Url element source file: {0}",
                    sourceFile);
}
Public Shared Sub GetElementSource() 

    ' Get the current configuration file.
    Dim config _
    As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration( _
    ConfigurationUserLevel.None)

    ' Get the section.
    Dim section As UrlsSection = _
    CType(config.GetSection("MyUrls"), UrlsSection)
    
    ' Get the element.
    Dim url As UrlConfigElement = _
    section.Simple
    
    ' Get the element source file.
    Dim sourceFile As String = _
    url.ElementInformation.Source
    
    Console.WriteLine( _
    "Url element source file: {0}", sourceFile)

End Sub

注解

ConfigurationElement可以在默认状态下创建对象,在这种情况下,此属性返回 null

适用于