Esempio n. 1
0
        private static void ProvideClearIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(null, "ClearIndent", "Remove any indentation", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { indentLengths.Ref().CallS("Clear", new CodeExpression[0]), currentIndent.Ref().Assign(string.Empty.Prim()) });

            method.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "Transform-time helpers"));
            members.Add(method);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates source code from given attributes.
        /// </summary>
        public static string GenerateFromAttribute(CodeDomProvider codeProvider, params CodeAttributeDeclaration[] attributes)
        {
            CodeTypeMemberCollection collection = new CodeTypeMemberCollection();
            CodeMemberMethod         temp       = new CodeMemberMethod();
            int start = 0;

            if (attributes == null || attributes.Length == 0)
            {
                return(string.Empty);
            }

            temp.Name       = " ";
            temp.ReturnType = new CodeTypeReference(" ");
            collection.Add(temp);

            foreach (CodeAttributeDeclaration a in attributes)
            {
                temp.CustomAttributes.Add(a);
            }

            // get the code from function with attributes:
            string code = GenerateFromMember(codeProvider, collection, false);

            // and remove the last line with the function declaration:
            for (int i = 0; i < attributes.Length; i++)
            {
                start = code.IndexOfAny(NewLineChars, start);
            }
            if (start != -1)
            {
                code = code.Substring(0, start);
            }

            return(code);
        }
        protected override void DbusServiceTargetField(CodeTypeReference typerefDbusInterface, CodeTypeReference typerefDbusMarshal, CodeTypeMemberCollection members)
        {
            CodeMemberField memberProxy = new CodeMemberField(typerefDbusInterface, CodeBuilderCommon.targetName);

            memberProxy.Attributes = MemberAttributes.Private;
            members.Add(memberProxy);
        }
Esempio n. 4
0
        public void Constructor2()
        {
            CodeTypeMember tm1 = new CodeTypeMember();
            CodeTypeMember tm2 = new CodeTypeMember();

            CodeTypeMemberCollection c = new CodeTypeMemberCollection();

            c.Add(tm1);
            c.Add(tm2);

            CodeTypeMemberCollection coll = new CodeTypeMemberCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(tm1), "#2");
            Assert.AreEqual(1, coll.IndexOf(tm2), "#3");
        }
Esempio n. 5
0
        public virtual CodeTypeDeclaration GenerateTypeDeclaration(string targetNamespace, string name, params string[] parents)
        {
            CodeTypeDeclaration type =
                CreateTypeDeclaration.Called(name)
                .AsPartial
                .WithAttributes(TypeAttributes.Public)
                .WithCustomAttributes(CodeGeneratorAttribute)
                .Type;

            CodeNamespace ns = LookupNamespace(targetNamespace);

            if (parents.Length == 0)
            {
                ns.Types.Add(type);
            }
            else
            {
                CodeTypeMemberCollection members = GetMemberCollectionForTypeDeclaration(ns.Types, parents[0]);

                for (int i = 1; i < parents.Length; i++)
                {
                    members = GetMemberCollectionForTypeMember(members, parents[i]);
                }

                members.Add(type);
            }

            return(type);
        }
