private TypePaths CreateTypePaths(Type type) { TypePaths paths = new TypePaths(type); Dijkstra.FindShortestPaths(_allTypes, type, _succRel, paths.RootDist, paths.Preds, _distRel); return(paths); }
public static string Convert(Type SType, TypeDescriptor TTypeD, IList <Type> interTypes, params string[] args) { var TType = TTypeD.CILType; if (SType.Equals(TType)) { return(args[0]); } TypePaths paths = _instance._typePaths[SType]; if (paths.Preds[TType] == null) { throw new NotSupportedException("Don't know any conversion from " + SType.Name + " to " + TType.Name); } Type curT = TType; Stack <MethodInfo> convChain = new Stack <MethodInfo>(); int nargs = args.Length; while (curT != SType) { interTypes.Add(curT); Type preT = paths.Preds[curT]; List <MethodInfo> cands = _converters[preT][curT]; MethodInfo convm = cands.Where(m => m.GetParameters().Length == nargs + 1).FirstOrDefault(); if (convm != null) { convChain.Push(convm); nargs = 1; } else { convm = cands.Where(m => m.GetParameters().Length == 2).FirstOrDefault(); if (convm == null) { throw new NotSupportedException("Don't know any conversion from " + SType.Name + " to " + TType.Name + " given the supplied parameters"); } convChain.Push(convm); } curT = preT; } string[] curArgs = (string[])args.Clone(); foreach (MethodInfo convm in convChain) { if (convm.GetParameters().Length == 2) { curArgs[0] = (string)convm.Invoke(null, new object[] { curArgs[0], TTypeD }); } else { curArgs[0] = (string)convm.Invoke(null, curArgs.Cast <object>().Concat(Enumerable.Repeat(TTypeD, 1)).ToArray()); } } return(curArgs[0]); }