static CodeTypeDeclarationCollection GenerateMultiTree(string name, SupportedType[] supportedTypes, bool isEvent, bool isType2) { CodeTypeDeclarationCollection types = new CodeTypeDeclarationCollection(); types.AddRange(GenerateTree(name + "F_", supportedTypes, null, isEvent, isType2)); types.AddRange(GenerateTree(name + "_P", null, supportedTypes, isEvent, isType2)); types.AddRange(GenerateTree(name + "FP", supportedTypes, supportedTypes, isEvent, isType2)); return(types); }
static CodeTypeDeclarationCollection GenAllIntrumentedTypeDefs(string name) { CodeTypeDeclarationCollection instrumentedTypes = new CodeTypeDeclarationCollection(); instrumentedTypes.AddRange(GenerateForest(name + "E1", true, false)); instrumentedTypes.AddRange(GenerateForest(name + "I1", false, false)); instrumentedTypes.AddRange(GenerateForest(name + "E2", true, true)); instrumentedTypes.AddRange(GenerateForest(name + "I2", false, true)); return(instrumentedTypes); }
public void Constructor1_Deny_Unrestricted() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(array); coll.CopyTo(array, 0); Assert.AreEqual(1, coll.Add(ctd), "Add"); Assert.AreSame(ctd, coll[0], "this[int]"); coll.AddRange(array); coll.AddRange(coll); Assert.IsTrue(coll.Contains(ctd), "Contains"); Assert.AreEqual(0, coll.IndexOf(ctd), "IndexOf"); coll.Insert(0, ctd); coll.Remove(ctd); }
static CodeTypeDeclarationCollection GenerateForest(string name, bool isEvent, bool isType2) { CodeTypeDeclarationCollection types = new CodeTypeDeclarationCollection(); SupportedType[] tinyTypes = SupportedType.GetSupportedTypes(typeof(string)); SupportedType[] smallTypes = SupportedType.GetSupportedTypes(typeof(string), typeof(string)); SupportedType[] mediumTypes = SupportedType.GetSupportedTypes(typeof(string), typeof(string), typeof(int), typeof(int)); types.AddRange(GenerateMultiTree(name + "T", tinyTypes, isEvent, isType2)); types.AddRange(GenerateMultiTree(name + "S", smallTypes, isEvent, isType2)); types.AddRange(GenerateMultiTree(name + "M", mediumTypes, isEvent, isType2)); types.AddRange(GenerateMultiTree(name + "B", SupportedType.All, isEvent, isType2)); return(types); }
public void AddRange() { CodeTypeDeclaration td1 = new CodeTypeDeclaration(); CodeTypeDeclaration td2 = new CodeTypeDeclaration(); CodeTypeDeclaration td3 = new CodeTypeDeclaration(); CodeTypeDeclarationCollection coll1 = new CodeTypeDeclarationCollection(); coll1.Add(td1); coll1.Add(td2); CodeTypeDeclarationCollection coll2 = new CodeTypeDeclarationCollection(); coll2.Add(td3); coll2.AddRange(coll1); Assert.AreEqual(3, coll2.Count, "#1"); Assert.AreEqual(1, coll2.IndexOf(td1), "#2"); Assert.AreEqual(2, coll2.IndexOf(td2), "#3"); Assert.AreEqual(0, coll2.IndexOf(td3), "#4"); CodeTypeDeclarationCollection coll3 = new CodeTypeDeclarationCollection(); coll3.Add(td3); coll3.AddRange(new CodeTypeDeclaration[] { td1, td2 }); Assert.AreEqual(3, coll2.Count, "#5"); Assert.AreEqual(1, coll2.IndexOf(td1), "#6"); Assert.AreEqual(2, coll2.IndexOf(td2), "#7"); Assert.AreEqual(0, coll2.IndexOf(td3), "#8"); }
private static void SortAsc(CodeTypeDeclarationCollection TypeCollection) { List <CodeTypeDeclaration> codeTypes = new List <CodeTypeDeclaration>(); codeTypes.AddRange(TypeCollection.OfType <CodeTypeDeclaration>().ToArray()); CodeTypeDeclaration generatedType = codeTypes.FirstOrDefault( type => { if (type.UserData[Constants.GENERATED_TYPE] as string != null) { return(true); } return(false); }); if (generatedType != null) { codeTypes.Remove(generatedType); } //Sort Types Ascending By Type Name codeTypes.Sort((a, b) => { return(String.Compare(a.Name, b.Name)); }); TypeCollection.Clear(); TypeCollection.AddRange(codeTypes.ToArray()); if (generatedType != null) { TypeCollection.Add(generatedType); } }
/// <summary> /// Visits a <see cref="CodeTypeDeclarationCollection"/>. /// </summary> /// <param name="codeTypeDeclarationCollection">The <see cref="CodeTypeDeclarationCollection"/> to visit.</param> protected override void VisitCodeTypeDeclarationCollection(CodeTypeDeclarationCollection codeTypeDeclarationCollection) { CodeTypeDeclaration[] sortedTypeDeclarations = codeTypeDeclarationCollection.Cast <CodeTypeDeclaration>().OrderBy(c => c.Name).ToArray(); codeTypeDeclarationCollection.Clear(); codeTypeDeclarationCollection.AddRange(sortedTypeDeclarations); base.VisitCodeTypeDeclarationCollection(codeTypeDeclarationCollection); }
public void AddRange_Self() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); coll.Add(new CodeTypeDeclaration()); Assert.AreEqual(1, coll.Count, "#1"); coll.AddRange(coll); Assert.AreEqual(2, coll.Count, "#2"); }
private CodeTypeDeclarationCollection GenerateClassForParameters(List <ClassParameter> parameters) { var classes = new CodeTypeDeclarationCollection(); foreach (var parameter in parameters) { if (!CodeDomUtils.IsBasicType(parameter.Type) && parameter.ChildProperties != null) { classes.Add(this.CreateParameterClass(parameter)); classes.AddRange(this.GenerateClassForParameters(parameter.ChildProperties)); } } return(classes); }
// CodeTypeDeclarationCollection public void CodeTypeDeclarationCollectionExample() { //<Snippet1> //<Snippet2> // Creates an empty CodeTypeDeclarationCollection. CodeTypeDeclarationCollection collection = new CodeTypeDeclarationCollection(); //</Snippet2> //<Snippet3> // Adds a CodeTypeDeclaration to the collection. collection.Add(new CodeTypeDeclaration("TestType")); //</Snippet3> //<Snippet4> // Adds an array of CodeTypeDeclaration objects to the collection. CodeTypeDeclaration[] declarations = { new CodeTypeDeclaration("TestType1"), new CodeTypeDeclaration("TestType2") }; collection.AddRange(declarations); // Adds a collection of CodeTypeDeclaration objects to the // collection. CodeTypeDeclarationCollection declarationsCollection = new CodeTypeDeclarationCollection(); declarationsCollection.Add(new CodeTypeDeclaration("TestType1")); declarationsCollection.Add(new CodeTypeDeclaration("TestType2")); collection.AddRange(declarationsCollection); //</Snippet4> //<Snippet5> // Tests for the presence of a CodeTypeDeclaration in the // collection, and retrieves its index if it is found. CodeTypeDeclaration testDeclaration = new CodeTypeDeclaration("TestType"); int itemIndex = -1; if (collection.Contains(testDeclaration)) { itemIndex = collection.IndexOf(testDeclaration); } //</Snippet5> //<Snippet6> // Copies the contents of the collection, beginning at index 0, // to the specified CodeTypeDeclaration array. // 'declarations' is a CodeTypeDeclaration array. collection.CopyTo(declarations, 0); //</Snippet6> //<Snippet7> // Retrieves the count of the items in the collection. int collectionCount = collection.Count; //</Snippet7> //<Snippet8> // Inserts a CodeTypeDeclaration at index 0 of the collection. collection.Insert(0, new CodeTypeDeclaration("TestType")); //</Snippet8> //<Snippet9> // Removes the specified CodeTypeDeclaration from the collection. CodeTypeDeclaration declaration = new CodeTypeDeclaration("TestType"); collection.Remove(declaration); //</Snippet9> //<Snippet10> // Removes the CodeTypeDeclaration at index 0. collection.RemoveAt(0); //</Snippet10> //</Snippet1> }
public void AddRange_Null_Collection() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); coll.AddRange((CodeTypeDeclarationCollection)null); }
public void AddRange_Null_Item() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); coll.AddRange(new CodeTypeDeclaration[] { null }); }