Exemplo n.º 1
0
        void IBuilder.Write(ref CodeWriter writer)
        {
            _xmlDoc.Write(ref writer);

            foreach (var attribute in _attributes)
            {
                writer.AppendLine($"[{attribute}]");
            }

            var    type = Type.Trim();
            var    name = Name.Trim();
            string additionalModifier = null;

            if (_virtual)
            {
                additionalModifier = "virtual";
            }
            else if (_override)
            {
                additionalModifier = "override";
            }

            var output = (FieldTypeValue switch
            {
                FieldType.Const => $"{AccessModifier.Code()} const {type} {name}",
                FieldType.ReadOnly => $"{AccessModifier.Code()} readonly {type} {name}",
                _ => additionalModifier is null
                    ? $"{AccessModifier.Code()} {type} {name}"
                    : $"{AccessModifier.Code()} {additionalModifier} {type} {name}"
            }).Trim();
Exemplo n.º 2
0
        internal override void Write(ref CodeWriter writer)
        {
            var output = string.IsNullOrEmpty(ReturnType) ? "void" : ReturnType.Trim();

            if (IsAsync)
            {
                output = $"async {output}";
            }

            if (_override)
            {
                output = $"override {output}";
            }
            else if (_virtual)
            {
                output = $"virtual {output}";
            }
            else if (IsStatic)
            {
                output = $"static {output}";
            }

            var parameters = string.Join(", ", _parameters.Select(x => x.ToString()));

            output = $"{AccessModifier.Code()} {output} {Name}({parameters})";

            _xmlDoc.RemoveUnusedParameters(_parameters);
            _xmlDoc.Write(ref writer);

            foreach (var attribute in _attributes)
            {
                writer.AppendLine($"[{attribute}]");
            }
            using (writer.Block(output.Trim(), _constraints.ToArray()))
            {
                _methodBodyWriter?.Invoke(writer);
            }
        }