{
return builder_to_declspace [t] as TypeContainer;
}
+
+ public static TypeContainer LookupGenericTypeContainer (Type t)
+ {
+ while (t.IsGenericInstance)
+ t = t.GetGenericTypeDefinition ();
+
+ return LookupTypeContainer (t);
+ }
public static IMemberContainer LookupMemberContainer (Type t)
{
}
public static bool HasConstructorConstraint (Type t)
+ {
+ GenericConstraints gc = GetTypeParameterConstraints (t);
+ if (gc == null)
+ return false;
+
+ return (gc.Attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0;
+ }
+
+ public static GenericConstraints GetTypeParameterConstraints (Type t)
{
if (!t.IsGenericParameter)
throw new InvalidOperationException ();
TypeParameter tparam = LookupTypeParameter (t);
if (tparam != null)
- return tparam.HasConstructorConstraint;
- else {
- object[] attrs = t.GetCustomAttributes (
- TypeManager.new_constraint_attr_type, false);
+ return tparam.GenericConstraints;
- return attrs.Length > 0;
- }
+ return new ReflectionConstraints (t);
}
/// <summary>
return tc.Kind == Kind.Interface;
}
- public static bool IsEqualGenericType (Type a, Type b)
+ public static bool IsEqual (Type a, Type b)
{
+ if (a.Equals (b))
+ return true;
+
if ((a is TypeBuilder) && a.IsGenericTypeDefinition && b.IsGenericInstance) {
//
// `a' is a generic type definition's TypeBuilder and `b' is a
// The first argument of `Test' will be the generic instance
// "Stack<!0>" - which is the same type than the "Stack" TypeBuilder.
//
+ //
+ // We hit this via Closure.Filter() for gen-82.cs.
+ //
if (a != b.GetGenericTypeDefinition ())
return false;
return false;
for (int i = 0; i < aparams.Length; i++)
- if (!aparams [i].Equals (bparams [i]))
+ if (!IsEqual (aparams [i], bparams [i]))
return false;
return true;
}
- return false;
- }
+ if (a.IsGenericParameter && b.IsGenericParameter) {
+ if ((a.DeclaringMethod == null) || (b.DeclaringMethod == null))
+ return false;
+ return a.GenericParameterPosition == b.GenericParameterPosition;
+ }
+
+ if (a.IsArray && b.IsArray) {
+ if (a.GetArrayRank () != b.GetArrayRank ())
+ return false;
+ return IsEqual (a.GetElementType (), b.GetElementType ());
+ }
+
+ if (a.IsGenericInstance && b.IsGenericInstance) {
+ Type at = a.GetGenericTypeDefinition ();
+ Type bt = b.GetGenericTypeDefinition ();
+
+ if (a.GetGenericTypeDefinition () != b.GetGenericTypeDefinition ())
+ return false;
+
+ Type[] aargs = a.GetGenericArguments ();
+ Type[] bargs = b.GetGenericArguments ();
+
+ if (aargs.Length != bargs.Length)
+ return false;
+
+ for (int i = 0; i < aargs.Length; i++) {
+ if (!IsEqual (aargs [i], bargs [i]))
+ return false;
+ }
- public static bool IsEqual (Type a, Type b)
- {
- if (a.Equals (b))
return true;
- else
- return IsEqualGenericType (a, b);
+ }
+
+ return false;
}
public static bool MayBecomeEqualGenericTypes (Type a, Type b)
static Closure closure = new Closure ();
static MemberFilter FilterWithClosure_delegate = new MemberFilter (closure.Filter);
- static MemberFilter FilterNone_delegate = new MemberFilter (FilterNone);
//
// Looks up a member called `name' in the `queried_type'. This lookup
return null;
}
- //
- // This is used to extract properties and event declarations from a type
- //
- static MemberInfo [] SpecialContainerLookup (Type t, bool is_static)
- {
- BindingFlags bf = BindingFlags.DeclaredOnly | (is_static ? BindingFlags.Static : BindingFlags.Instance);
-
- bf |= BindingFlags.Public | BindingFlags.NonPublic;
-
- if (t is TypeBuilder) {
- DeclSpace decl = (DeclSpace) builder_to_declspace [t];
-
- return (MemberInfo []) decl.FindMembers (
- MemberTypes.Property | MemberTypes.Event,
- bf, FilterNone_delegate, null);
- } else {
- return t.FindMembers (MemberTypes.Property | MemberTypes.Event,
- bf, FilterNone_delegate, null);
-
- }
- }
-
+ // Tests whether external method is really special
public static bool IsSpecialMethod (MethodBase mb)
{
- Type t = mb.DeclaringType;
-
- MemberInfo [] matches = TypeManager.SpecialContainerLookup (t, mb.IsStatic);
- if (matches == null)
- return false;
-
- foreach (MemberInfo mi in matches){
- if (mi is PropertyBuilder){
- Pair p = (Pair) properties [mi];
-
- if (p.First == mb || p.Second == mb)
- return true;
- } else if (mi is PropertyInfo){
- MethodInfo [] methods = ((PropertyInfo) mi).GetAccessors (true);
-
- foreach (MethodInfo m in methods){
- if (m == mb)
- return true;
- }
- } else if (mi is MyEventBuilder){
- Pair p = (Pair) events [mi];
-
- if (p.First == mb || p.Second == mb)
- return true;
- } else if (mi is EventInfo){
- EventInfo ei = ((EventInfo) mi);
-
- if (ei.GetAddMethod (true) == mb)
- return true;
-
- if (ei.GetRemoveMethod (true) == mb)
- return true;
+ string name = mb.Name;
+ if (name.StartsWith ("get_") || name.StartsWith ("set_"))
+ return mb.DeclaringType.GetProperty (name.Substring (4)) != null;
- if (ei.GetRaiseMethod (true) == mb)
- return true;
- }
- }
+ if (name.StartsWith ("add_"))
+ return mb.DeclaringType.GetEvent (name.Substring (4)) != null;
- //
- // Now check if it is an operator method
- //
- string s = mb.Name;
+ if (name.StartsWith ("remove_"))
+ return mb.DeclaringType.GetEvent (name.Substring (7)) != null;
- if (s.StartsWith ("op_")){
- foreach (string name in Unary.oper_names){
- if (s == name)
+ if (name.StartsWith ("op_")){
+ foreach (string oname in Unary.oper_names) {
+ if (oname == name)
return true;
}
- foreach (string name in Binary.oper_names){
- if (s == name)
+ foreach (string oname in Binary.oper_names) {
+ if (oname == name)
return true;
}
}
-
return false;
}