TypeBuilder.IsSecurityCritical 属性
定义
获取一个值,该值指示当前类型是安全-关键的还是安全-可靠-关键的,且因此是否可执行关键操作。Gets a value that indicates whether the current type is security-critical or security-safe-critical, and therefore can perform critical operations.
public:
virtual property bool IsSecurityCritical { bool get(); };
public override bool IsSecurityCritical { get; }
member this.IsSecurityCritical : bool
Public Overrides ReadOnly Property IsSecurityCritical As Boolean
属性值
如果当前类型是安全-关键的或安全-可靠-关键的,则为 true;如果它是透明的,则为 false。true if the current type is security-critical or security-safe-critical; false if it is transparent.
例外
当前动态类型不是通过调用 CreateType() 方法创建的。The current dynamic type has not been created by calling the CreateType() method.
注解
IsSecurityCritical、 IsSecuritySafeCritical 和 IsSecurityTransparent 属性报告由公共语言运行时 (CLR) 确定的类型的透明度级别。The IsSecurityCritical, IsSecuritySafeCritical, and IsSecurityTransparent properties report the transparency level of the type, as determined by the common language runtime (CLR). 下表显示了这些属性的组合:The combinations of these properties are shown in the following table:
| 安全级别Security level | IsSecurityCriticalIsSecurityCritical | IsSecurityCriticalIsSecuritySafeCritical | IsSecurityTransparentIsSecurityTransparent |
|---|---|---|---|
| 严重Critical | true |
false |
false |
| 安全-关键Safe-critical | true |
true |
false |
| 透明Transparent | false |
false |
true |
使用这些属性比检查程序集及其类型的安全批注、检查当前的信任级别,以及尝试复制运行时的规则要简单得多。Using these properties is much simpler than examining the security annotations of an assembly and its types, checking the current trust level, and attempting to duplicate the runtime's rules.
运行时开始计算程序集的透明度级别。The runtime begins evaluating transparency levels at the assembly. 例如,如果动态程序集是安全关键的,则类型上的批注将被忽略,并且所有类型都是安全关键的。For example, if the dynamic assembly is security-critical, annotations on types are ignored, and all types are security-critical.
默认情况下,动态程序集继承发出它的程序集的透明度。By default, a dynamic assembly inherits the transparency of the assembly that emits it. 您可以使用 AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>) 、 AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>) 或 AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>) 方法重载,并指定安全特性来重写此默认值。You can override this default by using the AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>), AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>), or AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>) method overload and specifying security attributes. 您无法通过执行此操作提升安全级别;也就是说,透明代码无法发出安全关键代码或安全可靠关键代码。You cannot elevate security levels by doing this; that is, transparent code cannot emit security-critical or security-safe-critical code. 创建动态程序集时必须指定属性,或在程序集保存到磁盘并重新加载后,它们才会生效。Attributes must be specified when the dynamic assembly is created, or they do not take effect until the assembly has been saved to disk and reloaded.
备注
默认继承限制为运行时的透明度计算。Default inheritance is limited to the runtime's evaluation of transparency. 没有属性应用于动态程序集。No attributes are applied to the dynamic assembly. 如果要添加安全属性,则必须自行应用这些属性。If you want to add security attributes, you must apply them yourself.
有关反射发出和透明度的详细信息,请参阅 反射发出中的安全问题。For more information about reflection emit and transparency, see Security Issues in Reflection Emit. 有关透明度的信息,请参阅 安全更改。For information about transparency, see Security Changes.
适用于
另请参阅
- IsSecuritySafeCritical
- IsSecurityTransparent
- 反射发出中的安全问题Security Issues in Reflection Emit
- 反射的安全注意事项Security Considerations for Reflection
- .NET Framework 4.0 版中的安全性更改Security Changes in the .NET Framework Version 4.0
- 安全透明的代码,级别 1Security-Transparent Code, Level 1
- 安全透明的代码,级别 2Security-Transparent Code, Level 2