public void ReadMobDataFromJson() { var unit = new CodeCompileUnit(); unit.Namespaces.Add(new CodeNamespace { Imports = { new CodeNamespaceImport("MiNET.Entities.Behaviors") } }); var ns = new CodeNamespace("MiNET.Generated"); ns.Comments.Add(new CodeCommentStatement("Types generated from bedrock component JSON")); unit.Namespaces.Add(ns); var files = Directory.EnumerateFileSystemEntries(@"D:\Downloads\bedrock-server-1.11.4.2\behavior_packs\vanilla\entities\", "*.json"); foreach (var file in files) { CreateEntity(ns, file); } CodeTypeDeclarationCollection types = ns.Types; CodeTypeDeclaration[] t = new CodeTypeDeclaration[types.Count]; types.CopyTo(t, 0); ns.Types.Clear(); var g = t.GroupBy(ctd => ctd.Name); foreach (var gg in g) { ns.Types.Add(gg.First()); } GenerateCSharpCode(unit); }
static CodeTypeDeclaration[] _ToArray(CodeTypeDeclarationCollection refs) { var result = new CodeTypeDeclaration[refs.Count]; refs.CopyTo(result, 0); return(result); }
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); }
// 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> }