public void TestLoadTestModule() { IAddonManager addons = AddonManager.Create(); var testFile = GetTestModulePath(); addons.LoadAssembly(testFile, false); var typeReference = addons.TryGetType(null, "TestModule.TestClassWithOnlyProperties"); Assert.IsNotNull(typeReference); typeReference = addons.TryGetType(null, "TestModule.SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace"); Assert.IsNotNull(typeReference); typeReference = addons.TryGetType(null, "TestModule.SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); var usings = new UsingData[] { new UsingData(-1, addons.Lookup(null, "TestModule")) }; typeReference = addons.TryGetType(usings, "TestClassWithOnlyProperties"); Assert.IsNotNull(typeReference); Assert.AreEqual("TestClassWithOnlyProperties", typeReference.Name); typeReference = addons.TryGetType(usings, "SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); Assert.AreEqual("SubClass", typeReference.Name); usings = new UsingData[] { new UsingData(-1, addons.Lookup(null, "TestModule")), new UsingData(-1, addons.Lookup(null, "TestModule.SubNamespace.Deep")) }; typeReference = addons.TryGetType(usings, "VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); Assert.AreEqual("SubClass", typeReference.Name); //var moduleClass = typeReference as ICodeModuleClass; //Assert.IsNotNull(moduleClass); }
internal static FileBuilder ParseProcedure( IAddonManager addonManager, string[] usings, Type usingType, params string[] content) { if (addonManager == null) { addonManager = AddonManager.Create(); addonManager.AddAssembly(typeof(Math).Assembly, false); addonManager.AddAssembly(typeof(Enumerable).Assembly, false); } addonManager.AddAssembly(AddonManager.StepBroCoreAssembly, true); // Add StepBro.Core always. if (usingType != null) { addonManager.AddAssembly(usingType.Assembly, false); } var contentBuilder = new StringBuilder(); foreach (var s in content) { contentBuilder.AppendLine(s); } var file = new ScriptFile(); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System.Linq")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, typeof(StepBro.Core.DataReport).Namespace)); if (usings != null) { foreach (var u in usings) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, u)); } } if (usingType != null) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, usingType.Namespace)); } var builder = new FileBuilder(new AntlrInputStream(contentBuilder.ToString()), addonManager, file); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.procedureDeclaration(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); if (file.Errors.ErrorCount > 0) { throw new Exception("PARSING ERRORS"); } return(builder); }