/// <summary>Finds which type of fragment will accept and handle the given character.</summary> /// <param name="peek">The character to find a handler for.</param> /// <returns>The handler which will deal with this character. May also be told to stop if no handler is available.</returns> public static Handler Find(char peek) { if (peek == StringReader.NULL || BracketFragment.IsEndBracket(peek) != -1) { return(Handler.Stop); } else if (BracketFragment.WillHandle(peek)) { return(Handler.Brackets); } else if (StringFragment.WillHandle(peek)) { return(Handler.String); } else if (TypeFragment.WillHandle(peek)) { return(Handler.Type); } else if (OperatorFragment.WillHandle(peek)) { return(Handler.Operator); } else if (PropertyFragment.WillHandle(peek)) { return(Handler.Property); } else if (NumberFragment.WillHandle(peek)) { return(Handler.Number); } return(Handler.Variable); }
/// <summary>Retrieves a section of the reference from the given fragment. /// This is required as a reference is likely to be a chain of property fragments which must /// be followed to retrieve the full reference.</summary> /// <param name="usingName">The current fragment to handle.</param> /// <returns>The reference as a string, e.g. 'System.Generics'</returns> private string ParseReference(CodeFragment usingName) { if (usingName == null) { return(""); } Type type = usingName.GetType(); if (type == typeof(VariableFragment)) { // e.g. using System; return(((VariableFragment)usingName).Value); } else if (type == typeof(PropertyFragment)) { // e.g. using System.Generic; // Follow the stack of 'of' until you hit null. PropertyFragment property = ((PropertyFragment)usingName); string text = property.Value; string propertyOf = ParseReference(property.of); if (propertyOf != "") { return(propertyOf + "." + text); } else { return(text); } } return(""); }