From 8221af433eb3b26a7ec88d5454f33a7d4181bf71 Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Fri, 28 Mar 2025 10:58:38 +0100 Subject: [PATCH] Remove WinRT ReflectionHelper dead code --- .../PresentationCore/PresentationCore.csproj | 1 - .../PresentationFramework.csproj | 1 - .../WindowsRuntime/ReflectionHelper.cs | 437 ------------------ 3 files changed, 439 deletions(-) delete mode 100644 src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/WindowsRuntime/ReflectionHelper.cs diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj index 10a8cd48508..5459c397232 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj @@ -84,7 +84,6 @@ - diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index 9e9473e6c93..d71ea445fac 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -53,7 +53,6 @@ - diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/WindowsRuntime/ReflectionHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/WindowsRuntime/ReflectionHelper.cs deleted file mode 100644 index 3447ed98897..00000000000 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/WindowsRuntime/ReflectionHelper.cs +++ /dev/null @@ -1,437 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// -// -// Description: Provides helper methods for invoking methods, accessing fields and properties via reflection -// - -#if WINDOWS_BASE -using MS.Internal.WindowsBase; -#elif PRESENTATION_CORE -using MS.Internal.PresentationCore; -using System; -using System.Reflection; - -#elif PRESENTATIONFRAMEWORK -using MS.Internal.WindowsRuntime; -using System; -using System.Reflection; - -#elif REACHFRAMEWORK -using MS.Internal.ReachFramework; -#else -using MS.Internal; -#endif - - -#if WINDOWS_BASE -namespace MS.Internal.WindowsBase -#elif PRESENTATION_CORE -namespace MS.Internal.PresentationCore -#elif REACHFRAMEWORK -namespace MS.Internal.ReachFramework -#else -namespace MS.Internal -#endif -{ - namespace WindowsRuntime - { - internal static class ReflectionHelper - { - /// - /// Calls method methodName statically from the type type. - /// This function is needed since a static reflection call requires a null object be passed in. - /// - /// - /// - /// - /// - /// type is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - /// The result of the method call cannot be successfully cast to TResult - public static TResult ReflectionStaticCall(this Type type, string methodName) - { - MethodInfo method; - object result; - - method = type.GetMethod(methodName, Type.EmptyTypes); - - if (method == null) - { - throw new MissingMethodException(methodName); - } - - result = method.Invoke(null, null); - - return (TResult)result; - } - - /// - /// Calls method methodName statically from type type. - /// This function is needed since a static reflection call requires a null object to be passed in. - /// - /// - /// - /// - /// - /// - /// - /// type is null - /// methodName is null - /// The invoked method throws an exception - /// The method methodName was not found - /// The caller does not have permission to execute the method - /// The result of the method call cannot be successfully cast to TResult - public static TResult ReflectionStaticCall(this Type type, string methodName, TArg arg) - { - MethodInfo method; - object result; - - method = type.GetMethod(methodName, new Type[] { typeof(TArg) }); - - if (method == null) - { - throw new MissingMethodException(methodName); - } - - result = method.Invoke(null, new object[] { arg }); - - return (TResult)result; - } - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - /// The result of the method call cannot be successfully cast to Result - public static TResult ReflectionCall(this object obj, string methodName) - { - object result = obj.ReflectionCall(methodName); - return (TResult)result; - } - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - public static object ReflectionCall(this object obj, string methodName) - { - MethodInfo method; - object result; - - - method = obj.GetType().GetMethod(methodName, Type.EmptyTypes); - - if (method == null) - { - throw new MissingMethodException(methodName); - } - - result = method.Invoke(obj, null); - - return result; - } - - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - public static object ReflectionCall(this object obj, string methodName, TArg1 arg1) - { - MethodInfo method; - object result; - - method = obj.GetType().GetMethod(methodName, new Type[] { typeof(TArg1) }); - if (method == null) - { - throw new MissingMethodException(methodName); - } - - result = method.Invoke(obj, new object[] { arg1 }); - - return result; - } - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - /// The result of the method call cannot be successfully cast to Result - public static TResult ReflectionCall(this object obj, string methodName, TArg1 arg1) - { - object result = obj.ReflectionCall(methodName, arg1); - return (TResult)result; - } - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - public static object ReflectionCall(this object obj, string methodName, TArg1 arg1, TArg2 arg2) - { - MethodInfo method; - object result; - - method = obj.GetType().GetMethod(methodName, new Type[] { typeof(TArg1), typeof(TArg2) }); - if (method == null) - { - throw new MissingMethodException(methodName); - } - - result = method.Invoke(obj, new object[] { arg1, arg2 }); - - return result; - } - - /// - /// Calls method methodName on object obj - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// obj is null - /// methodName is null - /// The invoked method throws an exception - /// More than one method of the form methodname() was found - /// The method methodName was not found - /// The caller does not have permission to execute the method - /// The result of the method call cannot be successfully cast to Result - public static TResult ReflectionCall(this object obj, string methodName, TArg1 arg1, TArg2 arg2) - { - object result = obj.ReflectionCall(methodName, arg1, arg2); - return (TResult)result; - } - - /// - /// Gets field name fieldName from object obj. Use this method for accessing fields from structs. - /// - /// - /// - /// - /// - /// obj is null - /// fieldName is null - /// The caller does not have permission to acccess this field - /// The Field fieldName was not found - /// The result of the method call cannot be successfully cast to Result - public static TResult ReflectionGetField(this object obj, string fieldName) - { - FieldInfo fieldInfo; - object result; - - fieldInfo = obj.GetType().GetField(fieldName); - if (fieldInfo == null) - { - throw new MissingFieldException(fieldName); - } - - result = fieldInfo.GetValue(obj); - - return (TResult)result; - } - - - /// - /// Calls default constructor for type type and returns an instance - /// - /// - /// null if default constructor doesn't exist - /// type is null - /// The class is abstract, or the constructor is a class initializer - /// The constructor is private or protected, and the caller lacks ReflectionPermissionFlag.MemberAccess/> - /// The invoked constructor throws an exception - /// The caller does not have the necessary code access permission - /// A default constructor does not exist - public static object ReflectionNew(this Type type) - { - ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); - if (constructor == null) - { - string constructorName = $"{type.FullName}.{type.Name}()"; - throw new MissingMethodException(constructorName); - } - - return constructor.Invoke(null); - } - - /// - /// Calls a constructor with one arg of type Arg1 - /// - /// - /// - /// - /// null if a matching constructor can't be found - /// type is null - /// The class is abstract, or the constructor is a class initializer - /// The constructor is private or protected, and the caller lacks ReflectionPermissionFlag.MemberAccess/> - /// The invoked constructor throws an exception - /// The caller does not have the necessary code access permission - /// A default constructor does not exist - public static object ReflectionNew(this Type type, TArg1 arg1) - { - ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(TArg1) }); - if (constructor == null) - { - string constructorName = $"{type.FullName}.{type.Name}({typeof(TArg1).Name})"; - throw new MissingMethodException(constructorName); - } - - return constructor.Invoke(new object[] { arg1 }); - } - - /// - /// Calls a constructor with two args of types Arg1 and Arg2 - /// - /// - /// - /// - /// - /// - /// null if a matching constructor can't be found - /// type is null - /// The class is abstract, or the constructor is a class initializer - /// The constructor is private or protected, and the caller lacks ReflectionPermissionFlag.MemberAccess/> - /// The invoked constructor throws an exception - /// The caller does not have the necessary code access permission - /// A default constructor does not exist - public static object ReflectionNew(this Type type, TArg1 arg1, TArg2 arg2) - { - ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(TArg1), typeof(TArg2) }); - if (constructor == null) - { - string constructorName = $"{type.FullName}.{type.Name}({typeof(TArg1).Name},{typeof(TArg2).Name})"; - throw new MissingMethodException(constructorName); - } - - return constructor.Invoke(new object[] { arg1, arg2 }); - } - - - /// - /// Retrieves the property propertyName from object obj. - /// This is equivalent to calling the method get_propertyName on the object obj - /// - /// - /// - /// - /// - /// More than one property is found with the specified name. See - /// is null - /// does not exist - /// An indexed property was accessed without an index - /// The result of the property access can not be cast to Result type - public static TResult ReflectionGetProperty(this object obj, string propertyName) - { - Type type = obj.GetType(); - PropertyInfo p = type.GetProperty(propertyName); - - if (p == null) - { - throw new MissingMemberException(propertyName); - } - - return (TResult)p.GetValue(obj); - } - - /// - /// Retrieves the property propertyName from object obj. - /// This is equivalent to calling the method get_propertyName on the object obj - /// - /// - /// - /// - /// More than one property is found with the specified name. See - /// is null - /// does not exist - /// An indexed property was accessed without an index - public static object ReflectionGetProperty(this object obj, string propertyName) - { - return obj.ReflectionGetProperty(propertyName); - } - - /// - /// Retrieves the static property propertyName from type type - /// - /// - /// - /// - /// - /// More than one property is found with the specified name. See - /// is null - /// does not exist - /// An indexed property was accessed without an index - public static TResult ReflectionStaticGetProperty(this Type type, string propertyName) - { - PropertyInfo p = type.GetProperty(propertyName, BindingFlags.Static); - if (p == null) - { - throw new MissingMemberException(propertyName); - } - - return (TResult)p.GetValue(null); - } - } - } -} \ No newline at end of file