コード例 #1
0
        public TypeToken ParseType(string type)
        {
            // create dummy wraper
            var codeText = string.Concat("class M { ", type, " x; }");

            var code = new CodeText(codeText, this.emptyCodeProject, this.defaultParser);

            CodeDocument codeDocument = null;

            code.Parser.PreParse();
            try
            {
                var requiredNextPass = code.Parser.ParseFile(code, 0, ref codeDocument);
            }
            catch (ArgumentException)
            {
                return null;
            }
            finally
            {
                code.Parser.PostParse();
            }

            var classDecl = codeDocument.DocumentContents.ChildCodeElements.First();
            var fieldDecl = classDecl.ChildCodeElements.First() as Field;
            return fieldDecl.FieldType;
        }
コード例 #2
0
 public static CsDocument ParseCode(string code, CodeProject project)
 {
     var csharpParser = new CsParser();
     var sourceCode = new CodeText(code, project, csharpParser);
     return Parse(sourceCode, project);
 }