当前位置: 首页>>代码示例>>C#>>正文


C# ParseContext类代码示例

本文整理汇总了C#中ParseContext的典型用法代码示例。如果您正苦于以下问题:C# ParseContext类的具体用法?C# ParseContext怎么用?C# ParseContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParseContext类属于命名空间,在下文中一共展示了ParseContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindDependency

 private static void BindDependency(Type type, string dependencyName, string dependencyText, ParseContext parseContext)
 {
     var serviceConstructor = type.GetConstructor();
     if (!serviceConstructor.isOk)
     {
         var message = string.Format("type [{0}] has ", type.FormatName());
         throw new SimpleContainerException(message + serviceConstructor.errorMessage);
     }
     var formalParameter = serviceConstructor.value.GetParameters().SingleOrDefault(x => x.Name == dependencyName);
     if (formalParameter == null)
     {
         const string message = "type [{0}] has no dependency [{1}]";
         throw new SimpleContainerException(string.Format(message, type.FormatName(), dependencyName));
     }
     var targetType = formalParameter.ParameterType;
     var underlyingType = Nullable.GetUnderlyingType(targetType);
     if (underlyingType != null)
         targetType = underlyingType;
     IConvertible convertible = dependencyText;
     object parsedValue;
     try
     {
         parsedValue = convertible.ToType(targetType, CultureInfo.InvariantCulture);
     }
     catch (Exception e)
     {
         const string message = "can't parse [{0}.{1}] from [{2}] as [{3}]";
         throw new SimpleContainerException(string.Format(message, type.FormatName(), dependencyName,
             dependencyText, formalParameter.ParameterType.FormatName()), e);
     }
     parseContext.GetServiceBuilder(type).BindDependency(dependencyName, parsedValue);
 }
开发者ID:shparun,项目名称:simple-container,代码行数:32,代码来源:FileConfigurationParser.cs

示例2: Extract

        public TextExtractionResult Extract(Func<Metadata, InputStream> streamFactory)
        {
            try
            {
                var parser = new AutoDetectParser();
                var metadata = new Metadata();
                var parseContext = new ParseContext();

                //use the base class type for the key or parts of Tika won't find a usable parser
                parseContext.set(typeof(Parser), parser);

                var content = new System.IO.StringWriter();
                var contentHandlerResult = new TextExtractorContentHandler(content);

                using (var inputStream = streamFactory(metadata))
                {
                    try
                    {
                        parser.parse(inputStream, contentHandlerResult, metadata, parseContext);
                    }
                    finally
                    {
                        inputStream.close();
                    }
                }

                return AssembleExtractionResult(content.ToString(), metadata);
            }
            catch (Exception ex)
            {
                throw new TextExtractionException("Extraction failed.", ex);
            }
        }
开发者ID:KevM,项目名称:tikaondotnet,代码行数:33,代码来源:TextExtractor.cs

示例3: CreateScope

        protected override IScope CreateScope(string name, IDictionary<string, string> data, ParseContext context)
        {
            var module = context.ModuleFactory.Create(name);
            module.Load(data);

            return new ModuleScope(module);
        }
开发者ID:tmont,项目名称:butterfly,代码行数:7,代码来源:ModuleStrategy.cs

示例4: ParseNode

        public override void ParseNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement)
        {
            XElement xElement = null;
            HtmlAttribute htmlAttribute = htmlNode.Attributes["src"];
            if (htmlAttribute != null)
            {
                MediaItem mediaItem = this.GetMediaItem(htmlAttribute.Value);
                if (mediaItem != null)
                {
                    string text;
                    string text2;
                    StyleParser.ParseDimensions(htmlNode, out text, out text2);
                    if (string.IsNullOrEmpty(text))
                    {
                        text = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Width"], true);
                    }
                    if (string.IsNullOrEmpty(text2))
                    {
                        text2 = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Height"], true);
                    }

                    xElement = this.CreateInlineElement(text, text2);
                    XElement content = this.CreateImageElement(htmlNode, mediaItem, parseContext, text, text2);
                    xElement.Add(content);
                }
            }
            if (xElement != null)
            {
                resultElement.Add(xElement);
            }
        }
开发者ID:ravikumhar,项目名称:Sitecore.PxM.Toolbox,代码行数:31,代码来源:CustomImageParser.cs

示例5: Main

        static void Main(string[] args)
        {
            string[] IgnoreClassifiers = new string[] { "Whitespace"};
            //var parser = DynamicParser.LoadFromMgx("M.mgx", "Microsoft.M.MParser");
            var parser = DynamicParser.LoadFromMgx("Mg.mgx", "Microsoft.M.Grammar.MGrammar");
            using (var sr = new StreamReader("rockfordauth.mg"))
            using (var parseContext = new ParseContext(parser.Lexer,
                                                       parser.Parser,
                                                       parser.GraphBuilder,
                                                       ErrorReporter.Standard,
                                                       "test.M"))
            {
                var lexerReader = new LexerReader();
                if (lexerReader.Open(parseContext, sr, true))
                {
                    using (StreamWriter sw = new StreamWriter("output.html"))
                    {
                       sw.WriteLine("<html><head><style>body { background-color: #333333; color: white; font-family: Consolas; } .Delimiter { color: #ddd; } .Keyword { color: #6dcff6; font-weight: bold; } .Literal { color: #10cc20; }</style></head><body>");
                        bool eof = false;
                        while (true)
                        {
                            var tokens = lexerReader.Read();
                            foreach (var token in tokens)
                            {
                                object[] tokenInfos = parser.GetTokenInfo(token.Tag);
                                ClassificationAttribute classificationAttribute = null;
                                if (tokenInfos != null && tokenInfos.Length > 0)
                                {
                                    classificationAttribute = tokenInfos[0] as ClassificationAttribute;
                                }

                                if (token.Description.Equals("EOF")) // TODO: Match against the EOF token if its public
                                {
                                    eof = true;
                                    break;
                                }
                                if (classificationAttribute != null &&
                                    !IgnoreClassifiers.Contains(classificationAttribute.Classification))
                                {
                                    sw.Write(string.Format("<span class=\"{0}\">{1}</span>",
                                        classificationAttribute.Classification,
                                        token.GetTextString()));
                                }
                                else
                                {
                                    string output = token.GetTextString().Replace(" ", "&nbsp;").Replace("\r", "<br />");
                                    sw.Write(output);
                                }
                            }
                            if (eof)
                                break;
                        }
                        sw.WriteLine("</body></html>");
                    }
                }
                Console.WriteLine("Output generated.");
                Console.ReadLine();
            }
        }
