public static T ParseStatement <T>(string statement) where T : INode { MethodDeclaration md = ParseTypeMember <MethodDeclaration>("Sub A()\n " + statement + "\nEnd Sub\n"); Assert.IsTrue(md.Body.Children.Count > 0); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(md.Body.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", md.GetType(), type, md)); return((T)md.Body.Children[0]); }
public static Statement DeepCopy(this Statement right) { MethodDeclaration md = ParseToMethodDeclaration("void A() { " + right.Print() + " }"); if (md.Body.Children.Count == 0) { throw new ApplicationException("There were no statements."); } Type type = typeof(Statement); if (!type.IsAssignableFrom(md.Body.Children[0].GetType())) { throw new ApplicationException(String.Format("Parsed expression was {0} instead of {1} ({2}).", md.GetType(), type, md)); } return((Statement)md.Body.Children[0]); }