+ /// <summary>
+ /// This is used to construct the `this' type inside a generic type definition.
+ /// </summary>
+ public ConstructedType (Type t, TypeParameter[] type_params, Location l)
+ : this (type_params, l)
+ {
+ gt = t.GetGenericTypeDefinition ();
+
+ this.name = new TypeExpression (gt, l);
+ full_name = gt.FullName + "<" + args.ToString () + ">";
+ }
+
+ /// <summary>
+ /// Instantiate the generic type `t' with the type arguments `args'.
+ /// Use this constructor if you already know the fully resolved
+ /// generic type.
+ /// </summary>
+ public ConstructedType (Type t, TypeArguments args, Location l)
+ : this (args, l)
+ {
+ gt = t.GetGenericTypeDefinition ();
+
+ this.name = new TypeExpression (gt, l);
+ full_name = gt.FullName + "<" + args.ToString () + ">";
+ }
+
+ public TypeArguments TypeArguments {
+ get { return args; }
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return TypeManager.CSharpName (gt);
+ }
+
+ protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ {
+ if (!ResolveConstructedType (ec))
+ return null;
+
+ return this;
+ }
+
+ /// <summary>
+ /// Check the constraints; we're called from ResolveAsTypeTerminal()
+ /// after fully resolving the constructed type.
+ /// </summary>
+ public bool CheckConstraints (EmitContext ec)
+ {
+ return ConstraintChecker.CheckConstraints (ec, gt, gen_params, atypes, loc);
+ }
+
+ /// <summary>
+ /// Resolve the constructed type, but don't check the constraints.
+ /// </summary>
+ public bool ResolveConstructedType (EmitContext ec)
+ {
+ if (type != null)
+ return true;
+ // If we already know the fully resolved generic type.
+ if (gt != null)
+ return DoResolveType (ec);
+
+ int num_args;
+ Type t = name.Type;
+
+ if (t == null) {
+ Report.Error (246, loc, "Cannot find type `{0}'<...>", Name);
+ return false;
+ }
+
+ num_args = TypeManager.GetNumberOfTypeArguments (t);
+ if (num_args == 0) {
+ Report.Error (308, loc,
+ "The non-generic type `{0}' cannot " +
+ "be used with type arguments.",
+ TypeManager.CSharpName (t));
+ return false;
+ }
+
+ gt = t.GetGenericTypeDefinition ();
+ return DoResolveType (ec);
+ }
+
+ bool DoResolveType (EmitContext ec)
+ {
+ //
+ // Resolve the arguments.
+ //
+ if (args.Resolve (ec) == false)
+ return false;
+
+ gen_params = gt.GetGenericArguments ();
+ atypes = args.Arguments;
+
+ if (atypes.Length != gen_params.Length) {
+ Report.Error (305, loc,
+ "Using the generic type `{0}' " +
+ "requires {1} type arguments",
+ TypeManager.CSharpName (gt),
+ gen_params.Length.ToString ());
+ return false;
+ }
+
+ //
+ // Now bind the parameters.
+ //
+ type = gt.MakeGenericType (atypes);
+ return true;
+ }
+
+ public Expression GetSimpleName (EmitContext ec)
+ {
+ return this;
+ }
+
+ public override bool CheckAccessLevel (DeclSpace ds)
+ {
+ return ds.CheckAccessLevel (gt);
+ }
+
+ public override bool AsAccessible (DeclSpace ds, int flags)
+ {
+ return ds.AsAccessible (gt, flags);
+ }
+
+ public override bool IsClass {
+ get { return gt.IsClass; }
+ }
+
+ public override bool IsValueType {
+ get { return gt.IsValueType; }
+ }
+
+ public override bool IsInterface {
+ get { return gt.IsInterface; }
+ }
+
+ public override bool IsSealed {
+ get { return gt.IsSealed; }