Ejemplo n.º 1
0
        public void EmitField(string type,
                              string name,
                              AccessModifier accessModifier          = AccessModifier.Private,
                              MemberModifier methodModifers          = MemberModifier.None,
                              Action <ExpressionBuilder> initialiser = null,
                              int?fixedLength = null,
                              IEnumerable <string> summary    = null,
                              Action <DocBuilder> docs        = null,
                              IEnumerable <string> attributes = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            if (attributes != null)
            {
                foreach (var attributeName in attributes)
                {
                    this.writer.WriteLine($"[{attributeName}]");
                }
            }

            string fixedLengthSuffix = fixedLength.HasValue ? $"[{fixedLength.Value}]" : "";

            this.writer.Write($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{type} {name}{fixedLengthSuffix}");
            if (initialiser != null)
            {
                writer.Write(" = ");
                initialiser(new ExpressionBuilder(this.writer.GetSubWriter()));
            }
            this.writer.WriteLine("; ");
        }
Ejemplo n.º 2
0
        public void EmitType(TypeKind kind,
                             string name,
                             Action <TypeBuilder> @type,
                             AccessModifier accessModifier   = AccessModifier.Internal,
                             IEnumerable <string> baseTypes  = null,
                             TypeModifier modifiers          = TypeModifier.None,
                             IEnumerable <string> summary    = null,
                             Action <DocBuilder> docs        = null,
                             IEnumerable <string> attributes = null)
        {
            this.EmitTypePreamble(summary, docs, attributes);

            this.writer.WriteLine($"{accessModifier.Emit()} {RenderTypeModifiers(modifiers)}{kind.ToString().ToLowerInvariant()} {name}");

            if (baseTypes != null && baseTypes.Any())
            {
                this.writer.IncreaseIndent();
                this.writer.WriteLine($": {string.Join(", ", baseTypes)}");
                this.writer.DecreaseIndent();
            }

            using (var builder = new TypeBuilder(this.writer.GetSubWriter(), name))
            {
                @type(builder);
            }
        }
Ejemplo n.º 3
0
        public void EmitEnum(string name,
                             Action <EnumBuilder> @enum,
                             AccessModifier accessModifier   = AccessModifier.Internal,
                             IEnumerable <string> summary    = null,
                             Action <DocBuilder> docs        = null,
                             IEnumerable <string> attributes = null)
        {
            this.EmitTypePreamble(summary, docs, attributes);

            this.writer.WriteLine($"{accessModifier.Emit()} enum {name}");
            using (var builder = new EnumBuilder(this.writer.GetSubWriter()))
            {
                @enum(builder);
            }
        }
Ejemplo n.º 4
0
        public void EmitProperty(string type,
                                 string name,
                                 Action <ExpressionBuilder> getter,
                                 AccessModifier accessModifier = AccessModifier.Private,
                                 MemberModifier methodModifers = MemberModifier.None,
                                 IEnumerable <string> summary  = null,
                                 Action <DocBuilder> docs      = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            this.writer.Write($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{type} {name} => ");
            getter(new ExpressionBuilder(this.writer.GetSubWriter()));
            this.writer.WriteLine(";");
        }
Ejemplo n.º 5
0
        public void EmitDelegate(string type,
                                 string name,
                                 AccessModifier accessModifier        = AccessModifier.Internal,
                                 TypeModifier modifiers               = TypeModifier.None,
                                 Action <ParameterBuilder> parameters = null,
                                 IEnumerable <string> summary         = null,
                                 Action <DocBuilder> docs             = null,
                                 IEnumerable <string> attributes      = null)
        {
            this.EmitTypePreamble(summary, docs, attributes);

            string parameterList = parameters != null
                                    ? ParameterBuilder.Apply(parameters)
                                    : "";

            this.writer.WriteLine($"{accessModifier.Emit()} {RenderTypeModifiers(modifiers)}delegate {type} {name}({parameterList});");
        }
Ejemplo n.º 6
0
        public void EmitMethod(string returnType,
                               string name,
                               Action <CodeBlockBuilder> methodBody,
                               Action <ParameterBuilder> parameters,
                               AccessModifier accessModifier   = AccessModifier.Private,
                               MemberModifier methodModifers   = MemberModifier.None,
                               IEnumerable <string> summary    = null,
                               Action <DocBuilder> docs        = null,
                               IEnumerable <string> attributes = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            if (attributes != null)
            {
                foreach (var attributeName in attributes)
                {
                    this.writer.WriteLine($"[{attributeName}]");
                }
            }

            string parameterList = parameters != null
                                    ? ParameterBuilder.Apply(parameters)
                                    : "";

            this.writer.Write($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{returnType} {name}({parameterList})");

            if (methodBody == null)
            {
                this.writer.WriteLine(";");
            }
            else
            {
                this.writer.WriteLine();

                using (var bodyEmitter = new CodeBlockBuilder(this.writer.GetSubWriter()))
                {
                    methodBody(bodyEmitter);
                }
            }
        }
Ejemplo n.º 7
0
        public void EmitConstructor(Action <CodeBlockBuilder> methodBody,
                                    Action <ParameterBuilder> parameters,
                                    AccessModifier accessModifier = AccessModifier.Private,
                                    MemberModifier methodModifers = MemberModifier.None,
                                    IEnumerable <Action <ExpressionBuilder> > baseArguments = null,
                                    IEnumerable <string> summary    = null,
                                    Action <DocBuilder> docs        = null,
                                    IEnumerable <string> attributes = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            if (attributes != null)
            {
                foreach (var attributeName in attributes)
                {
                    this.writer.WriteLine($"[{attributeName}]");
                }
            }

            string parameterList = parameters != null
                                    ? ParameterBuilder.Apply(parameters)
                                    : "";

            this.writer.WriteLine($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{this.name}({parameterList})");

            if (baseArguments != null)
            {
                this.writer.IncreaseIndent();
                this.writer.Write(": base(");
                ExpressionBuilder.EmitArguments(this.writer, baseArguments);
                this.writer.WriteLine(")");
                this.writer.DecreaseIndent();
            }

            using (var bodyEmitter = new CodeBlockBuilder(this.writer.GetSubWriter()))
            {
                methodBody(bodyEmitter);
            }
        }
Ejemplo n.º 8
0
        public void EmitProperty(string type,
                                 string name,
                                 AccessModifier accessModifier    = AccessModifier.Private,
                                 MemberModifier methodModifers    = MemberModifier.None,
                                 Action <CodeBlockBuilder> getter = null,
                                 Action <CodeBlockBuilder> setter = null,
                                 IEnumerable <string> summary     = null,
                                 Action <DocBuilder> docs         = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            this.writer.WriteLine($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{type} {name}");
            this.writer.WriteLine("{");
            this.writer.IncreaseIndent();

            if (getter != null)
            {
                this.writer.WriteLine("get");
                using (var getBuilder = new CodeBlockBuilder(this.writer))
                {
                    getter(getBuilder);
                }
            }

            if (setter != null)
            {
                this.writer.WriteLine("set");
                using (var setBuilder = new CodeBlockBuilder(this.writer))
                {
                    setter(setBuilder);
                }
            }

            this.writer.DecreaseIndent();
            this.writer.WriteLine("}");
        }
Ejemplo n.º 9
0
        public void EmitProperty(string type,
                                 string name,
                                 AccessModifier accessModifier = AccessModifier.Private,
                                 MemberModifier methodModifers = MemberModifier.None,
                                 AccessModifier?getter         = null,
                                 AccessModifier?setter         = null,
                                 IEnumerable <string> summary  = null,
                                 Action <DocBuilder> docs      = null)
        {
            this.EmitMemberSpacing();

            this.EmitMemberComments(accessModifier, summary, docs);

            this.writer.WriteLine($"{accessModifier.Emit()} {RenderMemberModifiers(methodModifers)}{type} {name}");
            this.writer.WriteLine("{");
            this.writer.IncreaseIndent();

            if (getter != null)
            {
                if (getter.HasValue && getter.Value != accessModifier)
                {
                    this.writer.Write(getter.Value.Emit() + " ");
                }
                this.writer.WriteLine("get;");
            }

            if (setter != null)
            {
                if (setter.HasValue && setter.Value != accessModifier)
                {
                    this.writer.Write(setter.Value.Emit() + " ");
                }
                this.writer.WriteLine("set;");
            }

            this.writer.DecreaseIndent();
            this.writer.WriteLine("}");
        }