AssemblyCollection 类

定义

表示 对象的集合 AssemblyInfo 。 此类不能被继承。

public ref class AssemblyCollection sealed : System::Configuration::ConfigurationElementCollection
[System.Configuration.ConfigurationCollection(typeof(System.Web.Configuration.AssemblyInfo))]
public sealed class AssemblyCollection : System.Configuration.ConfigurationElementCollection
[<System.Configuration.ConfigurationCollection(typeof(System.Web.Configuration.AssemblyInfo))>]
type AssemblyCollection = class
    inherit ConfigurationElementCollection
Public NotInheritable Class AssemblyCollection
Inherits ConfigurationElementCollection
继承
属性

示例

本部分提供了两个代码示例。 第一个演示如何以声明方式指定类的 AssemblyCollection 多个属性的值。 第二个演示如何使用类的成员 AssemblyCollection

以下配置文件示例演示如何以声明方式指定类的 AssemblyCollection 多个属性的值。

<system.web>
  <compilation>
    <assemblies>
      <add assembly="mscorlib" />
      <add assembly="System, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b77a5c561934e089" />
      <add assembly="System.Configuration, Version=2.0.0.0,
        Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.Data, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b77a5c561934e089" />
      <add assembly="System.Web.Services, Version=2.0.0.0,
        Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b77a5c561934e089" />
      <add assembly="System.Drawing, Version=2.0.0.0,
        Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.EnterpriseServices, Version=2.0.0.0,
        Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.Web.Mobile, Version=2.0.0.0,
        Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="System.Web.UI.MobileControls.Adapters,
        Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a" />
      <add assembly="*" />
    </assemblies>
  </compilation>
</system.web>

下面的代码示例演示如何使用类的成员 AssemblyCollection

#region Using directives

