ConfigurationElement.IsReadOnly 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,這個值表示 ConfigurationElement 物件是否唯讀。
public:
virtual bool IsReadOnly();
public virtual bool IsReadOnly ();
abstract member IsReadOnly : unit -> bool
override this.IsReadOnly : unit -> bool
Public Overridable Function IsReadOnly () As Boolean
傳回
如果 ConfigurationElement 物件是唯讀,則為 true
,否則為 false
。
範例
下列範例會示範如何使用 IsReadOnly 方法。 它會用於自訂區段,並傳 false
回 。
// Show how to use IsReadOnly.
// It loops to see if the elements are read only.
static void ReadOnlyElements()
{
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;
Console.WriteLine(elements.Count.ToString());
while (elemEnum.MoveNext())
{
Console.WriteLine("The element {0} is read only: {1}",
elements[i].Name,
elements[i].IsReadOnly().ToString());
i += 1;
}
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine("[ReadOnlyElements: {0}]",
err.ToString());
}
}
' Show how to use IsReadOnly.
' It loops to see if the elements are read only.
Shared Sub ReadOnlyElements()
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
Console.WriteLine(elements.Count.ToString())
While elemEnum.MoveNext()
Console.WriteLine("The element {0} is read only: {1}", _
elements(i).Name, elements(i).IsReadOnly().ToString())
i += 1
End While
Catch err As ConfigurationErrorsException
Console.WriteLine("[ReadOnlyElements: {0}]", _
err.ToString())
End Try
End Sub
備註
系統會定義無法修改的組態專案。
若要判斷哪些專案可以修改,請使用 IsReadOnly 方法。