Beispiel #1
0
        public override void Write(CodeWriter writer)
        {
            var elements = new List <string>();

            elements.Add(CSharpCodeGenerationUtility.AccessModifierToString(accessModifier));

            if (additionalModifiers != null)
            {
                elements.AddRange(additionalModifiers);
            }

            elements.Add(type);
            elements.Add(name);

            if (initializationStatement != null)
            {
                elements.Add("=");
                elements.Add(initializationStatement);
            }
            else if (innerGenerator != null)
            {
                var innerSb = new StringBuilder();
                innerGenerator.Write(writer.Clone(innerSb));
                elements.Add("=");
                elements.Add(innerSb.ToString());
            }

            writer.AppendLine(string.Join(" ", elements) + ";");
        }
Beispiel #2
0
        public override void Write(CodeWriter writer)
        {
            var elements = new List <string>();

            var accessModifierStr = CSharpCodeGenerationUtility.AccessModifierToString(accessModifier);

            if (accessModifierStr != null)
            {
                elements.Add(accessModifierStr);
            }

            if (additionalModifiers != null)
            {
                foreach (var m in additionalModifiers.Where(x => string.IsNullOrWhiteSpace(x) == false))
                {
                    elements.Add(m.Trim());
                }
            }

            elements.Add("class");

            elements.Add(name);

            if (bases != null)
            {
                var newBases = bases
                               .Where(x => string.IsNullOrWhiteSpace(x) == false)
                               .Select(x => x.Trim())
                               .ToArray();

                if (newBases.Length > 0)
                {
                    elements.Add(":");
                    foreach (var b in newBases)
                    {
                        elements.Add(b);
                    }
                }
            }

            writer.AppendLine(string.Join(" ", elements));
        }
        protected virtual void ConstructModifiers(List <string> outModifiers)
        {
            var accessModifierStr = CSharpCodeGenerationUtility.AccessModifierToString(accessModifier);

            if (isStatic)
            {
                outModifiers.Add("static");
            }
            else if (accessModifierStr != null)
            {
                outModifiers.Add(accessModifierStr);
            }

            if (additionalModifiers != null)
            {
                foreach (var m in additionalModifiers.Where(x => string.IsNullOrWhiteSpace(x) == false))
                {
                    outModifiers.Add(m);
                }
            }
        }