Add IsCollectible property to Memberinfo and MethodInfo (#21155)
authorJohn Salem <josalem@microsoft.com>
Thu, 29 Nov 2018 06:34:48 +0000 (22:34 -0800)
committerJan Kotas <jkotas@microsoft.com>
Thu, 29 Nov 2018 06:34:48 +0000 (22:34 -0800)
src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
src/System.Private.CoreLib/shared/System/Type.cs
src/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
src/System.Private.CoreLib/src/System/RuntimeHandles.cs
src/vm/ecalllist.h
src/vm/runtimehandles.cpp
src/vm/runtimehandles.h

index d8a7458..c61198d 100644 (file)
@@ -38,7 +38,7 @@ namespace System.Reflection
 
         public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
         public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
-
+        public virtual bool IsCollectible => true;
         public virtual int MetadataToken { get { throw new InvalidOperationException(); } }
 
         public override bool Equals(object obj) => base.Equals(obj);
index c78d988..8b19fbc 100644 (file)
@@ -102,8 +102,6 @@ namespace System
         public bool IsContextful => IsContextfulImpl();
         protected virtual bool IsContextfulImpl() => false;
 
-        public virtual bool IsCollectible => true;
-
         public virtual bool IsEnum => IsSubclassOf(typeof(Enum));
         public bool IsMarshalByRef => IsMarshalByRefImpl();
         protected virtual bool IsMarshalByRefImpl() => false;
index 7b35cd7..c90d72c 100644 (file)
@@ -68,6 +68,7 @@ namespace System.Reflection
         public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeFieldInfo>(other);
 
         public override Module Module { get { return GetRuntimeModule(); } }
+        public override bool IsCollectible => m_declaringType.IsCollectible;
         #endregion
 
         #region Object Overrides
index d3b0969..68caf30 100644 (file)
@@ -525,6 +525,8 @@ namespace System.Reflection
             }
         }
 
+        public override bool IsCollectible => RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle));
+
         public override MethodInfo GetBaseDefinition()
         {
             if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface)
index 7f118d3..313dcc5 100644 (file)
@@ -220,6 +220,7 @@ namespace System.Reflection
 
         public override Module Module { get { return GetRuntimeModule(); } }
         internal RuntimeModule GetRuntimeModule() { return m_declaringType.GetRuntimeModule(); }
+        public override bool IsCollectible => m_declaringType.IsCollectible;
         #endregion
 
         #region PropertyInfo Overrides
index bb1a010..29b3fe3 100644 (file)
@@ -791,6 +791,10 @@ namespace System
         }
 
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
+        [return: MarshalAs(UnmanagedType.Bool)]
+        internal static extern bool GetIsCollectible(RuntimeMethodHandleInternal handle);
+
+        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
         internal static extern bool IsCAVisibleFromDecoratedType(
             RuntimeTypeHandle attrTypeHandle,
             IRuntimeMethodInfo attrCtor,
index 5ee6173..91ca5e0 100644 (file)
@@ -317,6 +317,7 @@ FCFuncStart(gRuntimeMethodHandle)
     FCFuncElement("_GetCurrentMethod", RuntimeMethodHandle::GetCurrentMethod)
     FCFuncElement("InvokeMethod", RuntimeMethodHandle::InvokeMethod)
     QCFuncElement("GetFunctionPointer", RuntimeMethodHandle::GetFunctionPointer)
+    QCFuncElement("GetIsCollectible", RuntimeMethodHandle::GetIsCollectible)
     FCFuncElement("GetImplAttributes", RuntimeMethodHandle::GetImplAttributes)
     FCFuncElement("GetAttributes", RuntimeMethodHandle::GetAttributes)
     FCFuncElement("GetDeclaringType", RuntimeMethodHandle::GetDeclaringType)
index 722603c..8f2d8ef 100644 (file)
@@ -1732,6 +1732,21 @@ void * QCALLTYPE RuntimeMethodHandle::GetFunctionPointer(MethodDesc * pMethod)
 
     return funcPtr;
 }
+
+BOOL QCALLTYPE RuntimeMethodHandle::GetIsCollectible(MethodDesc * pMethod)
+{
+    QCALL_CONTRACT;
+
+    BOOL isCollectible = FALSE;
+
+    BEGIN_QCALL;
+
+    isCollectible = pMethod->GetLoaderAllocator()->IsCollectible();
+
+    END_QCALL;
+
+    return isCollectible;
+}
     
 FCIMPL1(LPCUTF8, RuntimeMethodHandle::GetUtf8Name, MethodDesc *pMethod) {
     CONTRACTL {
index e1f265d..739eb24 100644 (file)
@@ -313,6 +313,8 @@ public:
     static
     void * QCALLTYPE GetFunctionPointer(MethodDesc * pMethod);
 
+    static BOOL QCALLTYPE GetIsCollectible(MethodDesc * pMethod);
+
     static FCDECL1(INT32, GetAttributes, MethodDesc *pMethod);
     static FCDECL1(INT32, GetImplAttributes, ReflectMethodObject *pMethodUNSAFE);
     static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, MethodDesc *pMethod);