ConfigurationElement.IsModified ConfigurationElement.IsModified ConfigurationElement.IsModified ConfigurationElement.IsModified Method

정의

파생 클래스에서 구현될 때 이 구성 요소가 마지막으로 저장되거나 로드된 이후 수정되었는지 여부를 나타냅니다.Indicates whether this configuration element has been modified since it was last saved or loaded, when implemented in a derived class.

protected public:
 virtual bool IsModified();
protected internal virtual bool IsModified ();
abstract member IsModified : unit -> bool
override this.IsModified : unit -> bool
Protected Friend Overridable Function IsModified () As Boolean

반환

요소가 수정되었으면 true이고, 그렇지 않으면 false입니다.true if the element has been modified; otherwise, false.

예제

다음 예제에서는 확장 방법 IsModified합니다.The following example shows how to extend IsModified.

protected override bool IsModified()
{
    bool ret = base.IsModified();
    // You can enter your custom processing code here.
    return ret;
}
    Protected Overrides Function IsModified() As Boolean
        Dim ret As Boolean = MyBase.IsModified()
        ' Enter your custom processing code here.
        Return ret

    End Function 'IsModified
End Class 'UrlConfigElement 

이전 예에서 같이 메서드는 구성 요소 수정 되 면 다음 예제와 같이 호출 됩니다.The method shown in the previous example is called when a configuration element is modified, as in the following example.

// Show how to use IsModified.
// This method modifies the port property
// of the url element named Microsoft and
// saves the modification to the configuration
// file. This in turn will cause the overriden
// UrlConfigElement.IsModified() mathod to be called. 
static void ModifyElement()
{
    try
    {
        // Get the configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

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


        UrlsCollection elements = myUrlsSection.Urls;


        IEnumerator elemEnum =
            elements.GetEnumerator();

        int i = 0;
        while (elemEnum.MoveNext())
        {
            if (elements[i].Name == "Microsoft")
            {
                elements[i].Port = 1010;
                bool readOnly = elements[i].IsReadOnly();
                break;
            }
            i += 1;
        }

        if (!myUrlsSection.ElementInformation.IsLocked)
        {

            config.Save(ConfigurationSaveMode.Full);

            // This to obsolete the MyUrls cached 
            // section and read the updated version
            // from the configuration file.
            ConfigurationManager.RefreshSection("MyUrls");
        }
        else
            Console.WriteLine(
                "Section was locked, could not update.");
    }

    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine("[ModifyElement: {0}]",
            err.ToString());
    }

}

' Show how to use IsModified.
' This method modifies the port property
' of the url element named Microsoft and
' saves the modification to the configuration
' file. This in turn will cause the overriden
' UrlConfigElement.IsModified() mathod to be called. 
Shared Sub ModifyElement()
    Try
        ' Get the current configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Get the MyUrls section.
        Dim myUrlsSection As UrlsSection = _
        config.GetSection("MyUrls")


        Dim elements As UrlsCollection = _
        myUrlsSection.Urls


        Dim elemEnum As IEnumerator = _
        elements.GetEnumerator()

        Dim i As Integer = 0
        While elemEnum.MoveNext()
            If elements(i).Name = "Microsoft" Then
                elements(i).Port = 1010
                Dim [readOnly] As Boolean = _
                elements(i).IsReadOnly()
                Exit While
            End If
            i += 1
        End While

        If Not myUrlsSection.ElementInformation.IsLocked Then

            config.Save(ConfigurationSaveMode.Full)

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

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

End Sub 'ModifyElement

설명

IsModified 메서드를 결정 하는지 여부를이 ConfigurationElement 개체를 쓸 구성 있을 때 파일는 Save 메서드는.The IsModified method determines whether this ConfigurationElement object will be written to the configuration file when the Save method is called. 반환 값이 false이면 구성 파일이 요소의 현재 상태를 나타낸다고 가정됩니다.If the return value is false, it is assumed that the configuration file represents the current state of the element.

기본적으로 IsModified 반환 true 인덱서를 통해이 속성을 설정한 후 ConfigurationElement 개체입니다.By default, IsModified returns true after a property is set through the indexer to this ConfigurationElement object.

재정의 된 IsModified 의이 상태에 대 한 사용자 지정 표시를 제공 하는 방법 ConfigurationElement 요소입니다.Override the IsModified method to provide custom indication of the state of this ConfigurationElement element.

적용 대상