DependencyAttribute(String, LoadHint) 构造函数

定义

使用指定的 LoadHint 值初始化 DependencyAttribute 类的新实例。

public DependencyAttribute (string dependentAssemblyArgument, System.Runtime.CompilerServices.LoadHint loadHintArgument);

参数

dependentAssemblyArgument
String

要绑定到的依赖程序集。

loadHintArgument
LoadHint

LoadHint 值之一。

示例

以下示例指定本机映像生成服务始终绑定到 AssemblyA ,有时绑定到 AssemblyB

using System;
using System.Runtime.CompilerServices;

[assembly: DependencyAttribute("AssemblyA", LoadHint.Always)]
[assembly: DependencyAttribute("AssemblyB", LoadHint.Sometimes)]

class Program
{

    static void Main(string[] args)
    {

        Console.WriteLine("The DependencyAttribute attribute was applied.");
    }
}

注解

特性 DependencyAttribute 提供公共语言运行时提示绑定到依赖项的紧密程度。 运行时使用这些提示来帮助解决延迟依赖项负载与高效绑定到依赖项之间的权衡。 例如,硬绑定允许运行时对指向依赖本机映像的指针进行编码,这会导致工作集减少。 此属性指导运行时做出这些决策。

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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
.NET Standard 2.0, 2.1