Пример #1
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);
        }
Пример #2
0
        private static void ProvideCurrentIndentProperty(CodeTypeMemberCollection members, CodeMemberField currentIndent)
        {
            CodeMemberProperty member = new CodeMemberProperty {
                Type = new CodeTypeReference(typeof(string)),
                Name = "CurrentIndent"
            };

            member.AddSummaryComment("Gets the current indent we use when adding lines to the output");
            member.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            member.GetStatements.Add(new CodeMethodReturnStatement(currentIndent.Ref()));
            members.Add(member);
        }
Пример #3
0
        private static void ProvideNestedFormatProviderProperty(CodeTypeDeclaration nest, CodeFieldReferenceExpression formatProviderFieldRef)
        {
            CodeMemberProperty member = new CodeMemberProperty {
                Name       = "FormatProvider",
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Type       = new CodeTypeReference(typeof(IFormatProvider))
            };

            member.AddSummaryComment("Gets or sets format provider to be used by ToStringWithCulture method.");
            member.GetStatements.Add(new CodeMethodReturnStatement(formatProviderFieldRef));
            member.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodePropertySetValueReferenceExpression(), CodeBinaryOperatorType.IdentityInequality, CodeDomHelpers.nullEx), new CodeStatement[] { formatProviderFieldRef.Assign(new CodePropertySetValueReferenceExpression()) }));
            nest.Members.Add(member);
        }
Пример #4
0
        private static CodeMemberProperty ProvideErrorsProperty(CodeTypeMemberCollection members, CodeMemberField errors)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Type = new CodeTypeReference(typeof(CompilerErrorCollection));
            codeMemberProperty.Name = "Errors";
            codeMemberProperty.AddSummaryComment("The error collection for the generation process");
            codeMemberProperty.Attributes = (MemberAttributes)24578;
            codeMemberProperty.GetStatements.Add(CodeDomHelpers.IfVariableNullThenInstantiateType(errors.Ref(), typeof(CompilerErrorCollection)));
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(errors.Ref()));
            members.Add(codeMemberProperty);
            return(codeMemberProperty);
        }
Пример #5
0
        private static CodeMemberProperty ProvideIndentLengthsProperty(CodeTypeMemberCollection members, CodeMemberField indentLengthsField)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Type = new CodeTypeReference(typeof(List <int>));
            codeMemberProperty.Name = "indentLengths";
            codeMemberProperty.AddSummaryComment("A list of the lengths of each indent that was added with PushIndent");
            codeMemberProperty.Attributes = MemberAttributes.Private;
            codeMemberProperty.GetStatements.Add(CodeDomHelpers.IfVariableNullThenInstantiateType(indentLengthsField.Ref(), typeof(List <int>)));
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(indentLengthsField.Ref()));
            members.Add(codeMemberProperty);
            return(codeMemberProperty);
        }
Пример #6
0
        private static void ProvideSessionProperty(CodeTypeMemberCollection members, CodeMemberField session)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Type         = new CodeTypeReference(typeof(IDictionary <string, object>));
            codeMemberProperty.Type.Options = CodeTypeReferenceOptions.GlobalReference;
            codeMemberProperty.Name         = "Session";
            codeMemberProperty.AddSummaryComment("Current transformation session");
            codeMemberProperty.Attributes = MemberAttributes.Public;
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(session.Ref()));
            codeMemberProperty.SetStatements.Add(session.Ref().Assign(new CodePropertySetValueReferenceExpression()));
            codeMemberProperty.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "Properties"));
            members.Add(codeMemberProperty);
        }
Пример #7
0
        private static void ProvideNestedClassProperty(CodeTypeMemberCollection members, CodeTypeReference nestRef, CodeMemberField toStringHelperField)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty
            {
                Type       = nestRef,
                Name       = "ToStringHelper",
                Attributes = (MemberAttributes)24578
            };

            codeMemberProperty.AddSummaryComment("Helper to produce culture-oriented representation of an object as a string");
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), toStringHelperField.Name)));
            codeMemberProperty.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "ToString Helpers"));
            members.Add(codeMemberProperty);
        }
