Add() public method

public Add ( CodeTypeReference value ) : int
value CodeTypeReference
return int
 public static CodeTypeReferenceCollection Clone(this CodeTypeReferenceCollection collection)
 {
     if (collection == null) return null;
     CodeTypeReferenceCollection c = new CodeTypeReferenceCollection();
     foreach (CodeTypeReference reference in collection)
         c.Add(reference.Clone());
     return c;
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (ctr), "Add");
			Assert.AreSame (ctr, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (ctr), "Contains");
			Assert.AreEqual (0, coll.IndexOf (ctr), "IndexOf");
			coll.Insert (0, ctr);
			coll.Remove (ctr);
		}
Example #3
0
	public void interf_declr(
		CodeTypeReferenceCollection baseTypes
	) //throws RecognitionException, TokenStreamException
{

		returnAST = null;
		ASTPair currentAST = new ASTPair();
		AST interf_declr_AST = null;
		AST name_AST = null;

		try {      // for error handling
			{
				switch ( LA(1) )
				{
				case LITERAL_interface:
				{
					AST tmp52_AST = null;
					tmp52_AST = astFactory.create(LT(1));
					astFactory.makeASTRoot(ref currentAST, tmp52_AST);
					match(LITERAL_interface);
					break;
				}
				case LITERAL_dispinterface:
				{
					AST tmp53_AST = null;
					tmp53_AST = astFactory.create(LT(1));
					astFactory.makeASTRoot(ref currentAST, tmp53_AST);
					match(LITERAL_dispinterface);
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			identifier();
			if (0 == inputState.guessing)
			{
				name_AST = (AST)returnAST;
				astFactory.addASTChild(ref currentAST, returnAST);
			}
			if (0==inputState.guessing)
			{

						baseTypes.Add(name_AST.getText());

			}
			interf_declr_AST = currentAST.root;
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex);
				recover(ex,tokenSet_11_);
			}
			else
			{
				throw ex;
			}
		}
		returnAST = interf_declr_AST;
	}
 protected void Rewrite(CodeTypeReferenceCollection target, CodeTypeReferenceCollection source, ref bool didRewrite)
 {
     foreach (CodeTypeReference item in source)
     {
         target.Add(this.Rewrite(item, ref didRewrite));
     }
 }
		public void Constructor2 () 
		{
			CodeTypeReference ref1 = new CodeTypeReference (string.Empty);
			CodeTypeReference ref2 = new CodeTypeReference (string.Empty);

			CodeTypeReferenceCollection c = new CodeTypeReferenceCollection ();
			c.Add (ref1);
			c.Add (ref2);

			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ref1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ref2), "#3");
		}
		public void Remove ()
		{
			CodeTypeReference ctr1 = new CodeTypeReference (string.Empty);
			CodeTypeReference ctr2 = new CodeTypeReference (string.Empty);

			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection ();
			coll.Add (ctr1);
			coll.Add (ctr2);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ctr1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ctr2), "#3");
			coll.Remove (ctr1);
			Assert.AreEqual (1, coll.Count, "#4");
			Assert.AreEqual (-1, coll.IndexOf (ctr1), "#5");
			Assert.AreEqual (0, coll.IndexOf (ctr2), "#6");
		}
		public void AddRange_Self ()
		{
			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection ();
			coll.Add (new CodeTypeReference (string.Empty));
			Assert.AreEqual (1, coll.Count, "#1");
			coll.AddRange (coll);
			Assert.AreEqual (2, coll.Count, "#2");
		}
		public void AddRange () 
		{
			CodeTypeReference ref1 = new CodeTypeReference (string.Empty);
			CodeTypeReference ref2 = new CodeTypeReference (string.Empty);
			CodeTypeReference ref3 = new CodeTypeReference (string.Empty);

			CodeTypeReferenceCollection coll1 = new CodeTypeReferenceCollection ();
			coll1.Add (ref1);
			coll1.Add (ref2);

			CodeTypeReferenceCollection coll2 = new CodeTypeReferenceCollection ();
			coll2.Add (ref3);
			coll2.AddRange (coll1);
			Assert.AreEqual (3, coll2.Count, "#1");
			Assert.AreEqual (1, coll2.IndexOf (ref1), "#2");
			Assert.AreEqual (2, coll2.IndexOf (ref2), "#3");
			Assert.AreEqual (0, coll2.IndexOf (ref3), "#4");

			CodeTypeReferenceCollection coll3 = new CodeTypeReferenceCollection ();
			coll3.Add (ref3);
			coll3.AddRange (new CodeTypeReference[] { ref1, ref2 });
			Assert.AreEqual (3, coll2.Count, "#5");
			Assert.AreEqual (1, coll2.IndexOf (ref1), "#6");
			Assert.AreEqual (2, coll2.IndexOf (ref2), "#7");
			Assert.AreEqual (0, coll2.IndexOf (ref3), "#8");
		}
		public void Insert () 
		{
			CodeTypeReference ref1 = new CodeTypeReference (string.Empty);
			CodeTypeReference ref2 = new CodeTypeReference (string.Empty);

			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection ();
			coll.Add (ref1);
			Assert.AreEqual (1, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ref1), "#2");
			coll.Insert (0, ref2);
			Assert.AreEqual (2, coll.Count, "#3");
			Assert.AreEqual (1, coll.IndexOf (ref1), "#4");
			Assert.AreEqual (0, coll.IndexOf (ref2), "#5");
		}
		public void Add_Null () 
		{
			CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection ();
			coll.Add ((CodeTypeReference) null);
		}