Esempio n. 6
0
        public void AddRange()
        {
            CodeTypeMember tm1 = new CodeTypeMember();
            CodeTypeMember tm2 = new CodeTypeMember();
            CodeTypeMember tm3 = new CodeTypeMember();

            CodeTypeMemberCollection coll1 = new CodeTypeMemberCollection();

            coll1.Add(tm1);
            coll1.Add(tm2);

            CodeTypeMemberCollection coll2 = new CodeTypeMemberCollection();

            coll2.Add(tm3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(tm1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(tm2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(tm3), "#4");

            CodeTypeMemberCollection coll3 = new CodeTypeMemberCollection();

            coll3.Add(tm3);
            coll3.AddRange(new CodeTypeMember[] { tm1, tm2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(tm1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(tm2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(tm3), "#8");
        }
Esempio n. 7
0
        private static void ProvideWriteLineMethod2(CodeTypeMemberCollection members, CodeParameterDeclarationExpression argsParam)
        {
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "WriteLine", "Write formatted text directly into the generated output", (MemberAttributes)24578, CodeDomHelpers.Call("WriteLine", CodeDomHelpers.Call(typeof(string), "Format", typeof(CultureInfo).Expr().Prop("CurrentCulture"), new CodeVariableReferenceExpression("format"), new CodeVariableReferenceExpression("args"))));

            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "format"));
            codeMemberMethod.Parameters.Add(argsParam);
            members.Add(codeMemberMethod);
        }
Esempio n. 8
0
        private static string GenerateSourceCodeOutput(string codeClassName, IList <CodeNamedElement> codeElements, CodeModelLanguages language)
        {
            CodeTypeMemberCollection code            = new CodeTypeMemberCollection();
            CodeTypeMember           initConstructor = VariableHelper.GetInitConstructor(codeClassName, codeElements, language);

            code.Add(initConstructor);
            return(Environment.NewLine + CodeHelper.GenerateFromMember(language, code));
        }
Esempio n. 9
0
        public void Remove()
        {
            CodeTypeMember ctm1 = new CodeTypeMember();
            CodeTypeMember ctm2 = new CodeTypeMember();

            CodeTypeMemberCollection coll = new CodeTypeMemberCollection();

            coll.Add(ctm1);
            coll.Add(ctm2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ctm1), "#2");
            Assert.AreEqual(1, coll.IndexOf(ctm2), "#3");
            coll.Remove(ctm1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(ctm1), "#5");
            Assert.AreEqual(0, coll.IndexOf(ctm2), "#6");
        }
Esempio n. 10
0
        private static void ProvidePopIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression codeVariableReferenceExpression  = new CodeVariableReferenceExpression("indentLength");
            CodeVariableReferenceExpression codeVariableReferenceExpression2 = new CodeVariableReferenceExpression("returnValue");
            CodeMemberMethod value = CodeDomHelpers.CreateMethod(typeof(string), "PopIndent", "Remove the last indent that was added with PushIndent", (MemberAttributes)24578, new CodeVariableDeclarationStatement(typeof(string), codeVariableReferenceExpression2.VariableName, string.Empty.Prim()), new CodeConditionStatement(indentLengths.Ref().Prop("Count").Gt(0.Prim()), new CodeVariableDeclarationStatement(typeof(int), codeVariableReferenceExpression.VariableName, indentLengths.Ref().Index(indentLengths.Ref().Prop("Count").Subtract(1.Prim()))), indentLengths.Ref().CallS("RemoveAt", indentLengths.Ref().Prop("Count").Subtract(1.Prim())), new CodeConditionStatement(codeVariableReferenceExpression.Gt(0.Prim()), codeVariableReferenceExpression2.Assign(currentIndent.Ref().Call("Substring", currentIndent.Ref().Prop("Length").Subtract(codeVariableReferenceExpression))), currentIndent.Ref().Assign(currentIndent.Ref().Call("Remove", currentIndent.Ref().Prop("Length").Subtract(codeVariableReferenceExpression))))), new CodeMethodReturnStatement(codeVariableReferenceExpression2));

            members.Add(value);
        }
        // private SendOrPostCallback xxxOperationCompleted;
        internal static void AddCallbackDeclaration(CodeTypeMemberCollection members, string callbackMember)
        {
            CodeMemberField callback = new CodeMemberField();

            callback.Type = new CodeTypeReference(typeof(SendOrPostCallback));
            callback.Name = callbackMember;
            members.Add(callback);
        }
Esempio n. 12
0
        private static void ProvidePushIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression lhs = new CodeVariableReferenceExpression("indent");
            CodeMemberMethod method             = CodeDomHelpers.CreateMethod(null, "PushIndent", "Increase the indent", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeConditionStatement(lhs.VEquals(CodeDomHelpers.nullEx), new CodeStatement[] { new CodeThrowExceptionStatement(typeof(ArgumentNullException).New(new CodeExpression[] { "indent".Prim() })) }), currentIndent.Ref().Assign(currentIndent.Ref().Add(lhs)), indentLengths.Ref().CallS("Add", new CodeExpression[] { lhs.Prop("Length") }) });

            method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "indent"));
            members.Add(method);
        }
