ConfigurationElement.IsModified Yöntem

Tanım

Bu yapılandırma öğesinin türetilmiş bir sınıfta uygulandığında son kaydedildiğinden veya yüklendiğinden beri değiştirilip değiştirilmediğini gösterir.

C#
protected virtual bool IsModified ();
C#
protected internal virtual bool IsModified ();

Döndürülenler

true öğe değiştirildiyse; aksi takdirde , false.

Örnekler

Aşağıdaki örnek, öğesinin nasıl genişlet yapılacağını IsModifiedgösterir.

C#
protected override bool IsModified()
{
    bool ret = base.IsModified();
    // You can enter your custom processing code here.
    return ret;
}

Önceki örnekte gösterilen yöntem, aşağıdaki örnekte olduğu gibi bir yapılandırma öğesi değiştirildiğinde çağrılır.

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

Açıklamalar

IsModified yöntemi, yöntem çağrıldığında Save bu ConfigurationElement nesnenin yapılandırma dosyasına yazıp yazılmayacağını belirler. Dönüş değeri ise false, yapılandırma dosyasının öğesinin geçerli durumunu temsil ettiğini varsayılır.

Varsayılan olarak, IsModified bir özellik dizin oluşturucu aracılığıyla bu ConfigurationElement nesneye ayarlandıktan sonra döndürürtrue.

IsModified Bu ConfigurationElement öğenin durumunun özel göstergesini sağlamak için yöntemini geçersiz kılın.

Şunlara uygulanır

Ürün Sürümler
.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