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"); }
/// <summary> /// Core conversion routine. All code should just go through this /// </summary> /// <param name="bag"></param> /// <param name="ep"></param> /// <returns></returns> /// <remarks></remarks> private CodeTypeDeclarationCollection ConvertBagToCodeDom(NativeSymbolBag bag, ErrorProvider ep) { ThrowIfNull(bag); ThrowIfNull(ep); // Make sure than all of the referenced NativeDefinedType instances are in the correct // portion of the bag ChaseReferencedDefinedTypes(bag); // First step is to resolve the symbols bag.TryResolveSymbolsAndValues(ep); // Create the codedom transform CodeTransform transform = new CodeTransform(LanguageType, bag); MarshalTransform marshalUtil = new MarshalTransform(LanguageType, bag, TransformKindFlags); CodeTypeDeclarationCollection col = new CodeTypeDeclarationCollection(); // Only output the constants if there are actually any List <NativeConstant> list = new List <NativeConstant>(bag.FindResolvedConstants()); if (list.Count > 0) { CodeTypeDeclaration constCtd = transform.GenerateConstants(list); if (constCtd.Members.Count > 0) { col.Add(constCtd); } } foreach (NativeDefinedType definedNt in bag.FindResolvedDefinedTypes()) { CodeTypeDeclaration ctd = transform.GenerateDeclaration(definedNt); marshalUtil.Process(ctd); col.Add(ctd); } List <NativeProcedure> procList = new List <NativeProcedure>(bag.FindResolvedProcedures()); if (procList.Count > 0) { CodeTypeDeclaration procType = transform.GenerateProcedures(procList); marshalUtil.Process(procType); col.Add(procType); } // Add the helper types that we need AddHelperTypes(col); // Next step is to run the pretty lister on it CodeDomPrettyList prettyLister = new CodeDomPrettyList(bag); prettyLister.PerformRename(col); return(col); }
internal SyntaxTree Generate(NativeSymbolBag bag, ErrorProvider ep) { // Make sure than all of the referenced NativeDefinedType instances are in the correct // portion of the bag ChaseReferencedDefinedTypes(bag); // First step is to resolve the symbols bag.TryResolveSymbolsAndValues(ep); // Create the codedom transform var transform = new CodeTransform(_langaugeType, bag); var marshalUtil = new MarshalTransform(_langaugeType, bag, TransformKindFlags.All); var col = new CodeTypeDeclarationCollection(); // Only output the constants if there are actually any var constList = bag.FindResolvedConstants().ToList(); if (constList.Count > 0) { var constCtd = transform.GenerateConstants(constList); if (constCtd.Members.Count > 0) { col.Add(constCtd); } } foreach (var definedNt in bag.FindResolvedDefinedTypes()) { var ctd = transform.GenerateDeclaration(definedNt); marshalUtil.Process(ctd); col.Add(ctd); } var procList = bag.FindResolvedProcedures().ToList(); if (procList.Count > 0) { var procType = transform.GenerateProcedures(procList); marshalUtil.Process(procType); col.Add(procType); } // Add the helper types that we need AddHelperTypes(col); // Next step is to run the pretty lister on it var prettyLister = new CodeDomPrettyList(bag); prettyLister.PerformRename(col); var code = BasicConverter.ConvertCodeDomToPInvokeCodeImpl(_langaugeType, col, ep); return(CSharpSyntaxTree.ParseText(code)); }
public void Add() { CodeTypeDeclaration td1 = new CodeTypeDeclaration(); CodeTypeDeclaration td2 = new CodeTypeDeclaration(); CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); Assert.AreEqual(0, coll.Add(td1), "#1"); Assert.AreEqual(1, coll.Count, "#2"); Assert.AreEqual(0, coll.IndexOf(td1), "#3"); Assert.AreEqual(1, coll.Add(td2), "#4"); Assert.AreEqual(2, coll.Count, "#5"); Assert.AreEqual(1, coll.IndexOf(td2), "#6"); }
private static CodeTypeDeclarationCollection CollectionBuilder(string className, string classType, string ns) { // Declare a generic class. CodeTypeDeclaration newClass = new CodeTypeDeclaration(); newClass.Name = className; newClass.IsPartial = true; newClass.BaseTypes.Add(new CodeTypeReference("System.Collections.Generic.List", new CodeTypeReference[] { new CodeTypeReference(classType) })); // add the Serializable attribute to the class CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("System.SerializableAttribute"); newClass.CustomAttributes.Add(attribute); // add the Serializable attribute to the class CodeAttributeDeclaration xmlTypeAttribute = new CodeAttributeDeclaration("System.Xml.Serialization.XmlTypeAttribute"); xmlTypeAttribute.Arguments.Add(new CodeAttributeArgument() { Name = "Namespace", Value = new CodePrimitiveExpression(ns) }); newClass.CustomAttributes.Add(xmlTypeAttribute); CodeTypeDeclarationCollection decls = new CodeTypeDeclarationCollection(); decls.Add(newClass); return(decls); }
public void Constructor2() { CodeTypeDeclaration td1 = new CodeTypeDeclaration(); CodeTypeDeclaration td2 = new CodeTypeDeclaration(); CodeTypeDeclarationCollection c = new CodeTypeDeclarationCollection(); c.Add(td1); c.Add(td2); CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(c); Assert.AreEqual(2, coll.Count, "#1"); Assert.AreEqual(0, coll.IndexOf(td1), "#2"); Assert.AreEqual(1, coll.IndexOf(td2), "#3"); }
public void SetUpTestnameTest() { /*this.typeDeclarations = new CodeTypeDeclarationCollection(); * this.testClassDeclaration = new System.CodeDom.CodeTypeDeclaration(); * typeDeclarations.Add(this.testClassDeclaration);*/ testClassDeclaration.UserData[NStubConstants.UserDataClassTypeKey] = typeof(NStub.CSharp.Tests.Stubs.InfoApe); testClassDeclaration.Name = "NStub.CSharp.TopRootClass"; typeDeclarations.Add(this.testClassDeclaration); testClassDeclaration.UserData[NStubConstants.UserDataClassTypeKey] = typeof(NStub.CSharp.Tests.Stubs.InfoApe); testClassDeclaration.Name = "NStub.CSharp.BlaFasel.MyWorkClass"; this.namespaceDetector = new NStub.CSharp.NamespaceDetector(typeDeclarations); this.testObject = new CodeTypeSetup(this.namespaceDetector, buildData, this.testClassDeclaration); // testObject.SetUpCodeNamespace("NStub.CSharp", new[] { "System.F**k", "Rhino.Mocks" }); var expected = "MyWorkClass"; var actual = testObject.SetUpTestname(); Assert.AreEqual(expected, actual); Assert.AreEqual("NStub.CSharp.BlaFasel.MyWorkClass", testObject.BaseKey); Assert.AreEqual("MyWorkClassTest", testClassDeclaration.Name); // testObject.SetUpCodeNamespace("Jedzia.Loves.Testing", new[] { "System.F**k", "Rhino.Mocks" }); }
public override void Execute(CodeNamespace codeNamespace) { CodeTypeDeclarationCollection typesToRemove = new CodeTypeDeclarationCollection(); // foreach datatype in the codeNamespace foreach (CodeTypeDeclaration type in codeNamespace.Types) { if (Options.Type.Find(x => x.Name == codeNamespace.Name + "." + type.Name) != null || Options.Type.Find(x => x.Name == type.Name) != null) { typesToRemove.Add(type); } } foreach (CodeTypeDeclaration type in typesToRemove) { List <CodeAttributeDeclaration> toRemove = new List <CodeAttributeDeclaration>(); foreach (CodeAttributeDeclaration decl in type.CustomAttributes) { if (decl.Name == "System.Xml.Serialization.XmlTypeAttribute") { toRemove.Add(decl); } } foreach (var x in toRemove) { type.CustomAttributes.Remove(x); } //if (type.CustomAttributes.Contains(new CodeAttributeDeclaration("System.Xml.Serialization.XmlTypeAttribute"))) // type.CustomAttributes.Remove(new CodeAttributeDeclaration("System.Xml.Serialization.XmlTypeAttribute")); } }
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); } }
public string ConvertCodeDomToPInvokeCode(CodeTypeDeclaration ctd) { CodeTypeDeclarationCollection col = new CodeTypeDeclarationCollection(); col.Add(ctd); return(ConvertCodeDomToPInvokeCodeImpl(col, new ErrorProvider())); }
public void ToCodeDom(CodeTypeDeclarationCollection types) { if (this.OutputType != ClassOutputType.Interface) { CodeTypeDeclaration c = new CodeTypeDeclaration(this.Name); c.TypeAttributes = this.Attributes; types.Add(c); ToClassCodeDom(c); } if (this.OutputType == ClassOutputType.Interface || this.OutputType == ClassOutputType.ClassAndInterface) { CodeTypeDeclaration c = new CodeTypeDeclaration(InterfaceName); types.Add(c); ToInterfaceCodeDom(c); } }
private static void AddEntityOptionSetEnumDeclaration(CodeTypeDeclarationCollection types) { var enumClass = new CodeTypeDeclaration("EntityOptionSetEnum") { IsClass = true, TypeAttributes = TypeAttributes.Sealed | TypeAttributes.NotPublic, }; // public static int? GetEnum(Microsoft.Xrm.Sdk.Entity entity, string attributeLogicalName) var get = new CodeMemberMethod { Name = "GetEnum", ReturnType = new CodeTypeReference(typeof(int?)), // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags Attributes = System.CodeDom.MemberAttributes.Static | System.CodeDom.MemberAttributes.Public, }; get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Microsoft.Xrm.Sdk.Entity), "entity")); get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "attributeLogicalName")); // entity.Attributes.ContainsKey(attributeLogicalName) var entityAttributesContainsKey = new CodeMethodReferenceExpression( new CodePropertyReferenceExpression( new CodeArgumentReferenceExpression("entity"), "Attributes"), "ContainsKey"); var invokeContainsKey = new CodeMethodInvokeExpression(entityAttributesContainsKey, new CodeArgumentReferenceExpression("attributeLogicalName")); // Microsoft.Xrm.Sdk.OptionSetValue value = entity.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>(attributeLogicalName).Value; var declareAndSetValue = new CodeVariableDeclarationStatement { Type = new CodeTypeReference(typeof(OptionSetValue)), Name = "value", InitExpression = new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeArgumentReferenceExpression("entity"), "GetAttributeValue", new CodeTypeReference(typeof(OptionSetValue))), new CodeArgumentReferenceExpression("attributeLogicalName")) }; // value != null var valueNeNull = new CodeSnippetExpression("value != null"); // value.Value var invokeValueGetValue = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("value"), "Value"); // if(invokeContainsKey){return invokeGetAttributeValue;}else{return null} get.Statements.Add(new CodeConditionStatement(invokeContainsKey, declareAndSetValue, new CodeConditionStatement(valueNeNull, new CodeMethodReturnStatement(invokeValueGetValue)))); // return null; get.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null))); enumClass.Members.Add(get); types.Add(enumClass); }
static CodeTypeDeclarationCollection GenerateLongTree(string name, SupportedType[] fieldTypes, SupportedType[] propTypes, bool isEvent, bool isType2) { CodeTypeDeclarationCollection instrumentedTypes = new CodeTypeDeclarationCollection(); CodeTypeDeclaration type, typeD, typeDD, typeDDD, typeDDDD, typeDDDDD, typeDDDDDD; type = GenerateBigType(name + "A", null, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); if (isType2) { type.BaseTypes.Add(isEvent?typeof(System.Management.Instrumentation.Event):typeof(System.Management.Instrumentation.Instance)); } typeD = GenerateBigType(name + "AA", type, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeDD = GenerateBigType(name + "AAA", typeD, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeDDD = GenerateBigType(name + "AAAA", typeDD, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeDDDD = GenerateBigType(name + "AAAAA", typeDDD, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeDDDDD = GenerateBigType(name + "AAAAAA", typeDDDD, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeDDDDDD = GenerateBigType(name + "AAAAAAA", typeDDDDD, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); instrumentedTypes.Add(type); instrumentedTypes.Add(typeD); instrumentedTypes.Add(typeDD); instrumentedTypes.Add(typeDDD); instrumentedTypes.Add(typeDDDD); instrumentedTypes.Add(typeDDDDD); instrumentedTypes.Add(typeDDDDDD); return(instrumentedTypes); }
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"); }
internal static void AddDelegate(CodeTypeDeclarationCollection codeClasses, string handlerType, string handlerArgs) { CodeTypeDelegate delegate2 = new CodeTypeDelegate(handlerType); delegate2.CustomAttributes.Add(GeneratedCodeAttribute); delegate2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "sender")); delegate2.Parameters.Add(new CodeParameterDeclarationExpression(handlerArgs, "e")); delegate2.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true)); codeClasses.Add(delegate2); }
public void SetUp() { buildData = new BuildDataDictionary(); this.typeDeclarations = new CodeTypeDeclarationCollection(); this.testClassDeclaration = new System.CodeDom.CodeTypeDeclaration(); typeDeclarations.Add(this.testClassDeclaration); this.namespaceDetector = new NStub.CSharp.NamespaceDetector(typeDeclarations); this.testObject = new CodeTypeSetup(this.namespaceDetector, buildData, this.testClassDeclaration); }
static CodeTypeDeclarationCollection GenerateTree(string name, SupportedType[] fieldTypes, SupportedType[] propTypes, bool isEvent, bool isType2) { CodeTypeDeclarationCollection instrumentedTypes = new CodeTypeDeclarationCollection(); CodeTypeDeclaration type, typeD1, typeD2, typeD1a, typeD1b; type = GenerateBigType(name + "A", null, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); if (isType2) { type.BaseTypes.Add(isEvent?typeof(System.Management.Instrumentation.Event):typeof(System.Management.Instrumentation.Instance)); } typeD1 = GenerateBigType(name + "AA", type, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); typeD1a = GenerateBigType(name + "AAA", typeD1, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); typeD1b = GenerateBigType(name + "AAB", typeD1, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); typeD2 = GenerateBigType(name + "AB", type, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); instrumentedTypes.Add(type); instrumentedTypes.Add(typeD1); instrumentedTypes.Add(typeD1a); instrumentedTypes.Add(typeD1b); instrumentedTypes.Add(typeD2); type = GenerateBigType(name + "B", null, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvAbstract); if (isType2) { type.BaseTypes.Add(isEvent?typeof(System.Management.Instrumentation.Event):typeof(System.Management.Instrumentation.Instance)); } typeD1 = GenerateBigType(name + "BA", type, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); typeD2 = GenerateBigType(name + "BB", type, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); instrumentedTypes.Add(type); instrumentedTypes.Add(typeD1); instrumentedTypes.Add(typeD2); type = GenerateBigType(name + "C", null, fieldTypes, propTypes, isEvent ? SupportedType.attrProvEvent:SupportedType.attrProvInstance); if (isType2) { type.BaseTypes.Add(isEvent?typeof(System.Management.Instrumentation.Event):typeof(System.Management.Instrumentation.Instance)); } instrumentedTypes.Add(type); 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); }
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); }
/// <summary> /// /// </summary> /// <returns></returns> public override CodeTypeDeclarationCollection EmitApiClass() { Validate(); // emitter-specific validation CodeTypeReference baseType = this.GetBaseType(); // raise the TypeGenerated event TypeGeneratedEventArgs eventArgs = new TypeGeneratedEventArgs(Item, baseType); this.Generator.RaiseTypeGeneratedEvent(eventArgs); // public [abstract] partial class ClassName CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(Item.Name); typeDecl.IsPartial = true; typeDecl.TypeAttributes = System.Reflection.TypeAttributes.Class; if (Item.Abstract) { typeDecl.TypeAttributes |= System.Reflection.TypeAttributes.Abstract; } SetTypeVisibility(typeDecl); EmitTypeAttributes(Item.Name, typeDecl, eventArgs.AdditionalAttributes); // : baseclass AssignBaseType(typeDecl, baseType, eventArgs.BaseType); AddInterfaces(Item.Name, typeDecl, eventArgs.AdditionalInterfaces); CommentEmitter.EmitSummaryComments(Item, typeDecl.Comments); // Since abstract types cannot be instantiated, skip the factory method for abstract types if ((typeDecl.TypeAttributes & System.Reflection.TypeAttributes.Abstract) == 0) { EmitFactoryMethod(typeDecl); } EmitProperties(typeDecl); // additional members, if provided by the event subscriber this.AddMembers(Item.Name, typeDecl, eventArgs.AdditionalMembers); CodeTypeDeclarationCollection typeDecls = new CodeTypeDeclarationCollection(); typeDecls.Add(typeDecl); return(typeDecls); }
private CodeTypeDeclarationCollection GenerateStructures() { CodeTypeDeclarationCollection collection = new CodeTypeDeclarationCollection(); //todo: foreach (var item in this.StrutureList) { CodeTypeDeclaration codeType = new CodeTypeDeclaration(item.Name); codeType.IsClass = true; foreach (var field in item.FieldList) { CodeMemberField member = GetCodeMemberField(field); codeType.Members.Add(member); } collection.Add(codeType); } return(collection); }
private static void AddTypes(string prepend, bool nested, CodeTypeDeclarationCollection types, CodeExpressionCollection into) { foreach (CodeTypeDeclaration t in types) { into.Add(new CodeTypeOfExpression( ((prepend == null || prepend == "") ? "" : (prepend + (nested ? "+" : "."))) + t.Name)); CodeTypeDeclarationCollection ctd = new CodeTypeDeclarationCollection(); foreach (CodeTypeMember m in t.Members) { if (m is CodeTypeDeclaration) { ctd.Add((CodeTypeDeclaration)m); } } AddTypes( ((prepend == null || prepend == "") ? "" : (prepend + (nested ? "+" : "."))) + t.Name, true, ctd, into); } }
/// <summary> /// Add any of the helper types that we need /// </summary> private void AddHelperTypes(CodeTypeDeclarationCollection col) { var needed = false; var it = new CodeDomIterator(); foreach (var ctdRef in it.Iterate(col).OfType <CodeTypeReference>()) { if (String.Equals(ctdRef.BaseType, MarshalTypeFactory.PInvokePointerTypeName)) { needed = true; break; } } if (needed) { col.Add(MarshalTypeFactory.CreatePInvokePointerType()); } }
public override void Execute(CodeNamespace codeNamespace) { CodeTypeDeclarationCollection typesToRemove = new CodeTypeDeclarationCollection(); // foreach datatype in the codeNamespace foreach (CodeTypeDeclaration type in codeNamespace.Types) { if (Options.Type.ContainsName(codeNamespace.Name + "." + type.Name) || Options.Type.ContainsName(type.Name)) { typesToRemove.Add(type); } } foreach (CodeTypeDeclaration type in typesToRemove) { codeNamespace.Types.Remove(type); } }
public CodeTypeDeclaration AddCodeType(string strTypeName, ESheetType eType, string strComment = "") { CodeTypeDeclaration pCodeType = new CodeTypeDeclaration(strTypeName); _arrCodeTypeDeclaration.Add(pCodeType); switch (eType) { case ESheetType.Class: pCodeType.IsClass = true; break; case ESheetType.Struct: pCodeType.IsStruct = true; break; case ESheetType.Enum: pCodeType.IsEnum = true; break; } pCodeType.TypeAttributes = TypeAttributes.Public; pCodeType.AddComment(strComment); return(pCodeType); }
/// <summary> /// Add any of the helper types that we need /// </summary> /// <param name="col"></param> /// <remarks></remarks> private void AddHelperTypes(CodeTypeDeclarationCollection col) { bool addPInvokePointer = false; CodeDomIterator it = new CodeDomIterator(); List <object> list = it.Iterate(col); foreach (object obj in list) { CodeTypeReference ctdRef = obj as CodeTypeReference; if (ctdRef != null && 0 == string.CompareOrdinal(ctdRef.BaseType, MarshalTypeFactory.PInvokePointerTypeName)) { addPInvokePointer = true; } } if (addPInvokePointer) { col.Add(MarshalTypeFactory.CreatePInvokePointerType()); } }
private static int DeleteEnums(CodeNamespace ns, List <string> toDelete) { int deleted = 0; CodeTypeDeclarationCollection toRemove = new CodeTypeDeclarationCollection(); foreach (CodeTypeDeclaration type in ns.Types) { if (toDelete.Contains(type.Name) && type.IsEnum) { toRemove.Add(type); } } foreach (CodeTypeDeclaration type in toRemove) { ns.Types.Remove(type); deleted++; } return(deleted); }
public override void Execute(CodeNamespace codeNamespace) { #region find the values that have the namespace CodeTypeDeclarationCollection typesToRemove = new CodeTypeDeclarationCollection(); // foreach datatype in the codeNamespace foreach (CodeTypeDeclaration type in codeNamespace.Types) { string ns = Utility.GetXmlNamespace(type); if (string.IsNullOrEmpty(ns)) { continue; } if (Options.Namespace.ContainsXmlName(ns)) { typesToRemove.Add(type); } } #endregion #region remove the values that were in the namespace foreach (CodeTypeDeclaration type in typesToRemove) { codeNamespace.Types.Remove(type); } #endregion #region add imports foreach (NamespaceType ns in Options.Namespace) { if (string.IsNullOrEmpty(ns.CodeNamespace)) { continue; } codeNamespace.Imports.Add(new CodeNamespaceImport(ns.CodeNamespace)); } #endregion }
public void GeneratePool(CodeTypeDeclarationCollection typeList, CompileDirectives compileDirectives) { Guid nameExt = Guid.NewGuid(); string name = "pool" + nameExt.ToString("N").ToUpper(); CodeTypeDeclaration type = new CodeTypeDeclaration(name); type.IsClass = true; type.TypeAttributes = System.Reflection.TypeAttributes.Class | System.Reflection.TypeAttributes.Sealed; CodeExpression typeRef = new CodeTypeReferenceExpression(name); typeList.Add(type); int index = 0; //add all the pools to the type. foreach (KeyValuePair <ByteArray, CodeFieldReferenceExpression> item in this.pool) { //create the static member string itemName = "item" + index++; //decompressed in code CodeMethodReferenceExpression decompressMethod = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(ConstantArray.ArrayUtils)), "SimpleDecompress"); CodeExpression dataCode = ShaderBytes.ToArray(item.Key.Array, compileDirectives); CodeMemberField field = new CodeMemberField(typeof(byte[]), itemName); field.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final; //assign it inline field.InitExpression = new CodeMethodInvokeExpression(decompressMethod, dataCode); type.Members.Add(field); item.Value.FieldName = itemName; item.Value.TargetObject = typeRef; } }
// 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> }