Esempio n. 13
0
        private static void ProvidePushIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression codeVariableReferenceExpression = new CodeVariableReferenceExpression("indent");
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "PushIndent", "Increase the indent", (MemberAttributes)24578, new CodeConditionStatement(codeVariableReferenceExpression.VEquals(CodeDomHelpers.nullEx), new CodeThrowExceptionStatement(typeof(ArgumentNullException).New("indent".Prim()))), currentIndent.Ref().Assign(currentIndent.Ref().Add(codeVariableReferenceExpression)), indentLengths.Ref().CallS("Add", codeVariableReferenceExpression.Prop("Length")));

            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "indent"));
            members.Add(codeMemberMethod);
        }
Esempio n. 14
0
        private static void ProvidePopIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression lhs         = new CodeVariableReferenceExpression("indentLength");
            CodeVariableReferenceExpression expression2 = new CodeVariableReferenceExpression("returnValue");
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(typeof(string), "PopIndent", "Remove the last indent that was added with PushIndent", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeVariableDeclarationStatement(typeof(string), expression2.VariableName, string.Empty.Prim()), new CodeConditionStatement(indentLengths.Ref().Prop("Count").Gt(0.Prim()), new CodeStatement[] { new CodeVariableDeclarationStatement(typeof(int), lhs.VariableName, indentLengths.Ref().Index(new CodeExpression[] { indentLengths.Ref().Prop("Count").Subtract(1.Prim()) })), indentLengths.Ref().CallS("RemoveAt", new CodeExpression[] { indentLengths.Ref().Prop("Count").Subtract(1.Prim()) }), new CodeConditionStatement(lhs.Gt(0.Prim()), new CodeStatement[] { expression2.Assign(currentIndent.Ref().Call("Substring", new CodeExpression[] { currentIndent.Ref().Prop("Length").Subtract(lhs) })), currentIndent.Ref().Assign(currentIndent.Ref().Call("Remove", new CodeExpression[] { currentIndent.Ref().Prop("Length").Subtract(lhs) })) }) }), new CodeMethodReturnStatement(expression2) });

            members.Add(method);
        }
Esempio n. 15
0
        public CodeTypeMemberCollection GenerateAbstractPageElementMethods(PageInfo pageInfo)
        {
            CodeTypeMemberCollection pageElementMembers = new CodeTypeMemberCollection();

            foreach (ElementInfo elementInfo in pageInfo.Elements)
            {
                string           elmentIdentifier  = elementInfo.Name;
                string           rawElementLocator = elementInfo.Locator;
                CodeMemberMethod pageElementMethod = new CodeMemberMethod();
                pageElementMethod.Name = elementInfo.Name;
                PageElementID id = elementInfo.TranslateLocatorToPageElementID();
                CodeObjectCreateExpression pageElementIDExpression =
                    new CodeObjectCreateExpression(new CodeTypeReference("PageElementID"),
                                                   new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("PageElementSearchContext"), id.Context.ToString()),
                                                   new CodePrimitiveExpression(id.Value));
                CodeExpression[] param = new CodeExpression[] { pageElementIDExpression };
                // TODO: Generalize method creation code
                if (elementInfo.IsReadable())
                {
                    CodeMemberMethod readableMethod = new CodeMemberMethod();
                    readableMethod.ReturnType = new CodeTypeReference("IReadable");
                    readableMethod.Attributes = MemberAttributes.Public;
                    readableMethod.Name       = elementInfo.Name;
                    readableMethod.Statements.Add(new CodeMethodReturnStatement(ConstructIReadableExpression(param)));
                    pageElementMembers.Add(readableMethod);
                }
                if (elementInfo.IsClickable())
                {
                    CodeMemberMethod clickableMethod = new CodeMemberMethod();
                    clickableMethod.ReturnType = new CodeTypeReference("IClickable");
                    clickableMethod.Attributes = MemberAttributes.Public;
                    clickableMethod.Statements.Add(new CodeMethodReturnStatement(ConstructIClickableExpression(param)));
                    pageElementMembers.Add(clickableMethod);
                }
                if (elementInfo.IsInputable())
                {
                    CodeMemberMethod inputableMethod = new CodeMemberMethod();
                    inputableMethod.ReturnType = new CodeTypeReference("IReadable");
                    inputableMethod.Attributes = MemberAttributes.Public;
                    inputableMethod.Statements.Add(new CodeMethodReturnStatement(ConstructIInputableExpression(param)));
                    pageElementMembers.Add(inputableMethod);
                }
            }
            return(pageElementMembers);
        }
