Exemple #1
0
        public static IDocumentIndentEngine CreateEngine(string text, OptionSet formatOptions = null, IEnumerable <string> symbols = null)
        {
            var policy = formatOptions;

            if (policy == null)
            {
                policy = FormattingOptionsFactory.CreateMono();

//				policy.IndentPreprocessorDirectives = false;
//				policy.AlignToFirstMethodCallArgument = policy.AlignToFirstIndexerArgument = true;
            }

            var sb     = new StringBuilder();
            int offset = 0;

            for (int i = 0; i < text.Length; i++)
            {
                var ch = text[i];
                if (ch == '$')
                {
                    offset = i;
                    continue;
                }
                sb.Append(ch);
            }

            var document = SourceText.From(sb.ToString());

            var csi = new CSharpIndentEngine(policy)
            {
                EnableCustomIndentLevels = true
            };

            if (symbols != null)
            {
                foreach (var sym in symbols)
                {
                    csi.DefineSymbol(sym);
                }
            }
            var result = new CacheIndentEngine(csi);

            result.Update(document, offset);
            return(result);
        }