Example #11
0
        private CodeTypeReferenceCollection GetCodeTypeReferenceInCodeStatement(CodeStatement statement)
        {
            CodeTypeReferenceCollection references = new CodeTypeReferenceCollection();

            // Is this a variable declaration statement?
            if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
            {
                // Add CodeTypeReference used to define the type of the variable to output.
                CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
                references.Add(vdeclStatement.Type);

                // Do we have an initialization expression?
                if (vdeclStatement.InitExpression != null)
                {
                    // Add CodeTypeReference in the initialization statement if available.
                    CodeTypeReference r = GetCodeTypeReferenceInCodeExpression(vdeclStatement.InitExpression);
                    Debug.Assert(r != null, "Could not obtain a proper CodeTypeReference from the variable initialization expression.");
                    if (r == null)
                    {
                        Debugger.Break();
                    }
                    references.Add(r);
                }
            }
            //// Is this a return statement?
            //else if (typeof(CodeMethodReturnStatement) == statement.GetType())
            //{
            //    CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
            //    // Add CodeTypeReference in the return statement if available.
            //    CodeTypeReference r = GetCodeTypeReferenceInCodeExpression(retStatement.Expression);
            //    Debug.Assert(r != null, "Could not obtain a proper CodeTypeReference from the variable initialization expression.");
            //    references.Add(r);
            //}

            // Finally return the references.
            return references;
        }
		protected virtual void AddPageBaseTypes (CodeTypeReferenceCollection baseTypes)
		{

			baseTypes.Add (PageBaseClass);
			baseTypes.Add (typeof(System.Web.IHttpHandler));

			switch (parser.EnableSessionState) {
			case PagesEnableSessionState.ReadOnly:
				baseTypes.Add (typeof(IReadOnlySessionState));
				break;
			case PagesEnableSessionState.True:
				baseTypes.Add (typeof(IRequiresSessionState));
				break;
			}
		}
Example #13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Declares the co class object.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="attributes">The attributes.</param>
        /// <returns>The type declaration for the CoClass object. The CoClass object gets
        /// named after the interface it implements with a leading underscore and "Class"
        /// appended.</returns>
        /// ------------------------------------------------------------------------------------
        public CodeTypeDeclaration DeclareCoClassObject(CodeTypeDeclaration type,
			CodeNamespace nameSpace, IDictionary attributes)
        {
            string coClassName = GetCoClassObjectName(type);
            CodeTypeDeclaration coClass = new CodeTypeDeclaration(coClassName);
            coClass.IsClass = true;
            coClass.TypeAttributes = TypeAttributes.NestedAssembly;
            coClass.CustomAttributes.Add(new CodeAttributeDeclaration("ComImport"));
            coClass.CustomAttributes.Add(new CodeAttributeDeclaration("ClassInterface",
                new CodeAttributeArgument(new CodeSnippetExpression("ClassInterfaceType.None"))));
            coClass.CustomAttributes.Add(new CodeAttributeDeclaration("TypeLibType",
                new CodeAttributeArgument(new CodeSnippetExpression("TypeLibTypeFlags.FCanCreate"))));
            coClass.BaseTypes.Add(type.BaseTypes[0]);
            coClass.BaseTypes.Add(new CodeTypeReference(type.Name));

            // Prepare to remove redundant superclasses
            CodeTypeReferenceCollection bases = new CodeTypeReferenceCollection();
            Dictionary<string, StringCollection> allBases = new Dictionary<string, StringCollection>();
            foreach (CodeTypeReference baseType in type.BaseTypes)
                allBases[baseType.BaseType] = AllBases(baseType.BaseType, nameSpace);
            foreach (CodeTypeReference baseType in type.BaseTypes)
            {
                bool fRedundant = false;
                foreach (CodeTypeReference other in type.BaseTypes)
                {
                    // Is this base class contained in another?
                    if (other != baseType && allBases[other.BaseType].Contains(baseType.BaseType))
                    {
                        fRedundant = true;
                        break;
                    }
                }
                if (!fRedundant)
                    bases.Add(baseType);
            }

            string interfaceType;
            foreach (CodeTypeReference baseType in bases)
            {
                CodeTypeMemberCollection tmpColl = GetBaseMembers(baseType.BaseType, nameSpace,
                    out interfaceType);
                if (tmpColl != null)
                {
                    // adjust attributes
                    foreach (CodeTypeMember member in tmpColl)
                    {
                        //member.Attributes &= ~MemberAttributes.New;
                        member.Attributes = MemberAttributes.Public;
                        member.UserData.Add("extern", true);

                        AddMethodImplAttr(member, false);
                    }

                    tmpColl.AddRange(coClass.Members);
                    coClass.Members.Clear();
                    coClass.Members.AddRange(tmpColl);
                }
            }

            // Add a region around this class
            coClass.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start,
                "Private " + coClassName + " class"));
            coClass.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, coClassName));

            AddAttributesToType(coClass, attributes);

            return coClass;
        }