<ImpliesType> Element (.NET Native)

Applies policy to a type, if that policy has been applied to the containing type or method.

Syntax

<ImpliesType Name="type_name"
             Activate="policy_type"
             Browse="policy_type"
             Dynamic="policy_type"
             Serialize="policy_type"
             DataContractSerializer="policy_setting"
             DataContractJsonSerializer="policy_setting"
             XmlSerializer="policy_setting"
             MarshalObject="policy_setting"
             MarshalDelegate="policy_setting"
             MarshalStructure="policy_setting" />

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Attribute type Description
Name General Required attribute. Specifies the type name.
Activate Reflection Optional attribute. Controls runtime access to constructors to enable activation of instances.
Browse Reflection Optional attribute. Controls querying for information about program elements, but does not enable any runtime access.
Dynamic Reflection Optional attribute. Controls runtime access to all type members, including constructors, methods, fields, properties, and events, to enable dynamic programming.
Serialize Serialization Optional attribute. Controls runtime access to constructors, fields, and properties, to enable type instances to be serialized and deserialized by libraries such as the Newtonsoft JSON serializer.
DataContractSerializer Serialization Optional attribute. Controls policy for serialization that uses the System.Runtime.Serialization.DataContractSerializer class.
DataContractJsonSerializer Serialization Optional attribute. Controls policy for JSON serialization that uses the System.Runtime.Serialization.Json.DataContractJsonSerializer class.
XmlSerializer Serialization Optional attribute. Controls policy for XML serialization that uses the System.Xml.Serialization.XmlSerializer class.
MarshalObject Interop Optional attribute. Controls policy for marshaling reference types to Windows Runtime and COM.
MarshalDelegate Interop Optional attribute. Controls policy for marshaling delegate types as function pointers to native code.
MarshalStructure Interop Optional attribute. Controls policy for marshaling value types to native code.

Name attribute

Value Description
type_name The type name. If the type represented by this <ImpliesType> element is located in the same namespace as its containing <Type> element, type_name can include the name of the type without its namespace. Otherwise, type_name must include the fully qualified type name.

All other attributes

Value Description
policy_setting The setting to apply to this policy type. Possible values are All, Auto, Excluded, Public, PublicAndInternal, Required Public, Required PublicAndInternal, and Required All. For more information, see Runtime Directive Policy Settings.

Child Elements

None.

Parent Elements

Element Description
<Type> Applies reflection policy to a type and all its members.
<TypeInstantiation> Applies reflection policy to a constructed generic type and all its members.
<Method> Applies reflection policy to a method.

Remarks

The <ImpliesType> element is primarily intended for use by libraries. It addresses the following scenario:

  • If a routine needs to reflect on one type, it necessarily needs to reflect on a second type.

  • The metadata for the implied instantiation of the second type is otherwise unavailable, because static analysis doesn't indicate that it's necessary.

Most commonly, the two types are generic instantiations with shared type arguments.

The <ImpliesType> element was defined with the assumption that a need for reflection on the type specified by its parent element implies a need for reflection on the type specified by the <ImpliesType> element. For example, the following reflection directives apply to two types, Explicit<T> and Implicit<T>.

<Type Name="Explicit{ET}">
    <ImpliesType Name="Implicit{ET}" Dynamic="Required Public" />
</Type>

This directive has no effect unless an instantiation of Explicit has a defined Dynamic policy setting. For example, if that's the case for Explicit<Int32>, Implicit<Int32> is instantiated with its public members rooted, and their metadata is made accessible for dynamic programming.

The following is a real-world example that applies to at least one serializer. The directives capture the requirement that reflecting on something typed as IList<something> also involves reflecting on the corresponding List<something> type without requiring any per-application annotation.

<Type Name="System.Collections.Generic.IList{T}">
   <ImpliesType Name="System.Collections.Generic.List{T}" Serialize="Public" />
</Type>

The <ImpliesType> element can also appear within a <Method> element, because in some cases instantiating a generic method implies reflecting on a type instantiation. For example, imagine a generic method IEnumerable<T> MakeEnumerable<T>(string spelling, T defaultValue) that a given library will access dynamically along with the associated List<T> and Array types. This can be expressed as:

<Type Name="MyType">
    <Method Name="MakeEnumerable{T}" Signature="(System.String, T)" Dynamic="Included">
        <ImpliesType Name="T[]" Dynamic="Public" />
        <ImpliesType Name="System.Collections.Generic.List{T}" Dynamic="Public" />
    </Method>
</Type>

See also