[mono/mono] e7db8e89: [Mono.Debugger.Soft] Implemented inheritance for TypeMirror.GetCustomAttributes()

"Jeffrey Stedfast ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001420adfbdb3-9b358df3-6650-4610-a07c-5b5c4dc0aa07-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/599a21d6aeba...e7db8e896a18

   Commit: e7db8e896a180e5112d8152dbd9b09093f26a390
   Author: Jeffrey Stedfast <[email protected]> (jstedfast)
     Date: 2013-10-30 19:36:24 GMT
      URL: https://github.com/mono/mono/commit/e7db8e896a180e5112d8152dbd9b09093f26a390

[Mono.Debugger.Soft] Implemented inheritance for TypeMirror.GetCustomAttributes()

Fixes bug #15320

Changed paths:
  M mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs

Modified: mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
===================================================================
@@ -26,6 +26,7 @@ public class TypeMirror : Mirror
 		TypeMirror[] ifaces;
 		Dictionary<TypeMirror, InterfaceMappingMirror> iface_map;
 		TypeMirror[] type_args;
+		bool cached_base_type;
 		bool inited;
 
 		internal const BindingFlags DefaultBindingFlags =
@@ -78,9 +79,9 @@ public class TypeMirror : Mirror
 
 		public TypeMirror BaseType {
 			get {
-				// FIXME: base_type could be null for object/interfaces
-				if (base_type == null) {
+				if (!cached_base_type) {
 					base_type = vm.GetType (GetInfo ().base_type);
+					cached_base_type = true;
 				}
 				return base_type;
 			}
@@ -591,11 +592,11 @@ public TypeMirror[] GetNestedTypes ()
 
 		string[] source_files;
 		string[] source_files_full_path;
-		public string[] GetSourceFiles (bool return_full_paths) {
-			string[] res = return_full_paths ? source_files_full_path : source_files;
+		public string[] GetSourceFiles (bool returnFullPaths) {
+			string[] res = returnFullPaths ? source_files_full_path : source_files;
 			if (res == null) {
-				res = vm.conn.Type_GetSourceFiles (id, return_full_paths);
-				if (return_full_paths)
+				res = vm.conn.Type_GetSourceFiles (id, returnFullPaths);
+				if (returnFullPaths)
 					source_files_full_path = res;
 				else
 					source_files = res;
@@ -684,29 +685,38 @@ protected virtual bool IsMarshalByRefImpl ()
 		 * used by the reflection-only functionality on .net.
 		 */
 		public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
-			return GetCAttrs (null, inherit);
+			return GetCustomAttrs (null, inherit);
 		}
 
 		public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
 			if (attributeType == null)
 				throw new ArgumentNullException ("attributeType");
-			return GetCAttrs (attributeType, inherit);
+			return GetCustomAttrs (attributeType, inherit);
 		}
 
-		CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
+		void AppendCustomAttrs (IList<CustomAttributeDataMirror> attrs, TypeMirror type, bool inherit)
+		{
 			if (cattrs == null && Metadata != null && !Metadata.HasCustomAttributes)
 				cattrs = new CustomAttributeDataMirror [0];
 
-			// FIXME: Handle inherit
 			if (cattrs == null) {
 				CattrInfo[] info = vm.conn.Type_GetCustomAttributes (id, 0, false);
 				cattrs = CustomAttributeDataMirror.Create (vm, info);
 			}
-			var res = new List<CustomAttributeDataMirror> ();
-			foreach (var attr in cattrs)
+
+			foreach (var attr in cattrs) {
 				if (type == null || attr.Constructor.DeclaringType == type)
-					res.Add (attr);
-			return res.ToArray ();
+					attrs.Add (attr);
+			}
+
+			if (inherit && BaseType != null)
+				BaseType.AppendCustomAttrs (attrs, type, inherit);
+		}
+
+		CustomAttributeDataMirror[] GetCustomAttrs (TypeMirror type, bool inherit) {
+			var attrs = new List<CustomAttributeDataMirror> ();
+			AppendCustomAttrs (attrs, type, inherit);
+			return attrs.ToArray ();
 		}
 
 		public MethodMirror[] GetMethodsByNameFlags (string name, BindingFlags flags, bool ignoreCase) {


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.