コード例 #1
0
        internal GenerationResult Generate()
        {
            _usingsResult = new GenerationResult(_file);
            _parametersResult = new GenerationResult(_file);
            _inheritsResult = new GenerationResult(_file);
            _transformTextResult = new GenerationResult(_file);
            _featureResult = new GenerationResult(_file);
            _file.ProcessDescendants(this);

            var result = new GenerationResult(_file);
            StringBuilder builder = result.Builder;

            string ns = GetNamespace();
            bool hasNamespace = !String.IsNullOrEmpty(ns);
            if (hasNamespace) {
                builder.AppendFormat("namespace {0} {{", ns);
                builder.AppendLine();
            }
            builder.AppendLine("using System;");
            result.Append(_usingsResult);
            builder.AppendFormat("[{0}]", PsiManager.SyntheticAttribute);
            builder.AppendLine();

            var className = GetClassName();
            builder.AppendFormat("public partial class {0} : ", className);
            if (_inheritsResult.Builder.Length == 0)
                builder.Append(DefaultBaseClassName);
            else {
                result.Append(_inheritsResult);
            }
            builder.AppendLine(" {");

            builder.AppendFormat("[{0}] private static string __\x200CToString(object value) {{ return null; }}", PsiManager.SyntheticAttribute);
            builder.AppendLine();
            if (_hasHost)
                builder.AppendLine("public virtual Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost Host { get; set; }");
            result.Append(_parametersResult);
            //TODO: check if already generated on disk
            //builder.AppendFormat("[System.CodeDom.Compiler.GeneratedCodeAttribute] public override string {0}() {{", TransformTextMethodName);
            builder.AppendFormat("[System.CodeDom.Compiler.GeneratedCodeAttribute] public string __\x200C{0}() {{", TransformTextMethodName);
            builder.AppendLine();
            result.Append(_transformTextResult);
            builder.AppendLine();
            builder.AppendLine("return GenerationEnvironment.ToString();");
            builder.AppendLine("}");
            result.Append(_featureResult);
            builder.AppendLine("}");
            if (hasNamespace)
                builder.AppendLine("}");
            return result;
        }
コード例 #2
0
        internal GenerationResult Generate()
        {
            _usingsResult = new GenerationResult(_file);
            _parametersResult = new GenerationResult(_file);
            _transformTextResult = new GenerationResult(_file);
            _featureResult = new GenerationResult(_file);
            _file.ProcessDescendants(this);

            var result = new GenerationResult(_file);
            StringBuilder builder = result.Builder;

            string ns = GetNamespace();
            bool hasNamespace = !String.IsNullOrEmpty(ns);
            if (hasNamespace) {
                builder.AppendFormat("namespace {0} {{", ns);
                builder.AppendLine();
            }
            builder.AppendLine("using System;");
            result.Append(_usingsResult);
            builder.AppendFormat("[{0}]", PsiManager.SyntheticAttribute);
            builder.AppendLine();
            builder.AppendLine("public class Generated\x200CTransformation : Microsoft.VisualStudio.TextTemplating.TextTransformation {");
            builder.AppendFormat("[{0}] private static string __\x200CToString(object value) {{ return null; }}", PsiManager.SyntheticAttribute);
            builder.AppendLine();
            if (_hasHost)
                builder.AppendLine("public virtual Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost Host { get; set; }");
            result.Append(_parametersResult);
            builder.AppendLine("[System.CodeDom.Compiler.GeneratedCodeAttribute] public override string TransformText() {");
            result.Append(_transformTextResult);
            builder.AppendLine();
            builder.AppendLine("return GenerationEnvironment.ToString();");
            builder.AppendLine("}");
            result.Append(_featureResult);
            builder.AppendLine("}");
            if (hasNamespace)
                builder.AppendLine("}");
            return result;
        }