+ //
+ // Special version used during type definition
+ //
+ public bool AddInterfaceDefined (TypeSpec iface)
+ {
+ if (!AddInterface (iface))
+ return false;
+
+ //
+ // We can get into a situation where a type is inflated before
+ // its interfaces are resoved. Consider this situation
+ //
+ // class A<T> : X<A<int>>, IFoo {}
+ //
+ // When resolving base class of X`1 we inflate context type A`1
+ // All this happens before we even hit IFoo resolve. Without
+ // additional expansion any inside usage of A<T> would miss IFoo
+ // interface because it comes from early inflated TypeSpec
+ //
+ if (inflated_instances != null) {
+ foreach (var inflated in inflated_instances) {
+ inflated.Value.AddInterface (iface);
+ }
+ }
+
+ return true;
+ }
+
+ //
+ // Returns all type arguments, usefull for nested types
+ //
+ public static TypeSpec[] GetAllTypeArguments (TypeSpec type)
+ {
+ IList<TypeSpec> targs = TypeSpec.EmptyTypes;
+
+ do {
+ if (type.Arity > 0) {
+ if (targs.Count == 0) {
+ targs = type.TypeArguments;
+ } else {
+ var list = targs as List<TypeSpec> ?? new List<TypeSpec> (targs);
+ list.AddRange (type.TypeArguments);
+ targs = list;
+ }
+ }
+
+ type = type.declaringType;
+ } while (type != null);
+
+ return targs as TypeSpec[] ?? ((List<TypeSpec>) targs).ToArray ();
+ }
+