Migrate MethodBase.cs over to the shared partition. (dotnet/coreclr#10202)
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Wed, 15 Mar 2017 22:52:05 +0000 (15:52 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Mar 2017 22:52:05 +0000 (15:52 -0700)
* Replace each member with CoreRt prose.

* Lightup IsConstructedGenericMethod

* Copy over CoreRt MethodBase.cs (this is now just a reordering)

* Move MethodBase.cs verbative over to shared partition.

* AAAAND.... it looks like this exercise exposed a bug in CoreRt.

* Resolved merge conflict

Commit migrated from https://github.com/dotnet/coreclr/commit/450ac8f965586c7b28488b6af16855a383da6278

src/coreclr/src/mscorlib/System.Private.CoreLib.csproj
src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/coreclr/src/mscorlib/shared/System/Reflection/MethodBase.cs [new file with mode: 0644]
src/coreclr/src/mscorlib/src/SR.cs
src/coreclr/src/mscorlib/src/System/Reflection/MethodBase.cs [deleted file]

index 4f60b11..530aedc 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfoSerializationHolder.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberTypes.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodAttributes.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodImplAttributes.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodInfo.cs" />
index a648640..0ceaefd 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/MethodBase.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/MethodBase.cs
new file mode 100644 (file)
index 0000000..0037c74
--- /dev/null
@@ -0,0 +1,86 @@
+// 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.
+
+using System.Globalization;
+using System.Diagnostics;
+
+namespace System.Reflection
+{
+    public abstract partial class MethodBase : MemberInfo
+    {
+        protected MethodBase() { }
+
+        public abstract ParameterInfo[] GetParameters();
+        public abstract MethodAttributes Attributes { get; }
+        public virtual MethodImplAttributes MethodImplementationFlags => GetMethodImplementationFlags();
+        public abstract MethodImplAttributes GetMethodImplementationFlags();
+        public virtual MethodBody GetMethodBody() { throw new InvalidOperationException(); }
+        public virtual CallingConventions CallingConvention => CallingConventions.Standard;
+
+        public bool IsAbstract => (Attributes & MethodAttributes.Abstract) != 0;
+        public bool IsConstructor
+        {
+            get
+            {
+                // To be backward compatible we only return true for instance RTSpecialName ctors.
+                return (this is ConstructorInfo &&
+                        !IsStatic &&
+                        ((Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName));
+            }
+        }
+        public bool IsFinal => (Attributes & MethodAttributes.Final) != 0;
+        public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) != 0;
+        public bool IsSpecialName => (Attributes & MethodAttributes.SpecialName) != 0;
+        public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
+        public bool IsVirtual => (Attributes & MethodAttributes.Virtual) != 0;
+
+        public bool IsAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
+        public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
+        public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
+        public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
+        public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
+        public bool IsPublic => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
+
+        public virtual bool IsConstructedGenericMethod => IsGenericMethod && !IsGenericMethodDefinition;
+        public virtual bool IsGenericMethod => false;
+        public virtual bool IsGenericMethodDefinition => false;
+        public virtual Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
+        public virtual bool ContainsGenericParameters => false;
+
+        [DebuggerHidden]
+        [DebuggerStepThrough]
+        public object Invoke(object obj, object[] parameters) => Invoke(obj, BindingFlags.Default, binder: null, parameters: parameters, culture: null);
+        public abstract object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture);
+
+        public abstract RuntimeMethodHandle MethodHandle { get; }
+
+        public virtual bool IsSecurityCritical { get { throw NotImplemented.ByDesign; } }
+        public virtual bool IsSecuritySafeCritical { get { throw NotImplemented.ByDesign; } }
+        public virtual bool IsSecurityTransparent { get { throw NotImplemented.ByDesign; } }
+
+        public override bool Equals(object obj) => base.Equals(obj);
+        public override int GetHashCode() => base.GetHashCode();
+
+        public static bool operator ==(MethodBase left, MethodBase right)
+        {
+            if (object.ReferenceEquals(left, right))
+                return true;
+
+            if ((object)left == null || (object)right == null)
+                return false;
+
+            MethodInfo method1, method2;
+            ConstructorInfo constructor1, constructor2;
+
+            if ((method1 = left as MethodInfo) != null && (method2 = right as MethodInfo) != null)
+                return method1 == method2;
+            else if ((constructor1 = left as ConstructorInfo) != null && (constructor2 = right as ConstructorInfo) != null)
+                return constructor1 == constructor2;
+
+            return false;
+        }
+
+        public static bool operator !=(MethodBase left, MethodBase right) => !(left == right);
+    }
+}
index 8607c35..17bc05e 100644 (file)
@@ -877,6 +877,12 @@ internal static class SR
         get { return Environment.GetResourceString("Serialization_NonSerType"); }
     }
 
