Skip to content

Commit f56754e

Browse files
committed
Clean up DynamicDependencyAttribute: review feedback + another test
1 parent 6fd1230 commit f56754e

6 files changed

Lines changed: 25 additions & 215 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.ComponentModel;
3+
4+
/// <summary>
5+
/// Tests that the System.ComponentModel.TypeDescriptor.InterfaceType
6+
/// property works as expected when used in a trimmed application.
7+
/// </summary>
8+
class Program
9+
{
10+
static int Main(string[] args)
11+
{
12+
Type type = TypeDescriptor.InterfaceType;
13+
14+
// Tests that the ctor for System.ComponentModel.TypeDescriptor+TypeDescriptorInterface is not trimmed out.
15+
object obj = Activator.CreateInstance(type);
16+
string expectedObjTypeNamePrefix = "System.ComponentModel.TypeDescriptor+TypeDescriptorInterface, System.ComponentModel.TypeConverter, Version=";
17+
18+
return obj != null && obj.GetType().AssemblyQualifiedName.StartsWith(expectedObjTypeNamePrefix)
19+
? 100
20+
: -1;
21+
}
22+
}

src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ public PropertyFetch(Type? type)
892892
/// <summary>
893893
/// Create a property fetcher for a propertyName
894894
/// </summary>
895+
[DynamicDependency("#ctor(System.Type)", typeof(EnumeratePropertyFetch<>))]
896+
[DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(RefTypedFetchProperty<,>))]
897+
[DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(ValueTypedFetchProperty<,>))]
895898
public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
896899
{
897900
if (propertyName == null)
@@ -946,12 +949,6 @@ public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
946949
Logger.Message($"Property {propertyName} not found on {type}");
947950
return new PropertyFetch(type);
948951
}
949-
// Delegate creation below is incompatible with static properties.
950-
else if (propertyInfo.GetMethod?.IsStatic == true || propertyInfo.SetMethod?.IsStatic == true)
951-
{
952-
Logger.Message($"Property {propertyName} is static.");
953-
return new PropertyFetch(type);
954-
}
955952
Type typedPropertyFetcher = typeInfo.IsValueType ?
956953
typeof(ValueTypedFetchProperty<,>) : typeof(RefTypedFetchProperty<,>);
957954
Type instantiatedTypedPropertyFetcher = typedPropertyFetcher.GetTypeInfo().MakeGenericType(
@@ -969,8 +966,6 @@ public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
969966

970967
private sealed class RefTypedFetchProperty<TObject, TProperty> : PropertyFetch
971968
{
972-
[DynamicDependency("get_TraceStateString", typeof(Activity))]
973-
[DynamicDependency("get_IsAllDataRequested", typeof(Activity))]
974969
public RefTypedFetchProperty(Type type, PropertyInfo property) : base(type)
975970
{
976971
Debug.Assert(typeof(TObject).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()));

src/libraries/System.Diagnostics.DiagnosticSource/tests/TrimmingTests/EventSourcePropertyFetchTest.cs

Lines changed: 0 additions & 200 deletions
This file was deleted.

src/libraries/System.Diagnostics.DiagnosticSource/tests/TrimmingTests/System.Diagnostics.DiagnosticSource.TrimmingTests.proj

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/libraries/System.Linq.Expressions/tests/TrimmingTests/System.Linq.Expressions.TrimmingTests.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<Project DefaultTargets="Build">
32
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
43

src/libraries/System.Net.HttpListener/tests/TrimmingTests/System.Net.HttpListener.TrimmingTests.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<Project DefaultTargets="Build">
32
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
43

0 commit comments

Comments
 (0)