using System;
using System.Configuration;
using System.Web.Configuration;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingAssemblyCollection
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config = 
          WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        CompilationSection configSection =
          (CompilationSection)config.GetSection("system.web/compilation");

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);

        // Create a new assembly reference.
        AssemblyInfo myAssembly = 
          new AssemblyInfo("MyAssembly, Version=1.0.0000.0, " +
          "Culture=neutral, Public KeyToken=b03f5f7f11d50a3a");
        // Add an assembly to the configuration.
        configSection.Assemblies.Add(myAssembly);

        // Add a second assembly reference.
        AssemblyInfo myAssembly2 = new AssemblyInfo("MyAssembly2");
        configSection.Assemblies.Add(myAssembly2);

        // Assembly Collection
        int i = 1;
        int j = 1;
        foreach (AssemblyInfo assemblyItem in configSection.Assemblies)
        {
          Console.WriteLine();
          Console.WriteLine("Assemblies {0} Details:", i);
          Console.WriteLine("Type: {0}", assemblyItem.ElementInformation.Type);
          Console.WriteLine("Source: {0}", assemblyItem.ElementInformation.Source);
          Console.WriteLine("LineNumber: {0}", assemblyItem.ElementInformation.LineNumber);
          Console.WriteLine("Properties Count: {0}", 
            assemblyItem.ElementInformation.Properties.Count);
          j = 1;
          foreach (PropertyInformation propertyItem in assemblyItem.ElementInformation.Properties)
          {
            Console.WriteLine("Property {0} Name: {1}", j, propertyItem.Name);
            Console.WriteLine("Property {0} Value: {1}", j, propertyItem.Value);
            j++;
          }
          i++;
        }

        // Remove an assembly.
        configSection.Assemblies.Remove("MyAssembly, Version=1.0.0000.0, " +
          "Culture=neutral, Public KeyToken=b03f5f7f11d50a3a");

        // Remove an assembly.
        configSection.Assemblies.RemoveAt(configSection.Assemblies.Count - 1);

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait.
      Console.ReadLine();
    }
  }
}
Imports System.Configuration
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingAssemblyCollection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration = _
         WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As System.Web.Configuration.CompilationSection = _
         CType(config.GetSection("system.web/compilation"), _
         System.Web.Configuration.CompilationSection)

        ' Display title and info.
        Console.WriteLine("ASP.NET Configuration Info")
        Console.WriteLine()

        ' Display Config details.
        Console.WriteLine("File Path: {0}", _
         config.FilePath)
        Console.WriteLine("Section Path: {0}", _
         configSection.SectionInformation.Name)

        ' Create a new assembly reference.
        Dim myAssembly As AssemblyInfo = New AssemblyInfo("MyAssembly, " + _
        "Version=1.0.0000.0, Culture=neutral, Public KeyToken=b03f5f7f11d50a3a")
        ' Add an assembly to the configuration.
        configSection.Assemblies.Add(myAssembly)

        ' Add a second assembly reference.
        Dim myAssembly2 As AssemblyInfo = New AssemblyInfo("MyAssembly2")
        configSection.Assemblies.Add(myAssembly2)

        ' Assembly Collection
        Dim i = 1
        Dim j = 1
        For Each assemblyItem As AssemblyInfo In configSection.Assemblies
          Console.WriteLine()
          Console.WriteLine("Assemblies {0} Details:", i)
          Console.WriteLine("Type: {0}", assemblyItem.ElementInformation.Type)
          Console.WriteLine("Source: {0}", assemblyItem.ElementInformation.Source)
          Console.WriteLine("LineNumber: {0}", assemblyItem.ElementInformation.LineNumber)
          Console.WriteLine("Properties Count: {0}", assemblyItem.ElementInformation.Properties.Count)
          j = 1
          For Each propertyItem As PropertyInformation In assemblyItem.ElementInformation.Properties
            Console.WriteLine("Property {0} Name: {1}", j, propertyItem.Name)
            Console.WriteLine("Property {0} Value: {1}", j, propertyItem.Value)
            j = j + 1
          Next
          i = i + 1
        Next

        ' Remove an assembly.
        configSection.Assemblies.Remove("MyAssembly, Version=1.0.0000.0, " + _
          "Culture=neutral, Public KeyToken=b03f5f7f11d50a3a")

        ' Remove an assembly.
        configSection.Assemblies.RemoveAt(configSection.Assemblies.Count - 1)

        ' Update if not locked.
        If Not configSection.SectionInformation.IsLocked Then
          config.Save()
          Console.WriteLine("** Configuration updated.")
        Else
          Console.WriteLine("** Could not update, section is locked.")
        End If

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

注解

AssemblyCollection 类不引用基础配置文件中的任何实际元素。 它是一个允许访问其包含的程序集信息的构造。

构造函数

名称 说明
AssemblyCollection()

初始化 AssemblyCollection 类的新实例。

属性

名称 说明
AddElementName

获取或设置在派生类中重写时要与 ConfigurationElement 中的添加操作关联的 ConfigurationElementCollection 的名称。

(继承自 ConfigurationElementCollection)
ClearElementName

获取或设置在派生类中重写时要与 ConfigurationElement 中的清除操作关联的 ConfigurationElementCollection 的名称。

(继承自 ConfigurationElementCollection)
CollectionType

获取 ConfigurationElementCollection的类型。

(继承自 ConfigurationElementCollection)
Count

获取集合中的元素数。

(继承自 ConfigurationElementCollection)
CurrentConfiguration

获取对顶级 Configuration 实例的引用,该实例表示当前 ConfigurationElement 实例所属的配置层次结构。

(继承自 ConfigurationElement)
ElementInformation

获取一个 ElementInformation 对象,该对象包含 ConfigurationElement 对象的不可自定义信息和功能。

(继承自 ConfigurationElement)
ElementName

获取在派生类中重写时用于标识配置文件中此元素集合的名称。

(继承自 ConfigurationElementCollection)
ElementProperty

获取表示 ConfigurationElementProperty 对象本身的 ConfigurationElement 对象。

(继承自 ConfigurationElement)
EmitClear

