TypeBuilder.IsSecurityTransparent 屬性

定義

取得值,這個值表示目前類型是否為透明,因此無法執行重要作業。Gets a value that indicates whether the current type is transparent, and therefore cannot perform critical operations.

public:
 virtual property bool IsSecurityTransparent { bool get(); };
public override bool IsSecurityTransparent { get; }
member this.IsSecurityTransparent : bool
Public Overrides ReadOnly Property IsSecurityTransparent As Boolean

屬性值

Boolean

如果類型為安全性透明,則為 true,否則為 falsetrue if the type is security-transparent; otherwise, false.

例外狀況

尚未呼叫 CreateType() 方法建立目前動態類型。The current dynamic type has not been created by calling the CreateType() method.

備註

IsSecurityCriticalIsSecuritySafeCritical 和屬性會 IsSecurityTransparent 報告類型的透明度層級,由 common LANGUAGE runtime (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 IsSecuritySafeCriticalIsSecuritySafeCritical 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.

適用於

另請參閱