Пример #1
0
        public ParsedContext Parse(string contextFile)
        {
            if (string.IsNullOrEmpty(contextFile) || !File.Exists(contextFile))
            {
                return(null);
            }

            var code       = File.ReadAllText(contextFile);
            var syntaxTree = CSharpSyntaxTree.ParseText(code);
            var root       = (CompilationUnitSyntax)syntaxTree.GetRoot();

            var visitor = new ContextVisitor();

            visitor.Visit(root);

            var parsedContext = visitor.ParsedContext;

            if (parsedContext != null)
            {
                _logger.LogDebug(
                    "Parsed Context File: '{0}'; Entities: {1}",
                    Path.GetFileName(contextFile),
                    parsedContext.Properties.Count);
            }

            return(parsedContext);
        }
Пример #2
0
        public ParsedContext ParseCode(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(null);
            }

            var syntaxTree = CSharpSyntaxTree.ParseText(code);
            var root       = (CompilationUnitSyntax)syntaxTree.GetRoot();

            var visitor = new ContextVisitor();

            visitor.Visit(root);

            var parsedContext = visitor.ParsedContext;

            if (parsedContext == null)
            {
                return(null);
            }

            this._logger.LogDebug(
                "Parsed Context Class: {0}; Entities: {1}",
                parsedContext.ContextClass,
                parsedContext.Properties.Count);

            return(parsedContext);
        }