public override string Generate(int indent)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(string.Empty);
            }

            var _attributes = string.Empty;
            var count       = 0;

            foreach (AttributeGenerator attr in attributes)
            {
                _attributes += attr.Generate(indent) + (count < attributes.Count - 1 ? "\n" : string.Empty);
                count++;
            }

            if (attributes.Count > 0)
            {
                _attributes += "\n";
            }
            var modSpace   = (modifier == FieldModifier.None) ? string.Empty : " ";
            var definition = CodeBuilder.Indent(indent) + scope.AsString().ConstructHighlight() + " " + modifier.AsString().ConstructHighlight() + modSpace + (typeIsString ? stringType.WithHighlight(highlightType) : type.As().CSharpName()) + " " + name.LegalMemberName();
            var output     = !isString && (defaultValue == null || defaultValue.Equals(HUMValue.Create().New(type))) ? ";" : " = " + (isString ? stringDefault : defaultValue.As().Code(true) + ";");

            return(_attributes + definition + output);
        }
Exemple #2
0
        protected override sealed string GenerateBefore(int indent)
        {
            var attributes = string.Empty;

            foreach (AttributeGenerator attr in this.attributes)
            {
                attributes += attr.Generate(indent) + "\n";
            }
            var modSpace = modifier == MethodModifier.None ? string.Empty : " ";

            return(attributes + CodeBuilder.Indent(indent) + scope.AsString().ToLower().ConstructHighlight() + " " + modifier.AsString().ConstructHighlight() + modSpace + returnType.As().CSharpName() + " " + name.LegalMemberName() + CodeBuilder.Parameters(this.parameters));
        }
Exemple #3
0
        public override string Generate(int indent)
        {
            var _attributes = string.Empty;

            foreach (AttributeGenerator attr in attributes)
            {
                _attributes += attr.Generate(indent) + "\n";
            }

            var modSpace   = (modifier == FieldModifier.None) ? string.Empty : " ";
            var definition = CodeBuilder.Indent(indent) + scope.AsString() + " " + modifier.AsString() + modSpace + type.As().CSharpName() + " " + name;
            var output     = defaultValue == null && type.IsValueType ? ";" : " = " + (isString ? stringDefault : defaultValue.As().Code(true) + ";");

            return(_attributes + definition + output);
        }
Exemple #4
0
        public override string Generate(int indent)
        {
            return(CodeBuilder.Indent(indent) + scope.AsString() + " delegate " + returnType.Name + " " + name + "(" + GenerateParameters() + ");");

            string GenerateParameters()
            {
                var output = string.Empty;

                for (int i = 0; i < parameters.Count; i++)
                {
                    output += parameters[i].Generate(0);
                    output += i < parameters.Count - 1 ? ", " : string.Empty;
                }
                return(output);
            }
        }
Exemple #5
0
        public override string Generate(int indent)
        {
            if (returnTypeIsString)
            {
                var _attributes = string.Empty;

                foreach (AttributeGenerator attr in attributes)
                {
                    _attributes += attr.Generate(indent) + "\n";
                }

                var modSpace   = (modifier == PropertyModifier.None) ? string.Empty : " ";
                var definition = CodeBuilder.Indent(indent) + scope.AsString() + " " + modifier.AsString() + modSpace + returnTypeString + " " + name + " " + GetterSetter();
                var output     = defaultValue == null && returnType.IsValueType && returnType.IsPrimitive ? (hasGetter || hasSetter ? string.Empty : ";") : hasDefault ? " = " + defaultValue.As().Code(true) + ";" : string.Empty;
                return(_attributes + definition + output);
            }
            else
            {
                var _attributes = string.Empty;

                foreach (AttributeGenerator attr in attributes)
                {
                    _attributes += attr.Generate(indent) + "\n";
                }

                var modSpace   = (modifier == PropertyModifier.None) ? string.Empty : " ";
                var definition = CodeBuilder.Indent(indent) + scope.AsString() + " " + modifier.AsString() + modSpace + returnType.As().CSharpName() + " " + name + " " + GetterSetter();
                var output     = defaultValue == null && stringIsValueType && stringIsPrimitive ? (hasGetter || hasSetter ? string.Empty : ";") : hasDefault ? " = " + defaultValue.As().Code(true) + ";" : string.Empty;
                return(_attributes + definition + output);
            }

            string GetterSetter()
            {
                var result = string.Empty;

                if (multiStatementGetter || multiStatementSetter)
                {
                    return((getterBody == null ? string.Empty : "\n" + CodeBuilder.Indent(indent) + "{\n" + Getter()) + (setterBody == null ? string.Empty : "\n" + Setter() + "\n") + "\n" + CodeBuilder.Indent(indent) + "}");
                }
                else
                {
                    return("{ " + (getterBody == null ? string.Empty : Getter() + " ") + (setterBody == null ? string.Empty : (getterBody == null ? " " : string.Empty) + Setter() + " ") + "}");
                }
            }

            string Getter()
            {
                if (multiStatementGetter)
                {
                    return(CodeBuilder.Indent(indent + 1) + "get\n" + CodeBuilder.Indent(indent + 1) + "{\n" + CodeBuilder.Indent(indent + 2) + getterBody.Replace("\n", "\n" + CodeBuilder.Indent(indent + 2)) + "\n" + CodeBuilder.Indent(indent + 1) + "}");
                }
                else
                {
                    return("get => " + getterBody.Replace("\n", "\n" + CodeBuilder.Indent(indent + 1)) + ";");
                }
            }

            string Setter()
            {
                if (multiStatementSetter)
                {
                    return(CodeBuilder.Indent(indent + 1) + "set \n" + "{\n" + setterBody.Replace("\n", "\n" + CodeBuilder.Indent(indent + 1)) + "\n}");
                }
                else
                {
                    return("set => " + setterBody.Replace("\n", "\n" + CodeBuilder.Indent(indent + 1)) + ";");
                }
            }
        }
Exemple #6
0
 public override string Generate(int indent)
 {
     return(CodeBuilder.Indent(indent) + scope.AsString() + " event " + returnType.Name + " " + name + ";");
 }