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

Annotate System.Private.Reflection.Core #555

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.Serialization;
using System.Reflection.Runtime.General;
Expand Down Expand Up @@ -121,6 +122,7 @@ public sealed override AssemblyName GetName()
return RuntimeAssemblyName.ToAssemblyName();
}

[RequiresUnreferencedCode("Types might be removed")]
public sealed override Type[] GetForwardedTypes()
{
List<Type> types = new List<Type>();
Expand Down Expand Up @@ -175,6 +177,7 @@ public sealed override Type[] GetForwardedTypes()
/// </summary>
protected abstract IEnumerable<TypeForwardInfo> TypeForwardInfos { get; }

[RequiresUnreferencedCode("Types might be removed")]
private static void AddPublicNestedTypes(Type type, List<Type> types)
{
foreach (Type nestedType in type.GetNestedTypes(BindingFlags.Public))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -152,6 +153,8 @@ public static bool NeedsEscapingInTypeName(this char c)

private static readonly char[] s_charsToEscape = new char[] { '\\', '[', ']', '+', '*', '&', ',' };

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Delegates always generate metadata for the Invoke method")]
public static RuntimeMethodInfo GetInvokeMethod(this RuntimeTypeInfo delegateType)
{
Debug.Assert(delegateType.IsDelegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Reflection.Runtime.General;
using System.Diagnostics.CodeAnalysis;

namespace System.Reflection.Runtime.MethodInfos
{
Expand Down Expand Up @@ -74,15 +75,17 @@ public static Dictionary<MethodBase, CustomMethodInvokerAction> Map
}
);

map.AddMethod(type, nameof(Nullable<int>.GetValueOrDefault), Array.Empty<Type>(),
(object thisObject, object[] args, Type thisType) =>
{
if (thisObject == null)
return RuntimeHelpers.GetUninitializedObject(thisType.GenericTypeArguments[0]);
map.AddMethod(type, nameof(Nullable<int>.GetValueOrDefault), Array.Empty<Type>(), NullableGetValueOrDefault);

return thisObject;
}
);
static object NullableGetValueOrDefault(object thisObject, object[] args,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type thisType)
{
if (thisObject == null)
return RuntimeHelpers.GetUninitializedObject(thisType);

return thisObject;
}

map.AddMethod(type, nameof(Nullable<int>.GetValueOrDefault), new Type[] { theT },
(object thisObject, object[] args, Type thisType) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;

using Internal.Reflection.Core.Execution;
Expand Down Expand Up @@ -45,6 +46,8 @@ private static void AddConstructor(this Dictionary<MethodBase, CustomMethodInvok
map.AddMethod(declaringType, ConstructorInfo.ConstructorName, parameterTypes, action);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "GetConstructor/GetMethod being null is handled and expected.")]
private static void AddMethod(this Dictionary<MethodBase, CustomMethodInvokerAction> map, Type declaringType, string name, Type[] parameterTypes, CustomMethodInvokerAction action)
{
const BindingFlags bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Collections.Generic;
using System.Reflection.Runtime.BindingFlagSupport;
Expand All @@ -10,6 +11,7 @@ namespace System.Reflection.Runtime.TypeInfos
{
internal abstract partial class RuntimeTypeInfo
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public sealed override object InvokeMember(
string name, BindingFlags bindingFlags, Binder binder, object target,
object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Reflection.Runtime.General;
Expand Down Expand Up @@ -185,6 +186,13 @@ public sealed override Type[] GenericTypeArguments
}
}

[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicEvents
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.PublicNestedTypes)]
public sealed override MemberInfo[] GetDefaultMembers()
{
string defaultMemberName = GetDefaultMemberName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public sealed override string ToString()
return _declaringType + "+" + _nestedTypeName.EscapeTypeNameIdentifier();
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "Reflection implementation")]
public sealed override Type ResolveType(Assembly containingAssemblyIfAny, GetTypeOptions getTypeOptions)
{
Expand Down