Esempio n. 16
0
        public void AddRange_Self()
        {
            CodeTypeMemberCollection coll = new CodeTypeMemberCollection();

            coll.Add(new CodeTypeMember());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
Esempio n. 17
0
        private static void ProvideWriteMethod1(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberField endsWithNewline, CodeMemberProperty GenerationEnvironment, CodeVariableReferenceExpression textToAppend)
        {
            CodeExpression   lhs    = typeof(Environment).Expr().Prop("NewLine");
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(null, "Write", "Write text directly into the generated output", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeConditionStatement(CodeDomHelpers.Call(typeof(string), "IsNullOrEmpty", new CodeExpression[] { textToAppend }), new CodeStatement[] { new CodeMethodReturnStatement() }), new CodeCommentStatement("If we're starting off, or if the previous text ended with a newline,"), new CodeCommentStatement("we have to append the current indent first."), new CodeConditionStatement(new CodeBinaryOperatorExpression(GenerationEnvironment.Ref().Prop("Length").VEquals(0.Prim()), CodeBinaryOperatorType.BooleanOr, endsWithNewline.Ref()), new CodeStatement[] { GenerationEnvironment.Ref().CallS("Append", new CodeExpression[] { currentIndent.Ref() }), endsWithNewline.Ref().Assign(false.Prim()) }), new CodeCommentStatement("Check if the current text ends with a newline"), new CodeConditionStatement(textToAppend.Call("EndsWith", new CodeExpression[] { lhs, typeof(StringComparison).Expr().Prop("CurrentCulture") }), new CodeStatement[] { new CodeAssignStatement(endsWithNewline.Ref(), true.Prim()) }), new CodeCommentStatement("This is an optimization. If the current indent is \"\", then we don't have to do any"), new CodeCommentStatement("of the more complex stuff further down."), new CodeConditionStatement(currentIndent.Ref().Prop("Length").VEquals(0.Prim()), new CodeStatement[] { GenerationEnvironment.Ref().CallS("Append", new CodeExpression[] { textToAppend }), new CodeMethodReturnStatement() }), new CodeCommentStatement("Everywhere there is a newline in the text, add an indent after it"), textToAppend.Assign(textToAppend.Call("Replace", new CodeExpression[] { lhs, lhs.Add(currentIndent.Ref()) })), new CodeCommentStatement("If the text ends with a newline, then we should strip off the indent added at the very end"), new CodeCommentStatement("because the appropriate indent will be added when the next time Write() is called"), new CodeConditionStatement(endsWithNewline.Ref(), new CodeStatement[] { GenerationEnvironment.Ref().CallS("Append", new CodeExpression[] { textToAppend, 0.Prim(), textToAppend.Prop("Length").Subtract(currentIndent.Ref().Prop("Length")) }) }, new CodeStatement[] { GenerationEnvironment.Ref().CallS("Append", new CodeExpression[] { textToAppend }) }) });

            method.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Transform-time helpers"));
            method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), textToAppend.VariableName));
            members.Add(method);
        }
        internal static void AddCallbackDeclaration(CodeTypeMemberCollection members, string callbackMember)
        {
            CodeMemberField field = new CodeMemberField {
                Type = new CodeTypeReference(typeof(SendOrPostCallback)),
                Name = callbackMember
            };

            members.Add(field);
        }
Esempio n. 19
0
        private static void ProvideWriteMethod2(CodeTypeMemberCollection members, CodeParameterDeclarationExpression argsParam)
        {
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(null, "Write", "Write formatted text directly into the generated output", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { CodeDomHelpers.Call("Write", new CodeExpression[] { CodeDomHelpers.Call(typeof(string), "Format", new CodeExpression[] { typeof(CultureInfo).Expr().Prop("CurrentCulture"), new CodeVariableReferenceExpression("format"), new CodeVariableReferenceExpression("args") }) }) });

            method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "format"));
            argsParam.CustomAttributes.Add(new CodeAttributeDeclaration("System.ParamArrayAttribute"));
            method.Parameters.Add(argsParam);
            members.Add(method);
        }
