// (Integer, "3") return object of new Integer(3) public object Parse(Type c, string s) { Type d = ReflectionUtilities.BoxClass(c); foreach (Type e in ReflectionUtilities.ClassAndAncestors(d)) { // get all the super classes of Integer for example string name = ReflectionUtilities.GetAssemblyQualifiedName(e); if (parsers.ContainsKey(name)) { object ret = Parse(name, s); // check if ret can be cast as c if (c.IsAssignableFrom(ret.GetType())) { return(ret); } else { var ex = new InvalidCastException("Cannot cast from " + ret.GetType() + " to " + c); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } } } return(Parse(d.Name, s)); }
public object Parse(Type c, String s) { Type d = ReflectionUtilities.BoxClass(c); foreach (Type e in ReflectionUtilities.ClassAndAncestors(d)) { string name = e.FullName; if (parsers.ContainsKey(name)) { object ret = Parse(name, s); if (c.IsAssignableFrom(ret.GetType())) { return(ret); } else { throw new InvalidCastException("Cannot cast from " + ret.GetType() + " to " + c); } } } return(Parse(d.Name, s)); }