Пример #8
0
        private static void ProvideNestedFormatProviderProperty(CodeTypeDeclaration nest, CodeFieldReferenceExpression formatProviderFieldRef)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Name       = "FormatProvider";
            codeMemberProperty.Attributes = (MemberAttributes)24578;
            codeMemberProperty.Type       = new CodeTypeReference(typeof(IFormatProvider));
            CodeMemberProperty codeMemberProperty2 = codeMemberProperty;

            codeMemberProperty2.AddSummaryComment("Gets or sets format provider to be used by ToStringWithCulture method.");
            codeMemberProperty2.GetStatements.Add(new CodeMethodReturnStatement(formatProviderFieldRef));
            codeMemberProperty2.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodePropertySetValueReferenceExpression(), CodeBinaryOperatorType.IdentityInequality, CodeDomHelpers.nullEx), formatProviderFieldRef.Assign(new CodePropertySetValueReferenceExpression())));
            nest.Members.Add(codeMemberProperty2);
        }
Пример #9
0
        private static CodeMemberProperty ProvideErrorsProperty(CodeTypeMemberCollection members, CodeMemberField errors)
        {
            CodeMemberProperty member = new CodeMemberProperty {
                Type = new CodeTypeReference(typeof(CompilerErrorCollection)),
                Name = "Errors"
            };

            member.AddSummaryComment("The error collection for the generation process");
            member.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            member.GetStatements.Add(CodeDomHelpers.IfVariableNullThenInstantiateType(errors.Ref(), typeof(CompilerErrorCollection)));
            member.GetStatements.Add(new CodeMethodReturnStatement(errors.Ref()));
            members.Add(member);
            return(member);
        }
Пример #10
0
        private static CodeMemberProperty ProvideGenerationEnvironmentProperty(CodeTypeMemberCollection members, CodeMemberField generationTimeBuilder)
        {
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Properties"));
            codeMemberProperty.Type = new CodeTypeReference(typeof(StringBuilder));
            codeMemberProperty.Name = "GenerationEnvironment";
            codeMemberProperty.AddSummaryComment("The string builder that generation-time code is using to assemble generated output");
            codeMemberProperty.Attributes = (MemberAttributes)12290;
            codeMemberProperty.GetStatements.Add(CodeDomHelpers.IfVariableNullThenInstantiateType(generationTimeBuilder.Ref(), typeof(StringBuilder)));
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(generationTimeBuilder.Ref()));
            codeMemberProperty.SetStatements.Add(new CodeAssignStatement(generationTimeBuilder.Ref(), new CodePropertySetValueReferenceExpression()));
            members.Add(codeMemberProperty);
            return(codeMemberProperty);
        }
Пример #11
0
        /// <summary>
        /// Create the code added as members to the transform class.
        /// </summary>
        private void GenerateClassCode(string nameValue, string typeValue, out CodeMemberField field)
        {
            field              = new CodeMemberField(typeValue, string.Format(CultureInfo.InvariantCulture, "_{0}Field", nameValue));
            field.Attributes   = MemberAttributes.Private;
            field.Type.Options = CodeTypeReferenceOptions.GlobalReference;
            CodeMemberProperty codeMemberProperty = new CodeMemberProperty();

            codeMemberProperty.Name = nameValue;
            codeMemberProperty.Type = new CodeTypeReference(typeValue, CodeTypeReferenceOptions.GlobalReference);
            codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(field.Ref()));
            codeMemberProperty.AddSummaryComment("Access the " + nameValue + " parameter of the template.");
            CodeGeneratorOptions standardOptions = StandardOptions;

            using (StringWriter writer = new StringWriter(codeBuffer, CultureInfo.InvariantCulture))
            {
                languageCodeDomProvider.GenerateCodeFromMember(field, writer, standardOptions);
                languageCodeDomProvider.GenerateCodeFromMember(codeMemberProperty, writer, standardOptions);
            }
        }