Esempio n. 20
0
        private void CreateItemProperty(FieldPropertyInfo propertyInfo, CodeTypeMemberCollection members)
        {
            Assert.ArgumentNotNull(propertyInfo, "propertyInfo");

            var backingFieldName = "_" + propertyInfo.FieldPropertyName[0].ToString(CultureInfo.InvariantCulture).ToLower() + propertyInfo.FieldPropertyName.Substring(1);
            var backingField     = new CodeMemberField(new CodeTypeReference(propertyInfo.FieldType.InternalFieldType), backingFieldName);

            backingField.Attributes = MemberAttributes.Private;

            var property = new CodeMemberProperty
            {
                // ReSharper disable BitwiseOperatorOnEnumWithoutFlags
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                // ReSharper restore BitwiseOperatorOnEnumWithoutFlags
                Type   = new CodeTypeReference(propertyInfo.FieldType.PublicFieldType),
                Name   = propertyInfo.FieldPropertyName,
                HasGet = true
            };

            // add [IndexField] attribute
            property.CustomAttributes.Add(GetIndexFieldAttribute(propertyInfo.SearchFieldName));

            // if(backingField == null)
            //	backingField = new SynthesisFieldType(new Lazy<Field>(() => InnerItem.Fields["xxx"], GetSearchFieldValue("index-field-name"));

            var initializerLambda          = new CodeSnippetExpression(string.Format("new global::Synthesis.FieldTypes.LazyField(() => InnerItem.Fields[\"{0}\"], \"{1}\", \"{2}\")", propertyInfo.Field.Id, propertyInfo.Field.Template.FullPath, propertyInfo.Field.Name));
            var initializerSearchReference = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(),
                                                                            "GetSearchFieldValue",
                                                                            new CodePrimitiveExpression(propertyInfo.SearchFieldName));

            var backingFieldNullCheck = new CodeConditionStatement();

            backingFieldNullCheck.Condition = new CodeSnippetExpression(string.Format("{0} == null", backingFieldName));
            backingFieldNullCheck.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(backingFieldName), new CodeObjectCreateExpression(propertyInfo.FieldType.InternalFieldType, initializerLambda, initializerSearchReference)));
            property.GetStatements.Add(backingFieldNullCheck);

            // return backingField;
            property.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(backingFieldName)));

            AddCommentsToFieldProperty(property, propertyInfo.Field);

            members.Add(backingField);
            members.Add(property);
        }
        public void FindTypeMemberByNameTest()
        {
            CodeTypeMemberCollection collection = null;

            Assert.Throws(typeof(ArgumentNullException), () => collection.FindTypeMemberByName(null));
            Assert.Throws(typeof(ArgumentNullException), () => collection.FindTypeMemberByName("name"));

            collection = new CodeTypeMemberCollection(new[] { new CodeTypeMember(), });

            Assert.Throws(typeof(ArgumentNullException), () => collection.FindTypeMemberByName(null));
            Assert.Throws(typeof(ArgumentException), () => collection.FindTypeMemberByName(""));

            Assert.IsNull(collection.FindTypeMemberByName("AnyString"));

            collection.Add(CreateMemberProperty("Fish"));

            CodeTypeMember member = new CodeMemberMethod();

            member.Name = "Method";
            collection.Add(member);

            member      = new CodeMemberField();
            member.Name = "Field";
            collection.Add(member);

            member      = new CodeMemberEvent();
            member.Name = "Event";
            collection.Add(member);

            collection.Add(new CodeTypeDeclaration()
            {
                Name = "Class"
            });

            Assert.IsNull(collection.FindTypeMemberByName("AnyString"));
            Assert.IsNull(collection.FindTypeMemberByName("Method"));
            Assert.IsNull(collection.FindTypeMemberByName("Field"));
            Assert.IsNull(collection.FindTypeMemberByName("Event"));
            Assert.IsNull(collection.FindTypeMemberByName("Fish"));

            Assert.IsNotNull(collection.FindTypeMemberByName("Class"));
            Assert.AreEqual("Class", collection.FindTypeMemberByName("Class").Name);
        }
        // public event xxxCompletedEventHandler xxxCompleted;
        internal static void AddEvent(CodeTypeMemberCollection members, string handlerType, string handlerName)
        {
            CodeMemberEvent eventCompleted = new CodeMemberEvent();

            eventCompleted.Type       = new CodeTypeReference(handlerType);
            eventCompleted.Name       = handlerName;
            eventCompleted.Attributes = (eventCompleted.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            eventCompleted.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
            members.Add(eventCompleted);
        }
Esempio n. 23
0
        protected virtual void AddPageFields(CodeTypeMemberCollection members)
        {
            fileDependenciesField = new CodeMemberField {
                Name       = "__fileDependencies",
                Type       = new CodeTypeReference(typeof(string[])),
                Attributes = MemberAttributes.Private | MemberAttributes.Static
            };

            members.Add(fileDependenciesField);

            if (parser.OutputCache != null)
            {
                outputCacheField = new CodeMemberField {
                    Name       = "__outputCacheSettings",
                    Type       = new CodeTypeReference(typeof(System.Web.UI.OutputCacheParameters)),
                    Attributes = MemberAttributes.Private | MemberAttributes.Static
                };
                members.Add(outputCacheField);
            }
        }
Esempio n. 24
0
        private static CodeMemberField ProvideNestedClassField(CodeTypeMemberCollection members, CodeTypeReference nestRef)
        {
            CodeMemberField field = new CodeMemberField(nestRef, "toStringHelperField")
            {
                Attributes     = MemberAttributes.Private,
                InitExpression = new CodeObjectCreateExpression(nestRef, new CodeExpression[0])
            };

            members.Add(field);
            return(field);
        }
Esempio n. 25
0
        private static void ProvideCurrentIndentProperty(CodeTypeMemberCollection members, CodeMemberField currentIndent)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Type = new CodeTypeReference(typeof(string));
            codeMemberProperty.Name = "CurrentIndent";
            codeMemberProperty.AddSummaryComment("Gets the current indent we use when adding lines to the output");
            codeMemberProperty.Attributes = (MemberAttributes)24578;
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(currentIndent.Ref()));
            members.Add(codeMemberProperty);
        }
