public ICsClassHierarchy GetDefaultClassHierarchy(string[] assemblies, Type[] parameterParsers) { SetValuedKey key = new SetValuedKey(assemblies, parameterParsers); ICsClassHierarchy ret = null; defaultClassHierarchy.TryGetValue(key, out ret); if (ret == null) { ret = new ClassHierarchyImpl(assemblies, parameterParsers); defaultClassHierarchy.Add(key, ret); } return ret; }
public ICsClassHierarchy GetDefaultClassHierarchy(string[] assemblies, Type[] parameterParsers) { SetValuedKey key = new SetValuedKey(assemblies, parameterParsers); ICsClassHierarchy ret = null; defaultClassHierarchy.TryGetValue(key, out ret); if (ret == null) { ret = new ClassHierarchyImpl(assemblies, parameterParsers); defaultClassHierarchy.Add(key, ret); } return(ret); }
public static void GetNodeFromHierarchy(ClassHierarchyImpl classHierarchyImpl) { IClassNode timerClassNode = (IClassNode)classHierarchyImpl.GetNode("Com.Microsoft.Tang.Examples.Timer"); INode secondNode = classHierarchyImpl.GetNode("Com.Microsoft.Tang.Examples.Timer+Seconds"); string classNmae = timerClassNode.GetFullName(); //Type clazz = classHierarchyImpl.loader.GetType(classNmae); IList<IConstructorDef> constuctorDefs = timerClassNode.GetAllConstructors(); foreach (IConstructorDef consDef in constuctorDefs) { IList<IConstructorArg> consArgs = consDef.GetArgs(); foreach (IConstructorArg arg in consArgs) { string argName = arg.GetName(); string argTypeName = arg.Gettype(); Type nt = Type.GetType(argName); INode argNode = classHierarchyImpl.GetNode(nt); } } }
public void TestTimerWithClassHierarchy() { Type timerType = typeof(Com.Microsoft.Tang.Examples.Timer); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds"); ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder((ICsClassHierarchy)classHierarchyImpl); cb.BindNamedParameter(namedParameter, "2"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var timer = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType); Assert.IsNotNull(timer); System.Console.WriteLine("Tick..."); timer.sleep(); System.Console.WriteLine("Tock..."); }
public static void CreateClassHierarchy() { ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file); GetNodeFromHierarchy(classHierarchyImpl); }
public void TestTimerConfigurationWithClassHierarchy() { Type timerType = typeof(Com.Microsoft.Tang.Examples.Timer); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds"); ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(classHierarchyImpl); cb.BindNamedParameter(namedParameter, "1"); IConfiguration conf = cb.Build(); ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt"); IDictionary<string, string> p = ReadFromFile("timerConfH.txt"); ITang tang1 = TangFactory.GetTang(); ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { file }); ConfigurationFile.AddConfiguration(cb1, "timerConfH.txt"); IConfiguration conf1 = cb1.Build(); IInjector injector = tang1.NewInjector(conf1); var timer = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType); Assert.IsNotNull(timer); timer.sleep(); }