UrlMappingCollection.Clear 方法
定义
从集合中移除所有 UrlMapping 对象。Removes all the UrlMapping objects from the collection.
public:
void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()
示例
下面的代码示例 UrlMapping 从中移除所有对象 UrlMappingCollection 。The following code example removes all UrlMapping objects from the UrlMappingCollection.
有关如何获取集合的详细说明,请参阅类主题中的代码示例 UrlMappingCollection 。Refer to the code example in the UrlMappingCollection class topic to learn how to get the collection.
// Clear the url mapping collection.
urlMappings.Clear();
// Update the configuration file.
// Define the save modality.
ConfigurationSaveMode saveMode =
ConfigurationSaveMode.Minimal;
urlMappings.EmitClear =
Convert.ToBoolean(parm2);
if (parm1 == "none")
{
if (!urlMappingSection.IsReadOnly())
configuration.Save();
msg = String.Format(
"Default modality, EmitClear: {0}",
urlMappings.EmitClear.ToString());
}
else
{
if (parm1 == "full")
saveMode = ConfigurationSaveMode.Full;
else
if (parm1 == "modified")
saveMode = ConfigurationSaveMode.Modified;
if (!urlMappingSection.IsReadOnly())
configuration.Save(saveMode);
msg = String.Format(
"Save modality: {0}",
saveMode.ToString());
}
' Clear the url mapping collection.
urlMappings.Clear()
' Update the configuration file.
' Define the save modality.
Dim saveMode _
As ConfigurationSaveMode = _
ConfigurationSaveMode.Minimal
urlMappings.EmitClear = _
Convert.ToBoolean(parm2)
If parm1 = "none" Then
If Not urlMappingSection.IsReadOnly() Then
configuration.Save()
End If
msg = String.Format( _
"Default modality, EmitClear: {0}", _
urlMappings.EmitClear.ToString())
Else
If parm1 = "full" Then
saveMode = ConfigurationSaveMode.Full
ElseIf parm1 = "modified" Then
saveMode = ConfigurationSaveMode.Modified
End If
If Not urlMappingSection.IsReadOnly() Then
configuration.Save(saveMode)
End If
msg = String.Format( _
"Save modality: {0}", _
saveMode.ToString())
End If
注解
如果在调用方法后保存配置文件 Clear ,结果将取决于所选的 ConfigurationSaveMode 。If you save the configuration file after calling the Clear method, the result will be dependent upon the chosen ConfigurationSaveMode.
以下列表描述了使用方法保存文件时适用的条件 Save :The following list describes the conditions that apply if you use the Save method to save the file:
如果将 Full 或 ConfigurationSaveMode.Modified 作为参数值传递,则
clear会urlMappings在当前层次结构级别的配置文件的部分中插入元素。If you pass Full or ConfigurationSaveMode.Modified as the parameter value, aclearelement is inserted into theurlMappingssection of the configuration file at the current hierarchy level.如果 Minimal 作为参数值传递,则会将一系列
remove元素添加到urlMappings当前层次结构级别的配置文件的中。If you pass Minimal as the parameter value, a series ofremoveelements are added to theurlMappingsof the configuration file at the current hierarchy level. 这些remove元素删除对add层次结构中较高级别上的父配置文件中定义的元素的所有引用。Theseremoveelements remove all references to theaddelements defined in the parent configuration files at higher levels in the hierarchy. 对于 Minimal 枚举值,集合上还有一个附加属性,该属性会影响序列化到配置文件的内容。With the Minimal enumeration value, there is one additional property on the collection that affects what gets serialized to the configuration file. 属性为 EmitClear ,并且false默认为。The property is EmitClear and isfalseby default. 以下条件之一适用:One of the following conditions applies:EmitClear 设置为
true。EmitClear set totrue.clear元素插入到urlMappings配置文件中当前层次结构级别的部分。Aclearelement is inserted into theurlMappingssection of the configuration file at the current hierarchy level. 这将删除对add层次结构中较高级别上的父配置文件中定义的元素的所有引用。This removes all references to theaddelements defined in the parent configuration files at higher levels in the hierarchy.EmitClear 标志设置为
false。EmitClear flag is set tofalse. 这具有clear从urlMappings当前层次结构级别的配置文件的部分中删除元素(如果存在)的效果。This has the effect of removing theclearelement from theurlMappingssection of the configuration file at the current hierarchy level, if it exists.
Clear方法实际删除 add 在 urlMappings 当前层次结构级别的配置文件的部分中定义的元素。The Clear method actually deletes the add elements defined in the urlMappings section of the configuration file at the current hierarchy level. 它还删除对 add 层次结构中较高级别上的父配置文件中定义的元素的所有引用,但不会删除它们。It also removes all references to the add elements defined in the parent configuration files at higher levels in the hierarchy but does not delete them.