Esempio n. 26
0
        public CodeTypeMemberCollection ParseMembers()
        {
            CodeTypeMemberCollection mc = new CodeTypeMemberCollection();

            while (TokenType != CDILToken.EOF && !IsKeyword("end"))
            {
                CodeTypeMember member = ParseMember();
                mc.Add(member);
            }
            return(mc);
        }
Esempio n. 27
0
        public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members)
        {
            string   className = "DVAL_" + Guid.NewGuid().ToString("N");
            DynValue kval      = table.Get("value");

            DynValue vtype       = table.Get("type");
            DynValue vstaticType = table.Get("staticType");

            string type       = (vtype.Type == DataType.String) ? vtype.String : null;
            string staticType = (vstaticType.Type == DataType.String) ? vstaticType.String : null;


            CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);

            classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;

            classCode.BaseTypes.Add(typeof(DynValueMemberDescriptor));

            CodeConstructor ctor = new CodeConstructor();

            ctor.Attributes = MemberAttributes.Assembly;
            classCode.Members.Add(ctor);


            if (type == null)
            {
                Table tbl = new Table(null);
                tbl.Set(1, kval);
                string str = tbl.Serialize();

                ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));
                ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(str));
            }
            else if (type == "userdata")
            {
                ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));

                CodeMemberProperty p = new CodeMemberProperty();
                p.Name       = "Value";
                p.Type       = new CodeTypeReference(typeof(DynValue));
                p.Attributes = MemberAttributes.Override | MemberAttributes.Public;
                p.GetStatements.Add(
                    new CodeMethodReturnStatement(
                        new CodeMethodInvokeExpression(
                            new CodeTypeReferenceExpression(typeof(UserData)),
                            "CreateStatic", new CodeTypeOfExpression(staticType))));

                classCode.Members.Add(p);
            }


            members.Add(classCode);
            return(new CodeExpression[] { new CodeObjectCreateExpression(className) });
        }
        protected override void AddPageFields(CodeTypeMemberCollection members)
        {
            base.AddPageFields(members);

            executableField = new CodeMemberField {
                Name       = "_Executable",
                Type       = new CodeTypeReference(typeof(XQueryExecutable)),
                Attributes = MemberAttributes.Private | MemberAttributes.Static
            };

            members.Add(executableField);
        }
