Răsfoiți Sursa

2004-08-24 Martin Baulig <[email protected]>

	* generic.cs (TypeParameter.IsSubclassOf): New public method.
	(Constraints.IsSubclassOf): New internal method.

	* typemanager.cs (TypeManager.FindMembers): Added special support
	for GenericTypeParameterBuilder's.
	(TypeManager.IsSubclassOf, IsFamilyAccessible): Added support for
	type parameters.

svn path=/trunk/mcs/; revision=32784
Martin Baulig 21 ani în urmă
părinte
comite
cc34444241
3 a modificat fișierele cu 68 adăugiri și 0 ștergeri
  1. 10 0
      mcs/gmcs/ChangeLog
  2. 28 0
      mcs/gmcs/generic.cs
  3. 30 0
      mcs/gmcs/typemanager.cs

+ 10 - 0
mcs/gmcs/ChangeLog

@@ -1,3 +1,13 @@
+2004-08-24  Martin Baulig  <[email protected]>
+
+	* generic.cs (TypeParameter.IsSubclassOf): New public method.
+	(Constraints.IsSubclassOf): New internal method.
+
+	* typemanager.cs (TypeManager.FindMembers): Added special support
+	for GenericTypeParameterBuilder's.	
+	(TypeManager.IsSubclassOf, IsFamilyAccessible): Added support for
+	type parameters.
+
 2004-08-24  Martin Baulig  <[email protected]>
 
 	* typemanager.cs

+ 28 - 0
mcs/gmcs/generic.cs

@@ -334,6 +334,23 @@ namespace Mono.CSharp {
 		Type[] GenericConstraints.InterfaceConstraints {
 			get { return iface_constraint_types; }
 		}
+
+		internal bool IsSubclassOf (Type t)
+		{
+			if ((class_constraint_type != null) &&
+			    class_constraint_type.IsSubclassOf (t))
+				return true;
+
+			if (iface_constraint_types == null)
+				return false;
+
+			foreach (Type iface in iface_constraint_types) {
+				if (TypeManager.IsSubclassOf (iface, t))
+					return true;
+			}
+
+			return false;
+		}
 	}
 
 	//
@@ -476,6 +493,17 @@ namespace Mono.CSharp {
 			return new MemberList (members);
 		}
 
+		public bool IsSubclassOf (Type t)
+		{
+			if (type.Equals (t))
+				return true;
+
+			if (constraints != null)
+				return constraints.IsSubclassOf (t);
+
+			return false;
+		}
+
 		public override string ToString ()
 		{
 			return "TypeParameter[" + name + "]";

+ 30 - 0
mcs/gmcs/typemanager.cs

@@ -1430,6 +1430,16 @@ public class TypeManager {
 		if (t.IsSubclassOf (TypeManager.array_type))
 			return new MemberList (TypeManager.array_type.FindMembers (mt, bf, filter, criteria));
 
+		if (t is GenericTypeParameterBuilder) {
+			TypeParameter tparam = (TypeParameter) builder_to_type_param [t];
+
+			Timer.StartTimer (TimerType.FindMembers);
+			MemberList list = tparam.FindMembers (
+				mt, bf | BindingFlags.DeclaredOnly, filter, criteria);
+			Timer.StopTimer (TimerType.FindMembers);
+			return list;
+		}
+
 		//
 		// Since FindMembers will not lookup both static and instance
 		// members, we emulate this behaviour here.
@@ -1870,6 +1880,16 @@ public class TypeManager {
 
 	public static bool IsSubclassOf (Type type, Type parent)
 	{
+		TypeParameter tparam = LookupTypeParameter (type);
+		TypeParameter pparam = LookupTypeParameter (parent);
+
+		if ((tparam != null) && (pparam != null)) {
+			if (tparam == pparam)
+				return true;
+
+			return tparam.IsSubclassOf (parent);
+		}
+
 		do {
 			if (type.Equals (parent))
 				return true;
@@ -1882,6 +1902,16 @@ public class TypeManager {
 
 	public static bool IsFamilyAccessible (Type type, Type parent)
 	{
+		TypeParameter tparam = LookupTypeParameter (type);
+		TypeParameter pparam = LookupTypeParameter (parent);
+
+		if ((tparam != null) && (pparam != null)) {
+			if (tparam == pparam)
+				return true;
+
+			return tparam.IsSubclassOf (parent);
+		}
+
 		do {
 			if (IsEqualGenericInstance (type, parent))
 				return true;