获取或设置一个值,该值指定集合是否已清除。

(继承自 ConfigurationElementCollection)
EvaluationContext

获取 ContextInformation 对象的 ConfigurationElement 对象。

(继承自 ConfigurationElement)
HasContext

获取一个值,该值指示 CurrentConfiguration 属性是否 null

(继承自 ConfigurationElement)
IsSynchronized

获取一个值,该值指示是否同步对集合的访问。

(继承自 ConfigurationElementCollection)
Item[ConfigurationProperty]

获取或设置此配置元素的属性或属性。

(继承自 ConfigurationElement)
Item[Int32]

获取或设置 AssemblyInfo 指定索引处的 AssemblyCollection

Item[String]

获取由指定程序集名称标识的项。

LockAllAttributesExcept

获取锁定属性的集合。

(继承自 ConfigurationElement)
LockAllElementsExcept

获取锁定元素的集合。

(继承自 ConfigurationElement)
LockAttributes

获取锁定属性的集合。

(继承自 ConfigurationElement)
LockElements

获取锁定元素的集合。

(继承自 ConfigurationElement)
LockItem

获取或设置一个值,该值指示元素是否已锁定。

(继承自 ConfigurationElement)
Properties

获取属性的集合。

(继承自 ConfigurationElement)
RemoveElementName

获取或设置在派生类中重写时要与 ConfigurationElement 中删除操作关联的 ConfigurationElementCollection 的名称。

(继承自 ConfigurationElementCollection)
SyncRoot

获取一个对象,该对象用于同步对 ConfigurationElementCollection的访问。

(继承自 ConfigurationElementCollection)
ThrowOnDuplicate

获取一个值,该值指示是否尝试向 ConfigurationElement 添加重复 ConfigurationElementCollection 将导致引发异常。

(继承自 ConfigurationElementCollection)

方法

名称 说明
Add(AssemblyInfo)

将对象 AssemblyInfo 添加到 AssemblyCollection 集合。

BaseAdd(ConfigurationElement, Boolean)

将配置元素添加到配置元素集合。

(继承自 ConfigurationElementCollection)
BaseAdd(ConfigurationElement)

将配置元素添加到 ConfigurationElementCollection

(继承自 ConfigurationElementCollection)
BaseAdd(Int32, ConfigurationElement)

将配置元素添加到配置元素集合。

(继承自 ConfigurationElementCollection)
BaseClear()

从集合中删除所有配置元素对象。

(继承自 ConfigurationElementCollection)
BaseGet(Int32)

获取位于指定索引位置的配置元素。

(继承自 ConfigurationElementCollection)
BaseGet(Object)

返回具有指定键的配置元素。

(继承自 ConfigurationElementCollection)
BaseGetAllKeys()

返回 ConfigurationElementCollection中包含的所有配置元素的键数组。

(继承自 ConfigurationElementCollection)
BaseGetKey(Int32)

获取指定索引位置处 ConfigurationElement 的键。

(继承自 ConfigurationElementCollection)
BaseIndexOf(ConfigurationElement)

指示指定 ConfigurationElement的索引。

(继承自 ConfigurationElementCollection)
BaseIsRemoved(Object)

指示是否已从 ConfigurationElement中删除具有指定键的 ConfigurationElementCollection

(继承自 ConfigurationElementCollection)
BaseRemove(Object)

从集合中删除 ConfigurationElement

(继承自 ConfigurationElementCollection)
BaseRemoveAt(Int32)

删除位于指定索引位置的 ConfigurationElement

(继承自 ConfigurationElementCollection)
Clear()

清除AssemblyInfo集合中的所有AssemblyCollection对象。

CopyTo(ConfigurationElement[], Int32)

ConfigurationElementCollection 的内容复制到数组。

(继承自 ConfigurationElementCollection)
CreateNewElement()

在派生类中重写时,创建新的 ConfigurationElement

(继承自 ConfigurationElementCollection)
CreateNewElement(String)

