ConfigurationElement.IsModified メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ConfigurationElement.IsModified メソッドの意味・解説 

ConfigurationElement.IsModified メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

派生クラス実装された場合、この構成要素最後保存または読み込み以降変更されたかどうかを示します

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

解説解説

IsModified メソッドは、Save メソッド呼び出されたときにこの ConfigurationElement オブジェクト構成ファイル書き込まれかどうか確認します戻り値false場合構成ファイル要素現在の状態表していると見なされます

既定では、IsModified は、インデクサ通じてこの ConfigurationElement オブジェクトプロパティ設定された後に true返します

この ConfigurationElement 要素の状態を示すカスタムの値を提供するには、IsModified メソッドオーバーライドます。

使用例使用例

IsModified拡張する方法の例を次に示します

Protected Overrides Function
 IsModified() As Boolean 
    Dim ret As Boolean =
 MyBase.IsModified()
    
    ' Enter your custom processing code here.
    Console.WriteLine("UrlConfigElement.IsModified() called.")
    
    Return ret

End Function 'IsModified
protected override bool IsModified()
{
    bool ret = base.IsModified();

    // Enter your custom processing code here.

    Console.WriteLine("UrlConfigElement.IsModified() called.");

    return ret;
}

前述の例に示されているメソッドが、次の例では構成要素変更されたときに呼び出されます。

' 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

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

}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConfigurationElement クラス
ConfigurationElement メンバ
System.Configuration 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からConfigurationElement.IsModified メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConfigurationElement.IsModified メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConfigurationElement.IsModified メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ConfigurationElement.IsModified メソッド」の関連用語

ConfigurationElement.IsModified メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ConfigurationElement.IsModified メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS