Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change XmlFlowAnnotationSource implementation to expose CustomAttributes #1216

Merged
merged 6 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions docs/data-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ are applied.
```xml
<linker>
<assembly fullname="Assembly">
<attribute fullname="CustomAttributeName">
<attribute fullname="CustomAttributeName" assembly="AssemblyName">
<argument>Argument</argument>
</attribute>
</assembly>
Expand All @@ -244,7 +244,7 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<linker>
<assembly fullname="Assembly">
<type fullname="Assembly.A">
<attribute fullname="CustomAttributeName">
<attribute fullname="CustomAttributeName" assembly="AssemblyName">
<argument>Argument</argument>
</attribute>
</type>
Expand All @@ -259,7 +259,7 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<assembly fullname="Assembly">
<type fullname="Assembly.A">
<field name="MyTypeField">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</field>
Expand All @@ -275,7 +275,7 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<assembly fullname="Assembly">
<type fullname="Assembly.A">
<property name="MyTypeProperty">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</property>
Expand All @@ -291,7 +291,7 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<assembly fullname="Assembly">
<type fullname="Assembly.A">
<event name="MyTypeEvent">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="CustomAttribute" assembly="AssemblyName">
<argument>DefaultConstructor</argument>
</attribute>
</event>
Expand All @@ -308,21 +308,21 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<type fullname="Assembly.A">
<method signature="System.Void Method1(System.Type)">
<parameter name="typeParameter">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</parameter>
</method>
<method signature="System.Type Method2()">
<return>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>PublicConstructors</argument>
</attribute>
</return>
</method>
<method signature="Method3&lt;T&gt;(T)">
<parameter name="genericParameter">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</parameter>
Expand All @@ -340,17 +340,17 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<type fullname="Assembly.A">
<method signature="System.Void Method1(System.Type, System.Type, System.Type)">
<parameter name="typeParameter1">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</parameter>
<parameter name="typeParameter2">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</parameter>
<parameter name="typeParameter3">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>PublicConstructors</argument>
</attribute>
</parameter>
Expand All @@ -368,7 +368,7 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
<type fullname="Assembly.A">
<type name="NestedType">
<property name="MyTypeField">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</property>
Expand All @@ -378,6 +378,20 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
</linker>
```

### Custom attribute on type in all assemblies

```xml
<linker>
<assembly fullname="*">
<type fullname="Namespace.SpecialAttribute">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>DefaultConstructor</argument>
</attribute>
</type>
</assembly>
</linker>
```

### Conditional custom attributes

The `feature` and `featurevalue` attributes are optional, but must be used together when used.
Expand All @@ -391,7 +405,7 @@ attributes are applied.
<type fullname="Assembly.A" feature="EnableOptionalFeature" featurevalue="false">
<method signature="System.String TestMethod()">
<return>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute" assembly="System.Runtime">
<argument>PublicConstructors</argument>
</attribute>
</return>
Expand All @@ -403,6 +417,9 @@ attributes are applied.

### Custom attributes elements

The attribute element requires 'fullname' attribute without it linker will generate a warning and skip
the attribute. Optionally you can use the 'assembly' attribute to point to certain assembly to look
for the attribute, if not specified the linker will look the attribute in any loaded assembly.
Inside an attribute element in the xml you can define argument, field and property elements.
An attribute could have several arguments, several fields or several properties. When writing
custom attribute with multiple arguments you need to write the xml elements in an order dependent
Expand All @@ -411,11 +428,11 @@ second xml argument element correspond to the second custom attribute argument a
For fields and properties, you need to include the name since they are not order dependent.

```xml
<attribute fullname="SomeCustomAttribute">
<attribute fullname="SomeCustomAttribute" assembly="AssemblyName">
<argument>Argument1</argument>
<argument>Argument2</argument>
<argument>Argument3</argument>
<field name="fieldName">SomeValue</field>
<property name="propertyName">SomeValue</property>
</attribute>
```
```
30 changes: 23 additions & 7 deletions docs/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ error and warning codes.

- The 'XML document location' defined the set accessor of property 'property' on type 'type', but the accessor was not found.

#### `IL2020`: DynamicallyAccessedMembers attribute was specified but no argument was proportioned
#### `IL2020`: Argument 'argument' specified in 'XML document location' is of unsupported type 'type'

- The XML descriptor has a DynamicallyAccessedMembers attribute but the argument 'argument' does not match any of the existing DynamicallyAccessedMemberTypes
- The constructor parameter type is not supported in the XML reading code.

#### `IL2021`: Could not parse argument 'argument' specified in 'XML document location' as a DynamicallyAccessedMemberTypes
#### `IL2021`: Could not parse argument 'argument' specified in 'XML document location' as a 'type'

- The XML descriptor has a DynamicallyAccessedMembers attribute but the argument 'argument' does not match any of the existing DynamicallyAccessedMemberTypes
- The XML descriptor has a 'type' attribute but the argument 'argument' does not match any of the existing enum 'type' values

#### `IL2022`: DynamicallyAccessedMembers attribute was specified but there is more than one argument
#### `IL2022`: Could not find a constructor for type 'attribute type' that receives 'number of arguments' arguments as parameter

- The XML descriptor has more than one argument for a single DynamicallyAccessedMembers attribute, there can only be one argument in order to parse it
- The 'attribute type' 'number of arguments' doesnt match with the number of arguments in any of the constructor function described in 'attribute type'

#### `IL2023`: There is more than one return parameter specified for 'method' in 'XML document location'

Expand All @@ -169,4 +169,20 @@ error and warning codes.

#### `IL2028`: Attribute 'attribute' on 'method' doesn't have a required constructor argument.

- The linker found an instance of attribute 'attribute' on 'method' but it lacks a required constructor argument. Linker will ignore this attribute.
- The linker found an instance of attribute 'attribute' on 'method' but it lacks a required constructor argument. Linker will ignore this attribute.

#### `IL2029`: Attribute element does not contain attribute 'fullname'

- An attribute element was declared but does not contain the attribute 'fullname' or 'fullname' attribute is empty

#### `IL2030`: Could not resolve assembly 'assembly' in attribute 'attribute' specified in the 'XML document location'

- The assembly 'assembly' described as a attribute property of 'attribute' could not be resolved in 'XML document location'

#### `IL2031`: Attribute type 'attribute type' could not be found

- The described 'attribute type' could not be found in the assemblies

#### `IL2032`: Argument 'argument' specified in 'XML document location' could not be transformed to the constructor parameter type

- The number of arguments correspond to a certain type constructor, but the type of arguments specified in the xml does not match the type of arguments in the constructor.
46 changes: 0 additions & 46 deletions src/linker/Linker.Dataflow/AggregateFlowAnnotationSource.cs

This file was deleted.

70 changes: 0 additions & 70 deletions src/linker/Linker.Dataflow/AttributeFlowAnnotationSource.cs

This file was deleted.

Loading