MetadataLoadContext.CoreAssembly Propriedade

Definição

Obtém ou define o assembly que denota o "assembly de sistema" que hospeda os tipos conhecidos, tais como Int32.Gets or sets the assembly that denotes the "system assembly" that houses the well-known types such as Int32.

public:
 property System::Reflection::Assembly ^ CoreAssembly { System::Reflection::Assembly ^ get(); };
public System.Reflection.Assembly CoreAssembly { get; }
public System.Reflection.Assembly? CoreAssembly { get; }
member this.CoreAssembly : System.Reflection.Assembly
Public ReadOnly Property CoreAssembly As Assembly

Valor da propriedade

Assembly

Uma instância Assembly.An Assembly instance.

Comentários

O assembly principal é tratado de forma diferente de outros assemblies porque as referências a esses tipos conhecidos não incluem a referência de assembly, ao contrário dos tipos normais.The core assembly is treated differently than other assemblies because references to these well-known types do not include the assembly reference, unlike normal types.

Normalmente, esse assembly é denominado "mscorlib" ou "netstandard".Typically, this assembly is named "mscorlib" or "netstandard". Se o assembly principal não puder ser encontrado, o valor será null , e muitos outros métodos de reflexão, incluindo aqueles que analisam assinaturas de método, gerarão uma exceção.If the core assembly cannot be found, the value will be null, and many other reflection methods, including those that parse method signatures, will throw an exception.

O CoreAssembly é determinado pela passagem do coreAssemblyName parâmetro passado para o MetadataAssemblyResolver construtor para o MetadataAssemblyResolver.Resolve método.The CoreAssembly is determined by passing the coreAssemblyName parameter passed to the MetadataAssemblyResolver constructor to the MetadataAssemblyResolver.Resolve method.

Se nenhum coreAssemblyName argumento tiver sido especificado no construtor de MetadataLoadContext , os valores padrão serão usados, incluindo "mscorlib", "System. Runtime" e "netstandard".If no coreAssemblyName argument was specified in the constructor of MetadataLoadContext, then default values are used, including "mscorlib", "System.Runtime" and "netstandard".

O assembly principal designado não precisa conter os tipos principais diretamente.The designated core assembly does not need to contain the core types directly. Ele pode digitar encaminhá-los para outros assemblies.It can type forward them to other assemblies. Portanto, é perfeitamente permitido usar a fachada mscorlib como o assembly principal designado.Thus, it is perfectly permissible to use the mscorlib facade as the designated core assembly.

Observe que System.Runtime não é um assembly principal ideal porque ele exclui alguns dos tipos de atributo pseudo personalizados relacionados à interoperabilidade, como DllImportAttribute .Note that System.Runtime is not an ideal core assembly because it excludes some of the interop-related pseudo-custom attribute types such as DllImportAttribute. No entanto, ele pode servir se você não tiver interesse nesses atributos.However, it can serve if you have no interest in those attributes. A API CustomAttributes ignorará esses atributos se o assembly principal não incluir os tipos necessários.The CustomAttributes API will skip those attributes if the core assembly does not include the necessary types.

O assembly principal não é carregado até que seja necessário.The core assembly is not loaded until necessary. As APIs a seguir não disparam a pesquisa do assembly principal:The following APIs do not trigger the search for the core assembly:

Se um assembly principal não puder ser encontrado ou se o assembly principal estiver com tipos ausentes, isso afetará o comportamento do da MetadataLoadContext seguinte maneira:If a core assembly cannot be found or if the core assembly is missing types, this will affect the behavior of the MetadataLoadContext as follows:

  • As APIs que precisam analisar assinaturas ou TypeSpecs e retornar os resultados como Type objetos gerarão uma exceção.APIs that need to parse signatures or typespecs and return the results as Type objects will throw an exception. Por exemplo:For example:

  • As APIs que precisam comparar tipos com tipos principais conhecidos não lançarão uma exceção e a comparação será avaliada como false .APIs that need to compare types to well-known core types will not throw an exception, and the comparison will evaluate to false. Por exemplo, se você não especificar um assembly de núcleo, o IsPrimitive retornará false para tudo, até mesmo os tipos chamados Int32 .For example, if you do not specify a core assembly, IsPrimitive will return false for everything, even types named Int32. Da mesma forma, o Type.GetTypeCode retornará Object para tudo.Similarly, Type.GetTypeCode will return Object for everything.

  • Se uma entidade de metadados definir sinalizadores que Surface como um atributo pseudo personalizado e o assembly principal não contiver o tipo de atributo pseudo-personalizado, o Construtor necessário ou qualquer um dos tipos de parâmetro do Construtor, o MetadataLoadContext não será gerado.If a metadata entity sets flags that surface as a pseudo-custom attribute, and the core assembly does not contain the pseudo-custom attribute type, the necessary constructor or any of the parameter types of the constructor, the MetadataLoadContext will not throw. Ele omitirá o atributo pseudo-personalizado da lista de atributos retornados.It will omit the pseudo-custom attribute from the list of returned attributes.

Aplica-se a