Skip to content

Add TypeDescriptionProviderAttribute detection #807

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

Merged
merged 1 commit into from
Nov 1, 2019
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
13 changes: 8 additions & 5 deletions src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ void MarkTypeSpecialCustomAttributes (TypeDefinition type)
case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing":
MarkMethodsIf (type.Methods, IsPublicInstancePropertyMethod);
break;
case "TypeDescriptionProviderAttribute" when attrType.Namespace == "System.ComponentModel":
MarkTypeConverterLikeDependency (attribute, l => l.IsDefaultConstructor ());
break;
}
}
}
Expand All @@ -1173,7 +1176,9 @@ bool MarkSpecialCustomAttributeDependencies (CustomAttribute ca)
{
var dt = ca.Constructor.DeclaringType;
if (dt.Name == "TypeConverterAttribute" && dt.Namespace == "System.ComponentModel") {
MarkTypeConverterDependency (ca);
MarkTypeConverterLikeDependency (ca, l =>
l.IsDefaultConstructor () ||
l.Parameters.Count == 1 && l.Parameters [0].ParameterType.IsTypeOf ("System", "Type"));
return true;
}

Expand Down Expand Up @@ -1203,7 +1208,7 @@ void MarkXmlSchemaProvider (TypeDefinition type, CustomAttribute attribute)
MarkNamedMethod (type, method_name);
}

void MarkTypeConverterDependency (CustomAttribute attribute)
void MarkTypeConverterLikeDependency (CustomAttribute attribute, Func<MethodDefinition, bool> predicate)
{
var args = attribute.ConstructorArguments;
if (args.Count < 1)
Expand All @@ -1222,9 +1227,7 @@ void MarkTypeConverterDependency (CustomAttribute attribute)
if (tdef == null)
return;

MarkMethodsIf (tdef.Methods, l =>
l.IsDefaultConstructor () ||
l.Parameters.Count == 1 && l.Parameters [0].ParameterType.IsTypeOf ("System", "Type"));
MarkMethodsIf (tdef.Methods, predicate);
}

void MarkTypeWithDebuggerDisplayAttribute (TypeDefinition type, CustomAttribute attribute)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.ComponentModel;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.ComponentModel
{
[TypeDescriptionProvider (typeof (CustomTDP))]

[Kept]
[KeptAttributeAttribute (typeof (TypeDescriptionProviderAttribute))]
class CustomTypeDescriptionProvider_1
{
[Kept]
public CustomTypeDescriptionProvider_1 ()
{
}

[Kept]
[KeptBaseType (typeof (TypeDescriptionProvider))]
class CustomTDP : TypeDescriptionProvider
{
[Kept]
public CustomTDP ()
{
}
}
}

[Reference ("System.dll")]
public class TypeDescriptionProviderAttributeOnType
{
public static void Main ()
{
var r1 = new CustomTypeDescriptionProvider_1 ();
}
}
}