public void TestGenerics() { // Create the open class<T> which contains a List<T> GenericType genericClassArg = new GenericType("T"); Class openClass = new Class(); openClass.Name = "OpenClass"; openClass.Namespace = "Namespace"; openClass.DeclaredGenericArguments.Add(genericClassArg); TypeSpecifier listType = TypeSpecifier.FromType(typeof(List <>)); Assert.AreEqual(listType.GenericArguments.Count, 1); listType.GenericArguments[0] = genericClassArg; Method openMethod = new Method("OpenMethod"); // Add open list parameter TypeNode listTypeNode = new TypeNode(openMethod, listType); openMethod.MainReturnNode.AddReturnType(); GraphUtil.ConnectTypePins(listTypeNode.OutputTypePins[0], openMethod.MainReturnNode.InputTypePins[0]); GraphUtil.ConnectExecPins(openMethod.EntryNode.InitialExecutionPin, openMethod.ReturnNodes.First().ReturnPin); openClass.Methods.Add(openMethod); // Create the closed class which contains a List<string> Class closedClass = new Class(); closedClass.Name = "ClosedClass"; closedClass.Namespace = "Namespace"; TypeSpecifier closedListType = TypeSpecifier.FromType <string>(); Method closedMethod = new Method("ClosedMethod"); // Add closed list parameter TypeNode closedListTypeNode = new TypeNode(closedMethod, closedListType); closedMethod.MainReturnNode.AddReturnType(); GraphUtil.ConnectTypePins(closedListTypeNode.OutputTypePins[0], closedMethod.MainReturnNode.InputTypePins[0]); GraphUtil.ConnectExecPins(closedMethod.EntryNode.InitialExecutionPin, closedMethod.ReturnNodes.First().ReturnPin); closedClass.Methods.Add(closedMethod); // Translate the classes ClassTranslator translator = new ClassTranslator(); string openClassTranslated = translator.TranslateClass(openClass); string closedClassTranslated = translator.TranslateClass(closedClass); }
public static void CompileNetPrintsClass(ClassGraph classGraph, string outputPath) { ClassTranslator classTranslator = new ClassTranslator(); string translated = classTranslator.TranslateClass(classGraph); File.WriteAllText(outputPath, translated); }
public IEnumerable <string> GetGeneratedCode() { ClassTranslator classTranslator = new ClassTranslator(); foreach (var project in dte.Solution.Projects.OfType <EnvDTE.Project>()) { foreach (var projectItem in project.ProjectItems.OfType <EnvDTE.ProjectItem>()) { string fullPath = projectItem.Properties?.Item("FullPath")?.Value as string; if (fullPath != null && fullPath.EndsWith(".netpc")) { ClassGraph classGraph = NetPrints.Serialization.SerializationHelper.LoadClass(fullPath); yield return(classTranslator.TranslateClass(classGraph)); } } } }
public void TestClassTranslation() { string translated = classTranslator.TranslateClass(cls); }