Replace MemberInfo.cs with the CoreRt version and move to shared partition. (dotnet...
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Wed, 15 Mar 2017 13:40:24 +0000 (06:40 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Mar 2017 13:40:24 +0000 (06:40 -0700)
* Move file verbatim.

* Port over CoreRT style sans reordering.

* Final replacement with CoreRt file.

Commit migrated from https://github.com/dotnet/coreclr/commit/44df0f37ce9e4e4ea63718ba0b4e74d53970037a

src/coreclr/src/mscorlib/Common/NotImplemented.cs [new file with mode: 0644]
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/MemberInfo.cs [moved from src/coreclr/src/mscorlib/src/System/Reflection/MemberInfo.cs with 62% similarity]
src/coreclr/src/mscorlib/src/System/Reflection/MemberInfo.Internal.cs [new file with mode: 0644]

diff --git a/src/coreclr/src/mscorlib/Common/NotImplemented.cs b/src/coreclr/src/mscorlib/Common/NotImplemented.cs
new file mode 100644 (file)
index 0000000..82f4e18
--- /dev/null
@@ -0,0 +1,34 @@
+// 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.
+
+namespace System
+{
+    //
+    // This simple class enables one to throw a NotImplementedException using the following
+    // idiom:
+    //
+    //     throw NotImplemented.ByDesign;
+    //
+    // Used by methods whose intended implementation is to throw a NotImplementedException (typically
+    // virtual methods in public abstract classes that intended to be subclassed by third parties.)
+    //
+    // This makes it distinguishable both from human eyes and CCI from NYI's that truly represent undone work.
+    //
+    internal static class NotImplemented
+    {
+        internal static Exception ByDesign
+        {
+            get
+            {
+                return new NotImplementedException();
+            }
+        }
+
+        internal static Exception ByDesignWithMessage(string message)
+        {
+            return new NotImplementedException(message);
+        }
+    }
+}
+
index 8789ca8..cf14056 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MdConstant.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MdImport.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberFilter.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfo.cs" />
+    <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfo.Internal.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfoSerializationHolder.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberTypes.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodAttributes.cs" />
     <!-- These are files are preprocessed  -->
     <Compile Include="$(CommonPath)\Preprocessed\AssemblyRefs.g.cs" />
     <!-- These files are shared with other framework components and don't live the same folder as the rest of them-->
+    <Compile Include="$(CommonPath)\NotImplemented.cs" />
     <Compile Include="$(CommonPath)\PinnableBufferCache.cs" />
     <!-- Include Internals visible to file in the compilation -->
     <Compile Include="$(BclSourcesRoot)\mscorlib.Friends.cs" />
index 8e211d4..5955180 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs"/>
+    <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
@@ -2,74 +2,49 @@
 // 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;
 using System.Collections.Generic;
-using System.Diagnostics.Contracts;
-using System.Runtime;
-using System.Runtime.InteropServices;
 
 namespace System.Reflection
 {
-    [Serializable]
-    public abstract class MemberInfo : ICustomAttributeProvider
+    public abstract partial class MemberInfo : ICustomAttributeProvider
     {
-        #region Constructor
         protected MemberInfo() { }
-        #endregion
-
-        #region Internal Methods
-        internal virtual bool CacheEquals(object o) { throw new NotImplementedException(); }
-        #endregion
 
-        #region Public Abstract\Virtual Members
         public abstract MemberTypes MemberType { get; }
-
-        public abstract String Name { get; }
-
+        public abstract string Name { get; }
         public abstract Type DeclaringType { get; }
-
         public abstract Type ReflectedType { get; }
 
-        public virtual IEnumerable<CustomAttributeData> CustomAttributes
+        public virtual Module Module
         {
             get
             {
-                return GetCustomAttributesData();
+                // This check is necessary because for some reason, Type adds a new "Module" property that hides the inherited one instead 
+                // of overriding.
+
+                Type type = this as Type;
+                if (type != null)
+                    return type.Module;
+
+                throw NotImplemented.ByDesign;
             }
         }
-        public abstract Object[] GetCustomAttributes(bool inherit);
-
-        public abstract Object[] GetCustomAttributes(Type attributeType, bool inherit);
 
         public abstract bool IsDefined(Type attributeType, bool inherit);
+        public abstract object[] GetCustomAttributes(bool inherit);
+        public abstract object[] GetCustomAttributes(Type attributeType, bool inherit);
 
-        public virtual IList<CustomAttributeData> GetCustomAttributesData()
-        {
-            throw new NotImplementedException();
-        }
+        public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
+        public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
 
         public virtual int MetadataToken { get { throw new InvalidOperationException(); } }
 
-        public virtual Module Module
-        {
-            get
-            {
-                if (this is Type)
-                    return ((Type)this).Module;
-
-                throw new NotImplementedException();
-            }
-        }
-
-
-
-        #endregion
+        public override bool Equals(object obj) => base.Equals(obj);
+        public override int GetHashCode() => base.GetHashCode();
 
         public static bool operator ==(MemberInfo left, MemberInfo right)
         {
-            if (ReferenceEquals(left, right))
+            if (object.ReferenceEquals(left, right))
                 return true;
 
             if ((object)left == null || (object)right == null)
@@ -95,19 +70,6 @@ namespace System.Reflection
             return false;
         }
 
-        public static bool operator !=(MemberInfo left, MemberInfo right)
-        {
-            return !(left == right);
-        }
-
-        public override bool Equals(object obj)
-        {
-            return base.Equals(obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return base.GetHashCode();
-        }
+        public static bool operator !=(MemberInfo left, MemberInfo right) => !(left == right);
     }
 }
diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/MemberInfo.Internal.cs b/src/coreclr/src/mscorlib/src/System/Reflection/MemberInfo.Internal.cs
new file mode 100644 (file)
index 0000000..8e7be56
--- /dev/null
@@ -0,0 +1,11 @@
+// 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.
+
+namespace System.Reflection
+{
+    public abstract partial class MemberInfo
+    {
+        internal virtual bool CacheEquals(object o) { throw new NotImplementedException(); }
+    }
+}