在派生类中重写时创建新的 ConfigurationElement

(继承自 ConfigurationElementCollection)
DeserializeElement(XmlReader, Boolean)

从配置文件中读取 XML。

(继承自 ConfigurationElement)
Equals(Object)

ConfigurationElementCollection 与指定对象进行比较。

(继承自 ConfigurationElementCollection)
GetElementKey(ConfigurationElement)

获取在派生类中重写时指定配置元素的元素键。

(继承自 ConfigurationElementCollection)
GetEnumerator()

获取用于循环访问的IEnumerator一个 ConfigurationElementCollection

(继承自 ConfigurationElementCollection)
GetHashCode()

获取表示 ConfigurationElementCollection 实例的唯一值。

(继承自 ConfigurationElementCollection)
GetTransformedAssemblyString(String)

返回指定程序集名称的转换版本。

(继承自 ConfigurationElement)
GetTransformedTypeString(String)

返回指定类型名称的转换版本。

(继承自 ConfigurationElement)
GetType()

获取当前实例的 Type

(继承自 Object)
Init()

ConfigurationElement 对象设置为其初始状态。

(继承自 ConfigurationElement)
InitializeDefault()

用于初始化 ConfigurationElement 对象的默认值集。

(继承自 ConfigurationElement)
IsElementName(String)

指示指定的 ConfigurationElement 是否存在于 ConfigurationElementCollection中。

(继承自 ConfigurationElementCollection)
IsElementRemovable(ConfigurationElement)

指示是否可以从 ConfigurationElement中删除指定的 ConfigurationElementCollection

(继承自 ConfigurationElementCollection)
IsModified()

指示在派生类中重写此 ConfigurationElementCollection 自上次保存或加载以来是否已修改。

(继承自 ConfigurationElementCollection)
IsReadOnly()

指示 ConfigurationElementCollection 对象是否为只读。

(继承自 ConfigurationElementCollection)
ListErrors(IList)

将此 ConfigurationElement 对象和所有子元素中的无效属性错误添加到传递的列表。

(继承自 ConfigurationElement)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnDeserializeUnrecognizedAttribute(String, String)

获取一个值,该值指示在反序列化期间是否遇到未知属性。

(继承自 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

使配置系统引发异常。

(继承自 ConfigurationElementCollection)
OnRequiredPropertyNotFound(String)

在找不到所需属性时引发异常。

(继承自 ConfigurationElement)
PostDeserialize()

反序列化后调用。

(继承自 ConfigurationElement)
PreSerialize(XmlWriter)

在序列化之前调用。

(继承自 ConfigurationElement)
Remove(String)

AssemblyInfo 集合中删除对象 AssemblyCollection

RemoveAt(Int32)

AssemblyInfo集合中删除对象AssemblyCollection

Reset(ConfigurationElement)

在派生类中重写时,将 ConfigurationElementCollection 重置为其未修改的状态。

(继承自 ConfigurationElementCollection)
ResetModified()

在派生类中重写时,将 IsModified() 属性的值重置为 false

(继承自 ConfigurationElementCollection)
SerializeElement(XmlWriter, Boolean)

在派生类中重写时,将配置数据写入配置文件中的 XML 元素。

(继承自 ConfigurationElementCollection)
SerializeToXmlElement(XmlWriter, String)

在派生类中实现时,将此配置元素的外部标记写入配置文件。

(继承自 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

将属性设置为指定的值。

(继承自 ConfigurationElement)
SetReadOnly()

设置 IsReadOnly() 对象和所有子元素的 ConfigurationElementCollection 属性。

(继承自 ConfigurationElementCollection)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

反转从配置层次结构的不同级别合并配置信息的效果。

(继承自 ConfigurationElementCollection)

显式接口实现

名称 说明
ICollection.CopyTo(Array, Int32)

ConfigurationElementCollection 复制到数组。

(继承自 ConfigurationElementCollection)

扩展方法

名称 说明
AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

适用于

另请参阅