开发者ID:larsw,项目名称:larsw.msyntaxhighlighter,代码行数:59,代码来源:Program.cs

示例6: DoExecute

        protected override void DoExecute(ParseContext context)
        {
            context.Input.Read(3);
            context.UpdateCurrentChar();

            OpenScope(new HorizontalRulerScope(), context);
            CloseCurrentScope(context);
        }
开发者ID:tmont,项目名称:butterfly,代码行数:8,代码来源:HorizontalRulerStrategy.cs

示例7: BinaryOperator

        public BinaryOperator(Token Source, ParseContext.Operator Operator,
			Node LHS, Node RHS)
            : base(Source)
        {
            this.Operator = Operator;
            this.LHS = LHS;
            this.RHS = RHS;
        }
开发者ID:Blecki,项目名称:EtcScript,代码行数:8,代码来源:BinaryOperation.cs

示例8: DoExecute

        protected override void DoExecute(ParseContext context)
        {
            if (!context.Scopes.ContainsType(ScopeTypeCache.DefinitionList)) {
                OpenScope(new DefinitionListScope(), context);
            }

            OpenScope(new DefinitionTermScope(), context);
        }
开发者ID:tmont,项目名称:butterfly,代码行数:8,代码来源:DefinitionListStrategy.cs

示例9: Token

 public Token(TokenType type, string contents, int index, string text, ParseContext offset)
 {
     _type = type;
     _contents = contents;
     _index = index;
     _text = text;
     _offset = offset;
 }
开发者ID:rslijp,项目名称:sharptiles,代码行数:8,代码来源:Token.cs

示例10: IsSatisfiedBy

        public bool IsSatisfiedBy(ParseContext context)
        {
            if (chars.Length == 1) {
                return chars[0] == context.CurrentChar;
            }

            return (char)context.CurrentChar + context.Input.Peek(chars.Length - 1) == chars;
        }
开发者ID:tmont,项目名称:butterfly,代码行数:8,代码来源:ExactCharMatchSatisfier.cs

示例11: CloseParagraphIfNecessary

        protected void CloseParagraphIfNecessary(ParseContext context)
        {
            var scope = context.Scopes.PeekOrDefault();
            if (scope == null || scope.GetType() != ScopeTypeCache.Paragraph) {
                return;
            }

            CloseCurrentScope(context);
        }
开发者ID:tmont,项目名称:butterfly,代码行数:9,代码来源:ScopeDrivenStrategy.cs

示例12: Select

		public override void Select(StatementSink store) {
			ParseContext context = new ParseContext();
			context.source = new MyReader(sourcestream);
			context.store = GetDupCheckSink(store);
			context.namespaces = namespaces;
			context.namedNode = new UriMap();
			context.anonymous = new Hashtable();
			context.meta = Meta;
			
			while (ReadStatement(context)) { }
		}
开发者ID:AminBonyadUni,项目名称:facedetect-f-spot,代码行数:11,代码来源:N3Parser.cs

示例13: GetLanguage

        protected string GetLanguage(ParseContext context)
        {
            var languageBuilder = new StringBuilder();
            context.AdvanceInput();
            while (context.CurrentChar != '\n' && context.CurrentChar != ButterflyStringReader.NoValue) {
                languageBuilder.Append((char)context.CurrentChar);
                context.AdvanceInput();
            }

            return languageBuilder.ToString();
        }
开发者ID:tmont,项目名称:butterfly,代码行数:11,代码来源:OpenPreformattedStrategy.cs

示例14: Parse

 public static Action<ContainerConfigurationBuilder> Parse(Type[] types, string fileName)
 {
     var parseItems = SplitWithTrim(File.ReadAllText(fileName).Replace("\r\n", "\n"), "\n").Select(Parse).ToArray();
     var typesMap = types.ToLookup(x => x.Name);
     return delegate(ContainerConfigurationBuilder builder)
     {
         var context = new ParseContext(builder.RegistryBuilder, typesMap);
         foreach (var item in parseItems)
             item(context);
     };
 }
开发者ID:shparun,项目名称:simple-container,代码行数:11,代码来源:FileConfigurationParser.cs

示例15: Get

 public ITagGroup Get(string group, ParseContext context=null)
 {
     if (_tags.ContainsKey(group))
     {
         return _tags[group];
     }
     if (context != null) {
         throw TagException.UnkownTagGroup(group).Decorate(context);
     }
     return null;;
 }
开发者ID:rslijp,项目名称:sharptiles,代码行数:11,代码来源:TagLib.cs


注:本文中的ParseContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。