다음을 통해 공유


ConfigurationElement.LockItem 속성

정의

요소가 잠겨 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool LockItem { bool get(); void set(bool value); };
public bool LockItem { get; set; }
member this.LockItem : bool with get, set
Public Property LockItem As Boolean

속성 값

요소가 잠겨 있으면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예외

요소가 더 높은 구성 수준에서 이미 잠겨 있는 경우

예제

다음 예제에서는 사용 하는 방법의 LockItem합니다.

// Show how to set LockItem
// It adds a new UrlConfigElement to 
// the collection.
static void LockItem()
{
    string name = "Contoso";
    string url = "http://www.contoso.com/";
    int port = 8080;

    try
    {
        // Get the current configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

        // Get the MyUrls section.
        UrlsSection myUrls =
           config.Sections["MyUrls"] as UrlsSection;

        // Create the new  element.
        UrlConfigElement newElement =
            new UrlConfigElement(name, url, port);

        // Set its lock.
        newElement.LockItem = true;

        // Save the new element to the 
        // configuration file.
        if (!myUrls.ElementInformation.IsLocked)
        {

            myUrls.Urls.Add(newElement);

            config.Save(ConfigurationSaveMode.Full);

            // This is used to obsolete the cached 
            // section and read the updated 
            // bersion from the configuration file.
            ConfigurationManager.RefreshSection("MyUrls");
        }
        else
            Console.WriteLine(
                "Section was locked, could not update.");
    }
    catch (ConfigurationErrorsException e)
    {
        Console.WriteLine("[LockItem: {0}]",
            e.ToString());
    }
}
' Show how to set LockItem
' It adds a new UrlConfigElement to 
' the collection.
Shared Sub LockItem()
    Dim name As String = "Contoso"
    Dim url As String = "http://www.contoso.com/"
    Dim port As Integer = 8080

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

        ' Get the MyUrls section.
        Dim myUrls As UrlsSection = _
        config.Sections("MyUrls")


        ' Create the new  element.
        Dim newElement _
        As New UrlConfigElement(name, url, port)

        ' Set its lock.
        newElement.LockItem = True

        ' Save the new element to the 
        ' configuration file.
        If Not myUrls.ElementInformation.IsLocked Then

            myUrls.Urls.Add(newElement)

            config.Save(ConfigurationSaveMode.Full)

            ' This is used to obsolete the cached 
            ' section and read the updared version 
            ' from the configuration file.
            ConfigurationManager.RefreshSection("MyUrls")
        Else
            Console.WriteLine("Section was locked, could not update.")
        End If

    Catch e As ConfigurationErrorsException
        Console.WriteLine("[LockItem: {0}]", _
        e.ToString())
    End Try

End Sub

설명

LockItem 요소 자체 및 해당 자식 요소에 대한 일반 잠금을 적용하려면 속성을 사용합니다.

적용 대상