Esempio n. 29
0
        private static void ProvideNestedClassProperty(CodeTypeMemberCollection members, CodeTypeReference nestRef, CodeMemberField toStringHelperField)
        {
            CodeMemberProperty property = new CodeMemberProperty {
                Type       = nestRef,
                Name       = "ToStringHelper",
                Attributes = MemberAttributes.Public | MemberAttributes.Final
            };

            property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), toStringHelperField.Name)));
            property.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "ToString Helpers"));
            members.Add(property);
        }
        internal static void AddEvent(CodeTypeMemberCollection members, string handlerType, string handlerName)
        {
            CodeMemberEvent event2;

            event2 = new CodeMemberEvent {
                Type       = new CodeTypeReference(handlerType),
                Name       = handlerName,
                Attributes = (event2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public
            };
            event2.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
            members.Add(event2);
        }
Esempio n. 31
0
    public void PostMembersHook(Smoke* smoke, Smoke.Class* klass, CodeTypeDeclaration type)
    {
        if (Util.IsQObject(klass))
        {
            CodeMemberProperty emit = new CodeMemberProperty();
            emit.Name = "Emit";
            emit.Attributes = MemberAttributes.Family | MemberAttributes.New | MemberAttributes.Final;
            emit.HasGet = true;
            emit.HasSet = false;

            string signalsIfaceName = "I" + type.Name + "Signals";
            CodeTypeReference returnType = new CodeTypeReference(signalsIfaceName);
            emit.Type = returnType;

            emit.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(
                returnType,
                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "Q_EMIT")
            )));

            type.Members.Add(emit);

            string className = ByteArrayManager.GetString(klass->className);
            int colon = className.LastIndexOf("::", StringComparison.Ordinal);
            string prefix = (colon != -1) ? className.Substring(0, colon) : string.Empty;

            IList typeCollection = this.Data.GetTypeCollection(prefix);
            CodeTypeDeclaration ifaceDecl = new CodeTypeDeclaration(signalsIfaceName);
            ifaceDecl.IsInterface = true;

            if (className != "QObject")
            {
                string parentClassName = ByteArrayManager.GetString(smoke->classes[smoke->inheritanceList[klass->parents]].className);
                colon = parentClassName.LastIndexOf("::", StringComparison.Ordinal);
                prefix = (colon != -1) ? parentClassName.Substring(0, colon) : string.Empty;
                if (colon != -1)
                {
                    parentClassName = parentClassName.Substring(colon + 2);
                }

                string parentInterface = (prefix != string.Empty) ? prefix.Replace("::", ".") + "." : string.Empty;
                parentInterface += "I" + parentClassName + "Signals";

                ifaceDecl.BaseTypes.Add(new CodeTypeReference(parentInterface));
            }
            Dictionary<CodeSnippetTypeMember, CodeMemberMethod> signalEvents = new Dictionary<CodeSnippetTypeMember, CodeMemberMethod>();
            IEnumerable<CodeMemberMethod> methods = type.Members.OfType<CodeMemberMethod>().ToList();
            GetSignals(smoke, klass, delegate(string signature, string name, string typeName, IntPtr metaMethod)
            {
                CodeMemberMethod signal = new CodeMemberMethod();
                signal.Attributes = MemberAttributes.Abstract;

                // capitalize the first letter
                StringBuilder builder = new StringBuilder(name);
                builder[0] = char.ToUpper(builder[0]);
                string signalName = builder.ToString();
                if (type.Members.OfType<CodeTypeDeclaration>().Any(t => t.Name == signalName))
                {
                    builder[0] = name[0];
                }
                signal.Name = builder.ToString();
                bool isRef;
                try
                {
                    if (typeName == string.Empty)
                        signal.ReturnType = new CodeTypeReference(typeof(void));
                    else
                        signal.ReturnType = this.Translator.CppToCSharp(typeName, type, out isRef);
                }
                catch (NotSupportedException)
                {
                    Debug.Print("  |--Won't wrap signal {0}::{1}", className, signature);
                    return;
                }

                CodeAttributeDeclaration attr = new CodeAttributeDeclaration("Q_SIGNAL",
                    new CodeAttributeArgument(new CodePrimitiveExpression(signature)));
                signal.CustomAttributes.Add(attr);

                int argNum = 1;
                StringBuilder fullNameBuilder = new StringBuilder("Slot");
                GetMetaMethodParameters(metaMethod, delegate(string paramType, string paramName)
                {
                    if (paramName == string.Empty)
                    {
                        paramName = "arg" + argNum.ToString();
                    }
                    argNum++;

                    CodeParameterDeclarationExpression param;
                    try
                    {
                        short id = smoke->IDType(paramType);
                        CodeTypeReference paramTypeRef;
                        if (id > 0)
                        {
                            paramTypeRef = this.Translator.CppToCSharp(smoke->types + id, type, out isRef);
                        }
                        else
                        {
                            if (!paramType.Contains("::"))
                            {
                                id = smoke->IDType(className + "::" + paramType);
                                if (id > 0)
                                {
                                    paramTypeRef = this.Translator.CppToCSharp(smoke->types + id, type, out isRef);
                                }
                                else
                                {
                                    paramTypeRef = this.Translator.CppToCSharp(paramType, type, out isRef);
                                }
                            }
                            else
                            {
                                paramTypeRef = this.Translator.CppToCSharp(paramType, type, out isRef);
                            }
                        }
                        param = new CodeParameterDeclarationExpression(paramTypeRef, paramName);
                    }
                    catch (NotSupportedException)
                    {
                        Debug.Print("  |--Won't wrap signal {0}::{1}", className, signature);
                        return;
                    }
                    if (isRef)
                    {
                        param.Direction = FieldDirection.Ref;
                    }
                    signal.Parameters.Add(param);
                    if (argNum == 2)
                    {
                        fullNameBuilder.Append('<');
                    }
                    fullNameBuilder.Append(param.Type.BaseType);
                    fullNameBuilder.Append(',');
                });
                if (fullNameBuilder[fullNameBuilder.Length - 1] == ',')
                {
                    fullNameBuilder[fullNameBuilder.Length - 1] = '>';
                }
                ifaceDecl.Members.Add(signal);
                CodeSnippetTypeMember signalEvent = new CodeSnippetTypeMember();
                signalEvent.Name = signal.Name;
                DocumentSignalEvent(type, signal, methods, signalEvent, signature);
                foreach (CodeMemberMethod method in from method in methods
                                                    where method.Name == signal.Name && method.ReturnType.BaseType == signal.ReturnType.BaseType
                                                    select method)
                {
                    method.Name = "On" + method.Name;
                }
                CodeSnippetTypeMember existing = signalEvents.Keys.FirstOrDefault(m => m.Name == signal.Name);
                if (existing != null)
                {
                    CodeSnippetTypeMember signalEventToUse;
                    CodeMemberMethod signalToUse;
                    if (signal.Parameters.Count == 0)
                    {
                        signalEventToUse = existing;
                        signalToUse = signalEvents[existing];
                    }
                    else
                    {
                        signalEventToUse = signalEvent;
                        signalToUse = signal;
                    }
                    string suffix = GetSignalEventSuffix(signalToUse);
                    signalEventToUse.Text = signalEventToUse.Text.Replace(signalEventToUse.Name, signalEventToUse.Name += suffix);
                }
                else
                {
                    if (signal.Parameters.Count > 0 && methods.Any(m => m.Name == signal.Name))
                    {
                        signalEvent.Name += GetSignalEventSuffix(signal);
                    }
                }
                signalEvent.Text += string.Format(@"
        public event {0} {1}
        {{
            add
            {{
                QObject.Connect(this, Qt.SIGNAL(""{2}""), (QObject) value.Target, Qt.SLOT(value.Method.Name + ""{3}""));
            }}
            remove
            {{
                QObject.Disconnect(this, Qt.SIGNAL(""{2}""), (QObject) value.Target, Qt.SLOT(value.Method.Name + ""{3}""));
            }}
        }}", fullNameBuilder, signalEvent.Name, signature, signature.Substring(signature.IndexOf('(')));
                signalEvents.Add(signalEvent, signal);
            });

            typeCollection.Add(ifaceDecl);
            CodeTypeMemberCollection members = new CodeTypeMemberCollection();
            foreach (KeyValuePair<CodeSnippetTypeMember, CodeMemberMethod> signalEvent in signalEvents)
            {
                members.Add(signalEvent.Key);
            }
            int index = 0;
            CodeSnippetTypeMember lastEvent = type.Members.OfType<CodeSnippetTypeMember>().LastOrDefault(s => s.Text.Contains("EventHandler<QEventArgs<"));
            if (lastEvent != null)
            {
                index = type.Members.IndexOf(lastEvent) + 1;
            }
            for (int i = members.Count - 1; i >= 0; i--)
            {
                type.Members.Insert(index, members[i]);
            }
        }
    }