+
+    internal static string NotSupported_SubclassOverride
+    {
+        get { return Environment.GetResourceString("NotSupported_SubclassOverride"); }
+    }
+
     internal static string InvalidCast_IConvertible =>
         Environment.GetResourceString("InvalidCast_IConvertible");
 
diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/MethodBase.cs b/src/coreclr/src/mscorlib/src/System/Reflection/MethodBase.cs
deleted file mode 100644 (file)
index bf254b1..0000000
+++ /dev/null
@@ -1,148 +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.
-
-using System.Diagnostics;
-using System.Globalization;
-
-namespace System.Reflection
-{
-    [Serializable]
-    public abstract partial class MethodBase : MemberInfo
-    {
-        #region Constructor
-        protected MethodBase() { }
-        #endregion
-
-        public static bool operator ==(MethodBase left, MethodBase right)
-        {
-            if (ReferenceEquals(left, right))
-                return true;
-
-            if ((object)left == null || (object)right == null)
-                return false;
-
-            MethodInfo method1, method2;
-            ConstructorInfo constructor1, constructor2;
-
-            if ((method1 = left as MethodInfo) != null && (method2 = right as MethodInfo) != null)
-                return method1 == method2;
-            else if ((constructor1 = left as ConstructorInfo) != null && (constructor2 = right as ConstructorInfo) != null)
-                return constructor1 == constructor2;
-
-            return false;
-        }
-
-        public static bool operator !=(MethodBase left, MethodBase right)
-        {
-            return !(left == right);
-        }
-
-        public override bool Equals(object obj)
-        {
-            return base.Equals(obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return base.GetHashCode();
-        }
-
-        #region Public Abstract\Virtual Members
-        [System.Diagnostics.Contracts.Pure]
-        public abstract ParameterInfo[] GetParameters();
-
-        public virtual MethodImplAttributes MethodImplementationFlags
-        {
-            get
-            {
-                return GetMethodImplementationFlags();
-            }
-        }
-
-        public abstract MethodImplAttributes GetMethodImplementationFlags();
-
-        public abstract RuntimeMethodHandle MethodHandle { get; }
-
-        public abstract MethodAttributes Attributes { get; }
-
-        public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
-
-        public virtual CallingConventions CallingConvention { get { return CallingConventions.Standard; } }
-
-        public virtual Type[] GetGenericArguments() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); }
-
-        public virtual bool IsGenericMethodDefinition { get { return false; } }
-
-        public virtual bool ContainsGenericParameters { get { return false; } }
-
-        public virtual bool IsGenericMethod { get { return false; } }
-
-        public virtual bool IsSecurityCritical { get { throw new NotImplementedException(); } }
-
-        public virtual bool IsSecuritySafeCritical { get { throw new NotImplementedException(); } }
-
-        public virtual bool IsSecurityTransparent { get { throw new NotImplementedException(); } }
-
-        #endregion
-
-        #region Public Members
-        [DebuggerStepThroughAttribute]
-        [Diagnostics.DebuggerHidden]
-        public Object Invoke(Object obj, Object[] parameters)
-        {
-            // Theoretically we should set up a LookForMyCaller stack mark here and pass that along.
-            // But to maintain backward compatibility we can't switch to calling an 
-            // internal overload that takes a stack mark.
-            // Fortunately the stack walker skips all the reflection invocation frames including this one.
-            // So this method will never be returned by the stack walker as the caller.
-            // See SystemDomain::CallersMethodCallbackWithStackMark in AppDomain.cpp.
-            return Invoke(obj, BindingFlags.Default, null, parameters, null);
-        }
-
-        public bool IsPublic { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; } }
-
-        public bool IsPrivate { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; } }
-
-        public bool IsFamily { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; } }
-
-        public bool IsAssembly { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly; } }
-
-        public bool IsFamilyAndAssembly { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; } }
-
-        public bool IsFamilyOrAssembly { get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; } }
-
-        public bool IsStatic { get { return (Attributes & MethodAttributes.Static) != 0; } }
-
-        public bool IsFinal
-        {
-            get { return (Attributes & MethodAttributes.Final) != 0; }
-        }
-        public bool IsVirtual
-        {
-            get { return (Attributes & MethodAttributes.Virtual) != 0; }
-        }
-        public bool IsHideBySig { get { return (Attributes & MethodAttributes.HideBySig) != 0; } }
-
-        public bool IsAbstract { get { return (Attributes & MethodAttributes.Abstract) != 0; } }
-
-        public bool IsSpecialName { get { return (Attributes & MethodAttributes.SpecialName) != 0; } }
-
-        public bool IsConstructor
-        {
-            get
-            {
-                // To be backward compatible we only return true for instance RTSpecialName ctors.
-                return (this is ConstructorInfo &&
-                        !IsStatic &&
-                        ((Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName));
-            }
-        }
-
-        public virtual MethodBody GetMethodBody()
-        {
-            throw new InvalidOperationException();
-        }
-        #endregion
-    }
-}