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); }
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); }
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); } }
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); } }
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(" ", " ").Replace("\r", "<br />"); sw.Write(output); } } if (eof) break; } sw.WriteLine("</body></html>"); } } Console.WriteLine("Output generated."); Console.ReadLine(); } }
protected override void DoExecute(ParseContext context) { if (!context.Scopes.ContainsType(ScopeTypeCache.DefinitionList)) { OpenScope(new DefinitionListScope(), context); } OpenScope(new DefinitionTermScope(), context); }
public BinaryOperator(Token Source, ParseContext.Operator Operator, Node LHS, Node RHS) : base(Source) { this.Operator = Operator; this.LHS = LHS; this.RHS = RHS; }
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; }
protected override void DoExecute(ParseContext context) { context.Input.Read(3); context.UpdateCurrentChar(); OpenScope(new HorizontalRulerScope(), context); CloseCurrentScope(context); }
public Token(TokenType type, string contents, int index, string text, ParseContext offset) { _type = type; _contents = contents; _index = index; _text = text; _offset = offset; }
protected void CloseParagraphIfNecessary(ParseContext context) { var scope = context.Scopes.PeekOrDefault(); if (scope == null || scope.GetType() != ScopeTypeCache.Paragraph) { return; } CloseCurrentScope(context); }
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;; }
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); }; }
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(); }
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)) { } }
protected override void DoExecute(ParseContext context) { var depth = 1; while (context.Input.Peek() == '!') { depth++; context.Input.Read(); } context.Input.SeekToNonWhitespace(); //ignore spaces/tabs context.UpdateCurrentChar(); OpenScope(new HeaderScope(depth), context); }
protected override sealed void DoExecute(ParseContext context) { var c = GetChar(context); ParagraphStrategy.ExecuteIfSatisfied(context); if (context.CurrentNode != null && context.CurrentNode.Scope.GetType() == ScopeTypeCache.Unescaped) { context.Analyzer.WriteUnescapedChar(c); } else { context.Analyzer.WriteAndEscape(c); } }
protected void OpenScope(IScope scope, ParseContext context) { if (BeforeScopeOpens != null) { BeforeScopeOpens.Invoke(scope, context); } context.Scopes.Push(scope); scope.Open(context.Analyzer); if (AfterScopeOpens != null) { AfterScopeOpens.Invoke(scope, context); } }
protected override sealed void DoExecute(ParseContext context) { var peek = context.Input.Peek(); var functionNameBuilder = new StringBuilder(); while (peek != ButterflyStringReader.NoValue && peek != '|' && peek != ']') { functionNameBuilder.Append((char)context.Input.Read()); peek = context.Input.Peek(); } var closer = context.Input.Read(); //| or ] var name = functionNameBuilder.ToString(); var data = new Dictionary<string, string>(); if (closer != ']') { //read module options peek = context.Input.Peek(); var optionStringBuilder = new StringBuilder(); while (peek != ButterflyStringReader.NoValue) { if (peek == ']') { context.Input.Read(); if (context.Input.Peek() != ']') { //module closer break; } //fallthrough: output a literal "]" } else if (peek == '|') { context.Input.Read(); if (context.Input.Peek() != '|') { ParseOptions(optionStringBuilder.ToString(), data); optionStringBuilder.Clear(); } //fallthrough: output a literal "|" } optionStringBuilder.Append((char)context.Input.Read()); peek = context.Input.Peek(); } //handle the last option if (optionStringBuilder.Length > 0) { ParseOptions(optionStringBuilder.ToString(), data); } } context.UpdateCurrentChar(); OpenAndCloseScope(CreateScope(name, data, context), context); }
protected override void ParseChildNodes(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement) { foreach (HtmlNode current in (System.Collections.Generic.IEnumerable<HtmlNode>)htmlNode.ChildNodes) { this.ParseChildNode(current, resultElement, parseContext, baseFormattingElement); //Log.Info("Current nodetype" + current.OriginalName, this); if (current.OriginalName == "#text") { XElement linereturn = new XElement("SpecialCharacter"); linereturn.SetAttributeValue("Type", "10"); resultElement.Add(linereturn); } } }
protected override ListItemScope GetListItem(ParseContext context) { var lastNode = context.ScopeTree.GetMostRecentNode(context.Scopes.Count); if (lastNode == null || !(lastNode.Scope is ListItemScope)) { #if DEBUG //this shouldn't ever happen if the list parsing is performed correctly throw new InvalidOperationException("Encountered list with no list items"); #else return new ListItemScope(1); #endif } return (ListItemScope)lastNode.Scope; }
protected override void DoExecute(ParseContext context) { OpenScope(new UnparsedScope(), context); var match = unparsedRegex.Match(context.Input.PeekSubstring); if (!match.Success) { throw new ParseException("Unparsed scope never closes"); } var text = match.Groups[1].Value.Replace("]]", "]"); context.Input.Read(match.Value.Length); context.UpdateCurrentChar(); context.Analyzer.WriteAndEscape(text); CloseCurrentScope(context); }
public ITagGroup Get(string group, ParseContext context = null) { var matches = _stack.Where(l => l.Exists(group)).ToList(); if (matches.Count == 1) return matches.Single().Get(group, context); if (matches.Count > 0) { var groups = matches.Select(lib => lib.Get(group,context)).ToList(); var tags = groups.SelectMany(grp => grp.ToList()).ToArray(); return new CombinedTagGroup(group, tags); } if (context != null) { throw TagException.UnkownTagGroup(group).Decorate(context); } return null; }
protected override void DoExecute(ParseContext context) { var peek = context.Input.Peek(); var listText = new StringBuilder(((char)context.CurrentChar).ToString(), 3); while (peek == '*' || peek == '#') { listText.Append((char)context.Input.Read()); peek = context.Input.Peek(); } //ignore whitespace after * or # context.Input.SeekToNonWhitespace(); context.UpdateCurrentChar(); HandleList(listText.ToString(), context); }
public string ExtractText(byte[] data) { var parser = new AutoDetectParser(); var handler = new BodyContentHandler(); var context = new ParseContext(); context.set(parser.getClass(), parser); var metadata = new Metadata(); using (var output = new StringWriter()) { var transformerHandler = CreateTransformerHandler(output); using (var inputStream = TikaInputStream.get(data, metadata)) { parser.parse(inputStream, transformerHandler, metadata, context); inputStream.close(); } return output.toString(); } }
protected override void DoExecute(ParseContext context) { IScope rowScope = new TableRowLineScope(); if (context.Input.Peek() == '{') { context.AdvanceInput(); rowScope = new TableRowScope(); } var cellType = ScopeTypeCache.TableCell; if (context.Input.Peek() == '!') { context.AdvanceInput(); cellType = ScopeTypeCache.TableHeader; } context.Input.SeekToNonWhitespace(); context.UpdateCurrentChar(); if (!context.Scopes.ContainsType(ScopeTypeCache.Table)) { //no tables, so create a new one OpenScope(new TableScope(), context); OpenScope(rowScope, context); } else if (context.Scopes.ContainsType(ScopeTypeCache.TableCell, ScopeTypeCache.TableHeader)) { //close table cell var currentScope = context.Scopes.PeekOrDefault(); if (currentScope == null || (currentScope.GetType() != ScopeTypeCache.TableCell && currentScope.GetType() != ScopeTypeCache.TableHeader)) { throw new ParseException("Cannot close table cell until all containing scopes are closed"); } CloseCurrentScope(context); } else if (!context.Scopes.ContainsType(ScopeTypeCache.TableRow, ScopeTypeCache.TableRowLine)) { OpenScope(rowScope, context); } //figure out if we need to open a new cell or not //criteria: // - not EOL // - we're in a row terminated by a line break and the next char is not a new line (signifying a new row) // - OR we're in a row not terminated by a line break if ( context.Input.Peek() != ButterflyStringReader.NoValue && ( (context.Scopes.ContainsType(ScopeTypeCache.TableRowLine) && context.Input.Peek() != '\n') || context.Scopes.ContainsType(ScopeTypeCache.TableRow) ) ) { OpenScope(cellType == ScopeTypeCache.TableHeader ? (IScope)new TableHeaderScope() : new TableCellScope(), context); } }
protected override void DoExecute(ParseContext context) { OpenScope(new PreformattedScope(GetLanguage(context)), context); //this strategy ignores any formatting //read until }}}} var match = codeRegex.Match(context.Input.PeekSubstring); if (!match.Success) { throw new ParseException("Preformatted scope never closes"); } var text = match.Groups[1].Value; context.Input.Read(match.Value.Length); context.UpdateCurrentChar(); context.Analyzer.WriteAndEscape(text); CloseCurrentScope(context); }
protected override void DoExecute(ParseContext context) { //close paragraphs and table cells/headers while (!context.Scopes.IsEmpty()) { if (!closableScopes.Contains(context.Scopes.Peek().GetType())) { break; } CloseCurrentScope(context); } var currentScope = context.Scopes.PeekOrDefault(); if (currentScope == null || currentScope.GetType() != ScopeTypeCache.TableRow) { throw new ParseException("Cannot close table row until all containing scopes are closed"); } CloseCurrentScope(context); }
private void HandleList(string listStart, ParseContext context) { var depth = listStart.Length; var newScope = listStart.Last() == '*' ? new UnorderedListScope() : (IScope)new OrderedListScope(); //get the number of opened lists var openLists = context.Scopes.Count(IsList); if (openLists == 0) { //new list if (depth > 1) { throw new ParseException("Cannot start a list with a depth greater than one"); } OpenScope(newScope, context); } else { //a list has already been opened var difference = depth - openLists; if (difference == 1) { //start a new list at a higher depth OpenScope(newScope, context); } else if (difference > 1) { throw new ParseException(string.Format( "Nested lists cannot skip levels: expected a depth of less than or equal to {0} but got {1}", openLists + 1, depth )); } else { //verify that the list types match var currentListScope = context.Scopes.First(IsList); if (currentListScope.GetType() != newScope.GetType()) { throw new ParseException(string.Format( "Expected list of type {0} but got {1}", currentListScope.GetName(), newScope.GetName() )); } } } OpenScope(new ListItemScope(depth), context); }
protected virtual XElement CreateImageElement(HtmlNode htmlNode, Item mediaContentItem, ParseContext parseContext, string width, string height) { Item item = parseContext.Database.GetItem(WebConfigHandler.PrintStudioEngineSettings.EngineTemplates + "P_Image"); Item standardValues = item.Template.StandardValues; XElement xElement = RenderItemHelper.CreateXElement("Image", standardValues, parseContext.PrintOptions.IsClient, null); ParseDefinition parseDefinition = parseContext.ParseDefinitions[htmlNode]; if (parseDefinition != null) { this.SetAttributes(xElement, htmlNode, parseDefinition); } xElement.SetAttributeValue("Height", height); xElement.SetAttributeValue("Width", width); xElement.SetAttributeValue("SitecoreMediaID", mediaContentItem.ID.Guid.ToString()); string text = ImageRendering.CreateImageOnServer(parseContext.PrintOptions, mediaContentItem); text = parseContext.PrintOptions.FormatResourceLink(text); xElement.SetAttributeValue("LowResSrc", text); xElement.SetAttributeValue("HighResSrc", text); return xElement; }
public Context(ParseContext parseContext) { Instructions = parseContext.instructions.ToArray(); LexicalEnvironment = parseContext.LexicalEnvironment; Variables = new Dictionary <int, VariableReference>(parseContext.Variables); }
public static T TryParse <T>(ParseContext ctx) { return((T)TryParse(typeof(T), ctx)); }
protected ParametersCompiled ResolveParameters(ParseContext ec, TypeInferenceContext tic, Type delegateType) { if (!TypeManager.IsDelegateType(delegateType)) { return(null); } var delegateParameters = TypeManager.GetParameterData(delegateType.GetMethod("Invoke")); if (HasExplicitParameters) { if (!VerifyExplicitParameters(ec, delegateType, delegateParameters)) { return(null); } return(_scope.Parameters.Clone()); } // // If L has an implicitly typed parameter list we make implicit parameters explicit // Set each parameter of L is given the type of the corresponding parameter in D // if (!VerifyParameterCompatibility(ec, delegateType, delegateParameters, ec.IsInProbingMode)) { return(null); } var ptypes = new Type[_scope.Parameters.Count]; for (int i = 0; i < delegateParameters.Count; i++) { // D has no ref or out parameters if ((delegateParameters.FixedParameters[i].ModifierFlags & Parameter.Modifier.IsByRef) != 0) { return(null); } Type dParam = delegateParameters.Types[i]; // Blablabla, because reflection does not work with dynamic types if (dParam.IsGenericParameter) { dParam = delegateType.GetGenericArguments() [dParam.GenericParameterPosition]; } // // When type inference context exists try to apply inferred type arguments // if (tic != null) { dParam = tic.InflateGenericArgument(dParam); } ptypes[i] = dParam; ((ImplicitLambdaParameter)_scope.Parameters.FixedParameters[i]).ParameterType = dParam; } // TODO : FIX THIS //ptypes.CopyTo(_scope.Parameters.Types, 0); // TODO: STOP DOING THIS _scope.Parameters.Types = ptypes; return(_scope.Parameters); }
protected bool VerifyParameterCompatibility(ParseContext ec, Type delegateType, ParametersCollection invokePd, bool ignoreErrors) { if (_scope.Parameters.Count != invokePd.Count) { if (ignoreErrors) { return(false); } ec.ReportError( 1593, string.Format( "Delegate '{0}' does not take '{1}' arguments.", TypeManager.GetCSharpName(delegateType), _scope.Parameters.Count), Span); return(false); } var hasImplicitParameters = !HasExplicitParameters; var error = false; for (int i = 0; i < _scope.Parameters.Count; ++i) { var pMod = invokePd.FixedParameters[i].ModifierFlags; if (_scope.Parameters.FixedParameters[i].ModifierFlags != pMod && pMod != Parameter.Modifier.Params) { if (ignoreErrors) { return(false); } if (pMod == Parameter.Modifier.None) { ec.ReportError( 1677, string.Format( "Parameter '{0}' should not be declared with the '{1}' keyword.", (i + 1), Parameter.GetModifierSignature(_scope.Parameters.FixedParameters[i].ModifierFlags)), Span); } else { ec.ReportError( 1676, string.Format( "Parameter '{0}' must be declared with the '{1}' keyword.", (i + 1), Parameter.GetModifierSignature(pMod)), Span); } error = true; } if (hasImplicitParameters) { continue; } Type type = invokePd.Types[i]; // We assume that generic parameters are always inflated if (TypeManager.IsGenericParameter(type)) { continue; } if (TypeManager.HasElementType(type) && TypeManager.IsGenericParameter(type.GetElementType())) { continue; } if (invokePd.Types[i] != _scope.Parameters.Types[i]) { if (ignoreErrors) { return(false); } ec.ReportError( 1678, string.Format( "Parameter '{0}' is declared as type '{1}' but should be '{2}'", (i + 1), TypeManager.GetCSharpName(_scope.Parameters.Types[i]), TypeManager.GetCSharpName(invokePd.Types[i])), Span); error = true; } } return(!error); }
protected override bool IsNeedToProcess(ParseContext context, Uri uri) { return(!uri.IsFile && !uri.IsLoopback && !string.IsNullOrWhiteSpace(uri.Host)); }
protected override BareANY DoCreateR2DataTypeInstance(ParseContext context) { return(CodedTypeR2Helper.CreateCEInstance(context.GetExpectedReturnType())); }
protected override CodedTypeR2 <Code> ParseTranslation(XmlElement translationElement, ParseContext newContext, XmlToModelResult result) { BareANY anyResult = new CdR2ElementParser().Parse(newContext, translationElement, result); CodedTypeR2 <Code> translation = anyResult == null ? null : (CodedTypeR2 <Code>)anyResult.BareValue; if (translation != null) { translation.NullFlavorForTranslationOnly = anyResult == null ? null : anyResult.NullFlavor; } return(translation); }
/// <inheritdoc/> public override ulong ReadValue(ref ParseContext parser) { return(parser.ReadUInt64()); }
protected virtual void ParseChildNodes(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement) { foreach (HtmlNode htmlNode1 in (IEnumerable <HtmlNode>)htmlNode.ChildNodes) { this.ParseChildNode(htmlNode1, resultElement, parseContext, baseFormattingElement); } }
static void ParseCode(int code_size, ParseContext context) { var code = context.Code; var metadata = context.Metadata; var visitor = context.Visitor; var start = code.position; var end = start + code_size; while (code.position < end) { var il_opcode = code.ReadByte(); var opcode = il_opcode != 0xfe ? OpCodes.OneByteOpCode [il_opcode] : OpCodes.TwoBytesOpCode [code.ReadByte()]; switch (opcode.OperandType) { case OperandType.InlineNone: visitor.OnInlineNone(opcode); break; case OperandType.InlineSwitch: var length = code.ReadInt32(); var branches = new int [length]; for (int i = 0; i < length; i++) { branches [i] = code.ReadInt32(); } visitor.OnInlineSwitch(opcode, branches); break; case OperandType.ShortInlineBrTarget: visitor.OnInlineBranch(opcode, code.ReadSByte()); break; case OperandType.InlineBrTarget: visitor.OnInlineBranch(opcode, code.ReadInt32()); break; case OperandType.ShortInlineI: if (opcode == OpCodes.Ldc_I4_S) { visitor.OnInlineSByte(opcode, code.ReadSByte()); } else { visitor.OnInlineByte(opcode, code.ReadByte()); } break; case OperandType.InlineI: visitor.OnInlineInt32(opcode, code.ReadInt32()); break; case OperandType.InlineI8: visitor.OnInlineInt64(opcode, code.ReadInt64()); break; case OperandType.ShortInlineR: visitor.OnInlineSingle(opcode, code.ReadSingle()); break; case OperandType.InlineR: visitor.OnInlineDouble(opcode, code.ReadDouble()); break; case OperandType.InlineSig: visitor.OnInlineSignature(opcode, code.GetCallSite(code.ReadToken())); break; case OperandType.InlineString: visitor.OnInlineString(opcode, code.GetString(code.ReadToken())); break; case OperandType.ShortInlineArg: visitor.OnInlineArgument(opcode, code.GetParameter(code.ReadByte())); break; case OperandType.InlineArg: visitor.OnInlineArgument(opcode, code.GetParameter(code.ReadInt16())); break; case OperandType.ShortInlineVar: visitor.OnInlineVariable(opcode, GetVariable(context, code.ReadByte())); break; case OperandType.InlineVar: visitor.OnInlineVariable(opcode, GetVariable(context, code.ReadInt16())); break; case OperandType.InlineTok: case OperandType.InlineField: case OperandType.InlineMethod: case OperandType.InlineType: var member = metadata.LookupToken(code.ReadToken()); switch (member.MetadataToken.TokenType) { case TokenType.TypeDef: case TokenType.TypeRef: case TokenType.TypeSpec: visitor.OnInlineType(opcode, (TypeReference)member); break; case TokenType.Method: case TokenType.MethodSpec: visitor.OnInlineMethod(opcode, (MethodReference)member); break; case TokenType.Field: visitor.OnInlineField(opcode, (FieldReference)member); break; case TokenType.MemberRef: var field_ref = member as FieldReference; if (field_ref != null) { visitor.OnInlineField(opcode, field_ref); break; } var method_ref = member as MethodReference; if (method_ref != null) { visitor.OnInlineMethod(opcode, method_ref); break; } throw new InvalidOperationException(); } break; } } }
public static object TryParse(Type t, ParseContext ctx) { var del = GetTryParseDelegateForType(t); return(del.DynamicInvoke(ctx)); }