You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/02/05 22:05:57 UTC
[36/51] [partial] incubator-reef git commit: [REEF-131] Towards the
new .Net project structure This is to change .Net project structure for Tang,
Wake, REEF utilities, Common and Driver:
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestLegacyConstructors.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestLegacyConstructors.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestLegacyConstructors.cs
new file mode 100644
index 0000000..9bc860e
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestLegacyConstructors.cs
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tests.Tang
+{
+ [TestClass]
+ public class TestLegacyConstructors
+ {
+ static ITang tang;
+
+ [TestInitialize()]
+ public void TestSetup()
+ {
+ tang = TangFactory.GetTang();
+ }
+
+ [TestMethod]
+ public void TestLegacyConstructor()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+
+ IList<string> constructorArg = new List<string>();
+ constructorArg.Add(ReflectionUtilities.GetAssemblyQualifiedName(typeof(int)));
+ constructorArg.Add(ReflectionUtilities.GetAssemblyQualifiedName(typeof(string)));
+ cb.RegisterLegacyConstructor(ReflectionUtilities.GetAssemblyQualifiedName(typeof(LegacyConstructor)), constructorArg);
+ //cb.Bind(typeof(LegacyConstructor), typeof(LegacyConstructor));
+ cb.BindImplementation(GenericType<LegacyConstructor>.Class, GenericType<LegacyConstructor>.Class);
+
+ IInjector i = tang.NewInjector(cb.Build());
+ i.BindVolatileInstance(GenericType<int>.Class, 42);
+ i.BindVolatileInstance(GenericType<string>.Class, "The meaning of life is ");
+ LegacyConstructor l = i.GetInstance<LegacyConstructor>();
+ Assert.AreEqual(42, l.X);
+ Assert.AreEqual("The meaning of life is ", l.Y);
+ }
+ }
+
+ class LegacyConstructor
+ {
+ public LegacyConstructor(int x, string y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
+ public int X { get; set; }
+
+ public string Y { get; set; }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestTang.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestTang.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestTang.cs
new file mode 100644
index 0000000..df18b7a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestTang.cs
@@ -0,0 +1,1160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Reflection;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Tang.Exceptions;
+using Org.Apache.REEF.Tang.Implementations;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Types;
+using Org.Apache.REEF.Tang.Util;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Examples;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+using Org.Apache.REEF.Tang.Implementations.InjectionPlan;
+
+namespace Org.Apache.REEF.Tang.Tests.Tang
+{
+ [TestClass]
+ public class TestTang
+ {
+ private static ITang tang;
+
+ private static Assembly asm = null;
+
+ [ClassInitialize]
+ public static void ClassSetup(TestContext context)
+ {
+ asm = Assembly.Load(FileNames.Examples);
+ }
+
+ [ClassCleanup]
+ public static void ClassCleanup()
+ {
+ }
+
+ [TestInitialize()]
+ public void TestSetup()
+ {
+ MustBeSingleton.alreadyInstantiated = false;
+ tang = TangFactory.GetTang();
+ }
+
+ [TestCleanup()]
+ public void TestCleanup()
+ {
+ }
+
+ [TestMethod]
+ public void TestSingleton()
+ {
+ IInjector injector = tang.NewInjector();
+ Assert.IsNotNull(injector.GetInstance(typeof (TwoSingletons)));
+ Assert.IsNotNull(injector.GetInstance(typeof (TwoSingletons)));
+ }
+
+ [TestMethod]
+ public void TestNotSingleton()
+ {
+ TwoSingletons obj = null;
+ Assert.IsNotNull(tang.NewInjector().GetInstance(typeof (TwoSingletons)));
+ try
+ {
+ obj = (TwoSingletons) tang.NewInjector().GetInstance(typeof (TwoSingletons));
+ }
+ catch (InjectionException)
+ {
+
+ }
+ Assert.IsNull(obj);
+ }
+
+ [TestMethod]
+ public void TestRepeatedAmbiguousArgs()
+ {
+ INode node = null;
+ try
+ {
+ ICsConfigurationBuilder t = tang.NewConfigurationBuilder();
+ node =
+ t.GetClassHierarchy()
+ .GetNode(ReflectionUtilities.GetAssemblyQualifiedName(typeof (RepeatedAmbiguousArgs)));
+ }
+ catch (ClassHierarchyException)
+ {
+ }
+ Assert.IsNull(node);
+ }
+
+ [TestMethod]
+ public void TestRepeatedOKArgs()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<RepeatedNamedArgs.A, Int32>(GenericType<RepeatedNamedArgs.A>.Class, "1");
+ cb.BindNamedParameter<RepeatedNamedArgs.B, Int32>(GenericType<RepeatedNamedArgs.B>.Class, "2");
+
+ IInjector injector = tang.NewInjector(cb.Build());
+ injector.GetInstance(typeof (RepeatedNamedArgs));
+ }
+
+ // NamedParameter A has no default_value, so this should throw.
+ [TestMethod]
+ public void TestOneNamedFailArgs()
+ {
+ string msg = null;
+ try
+ {
+ tang.NewInjector().GetInstance<OneNamedSingletonArgs>();
+ msg =
+ "Cannot inject OneNamedSingletonArgs: cOneNamedSingletonArgs missing argument OneNamedSingletonArgs+A";
+ }
+ catch (Exception)
+ {
+ }
+ Assert.IsNull(msg);
+ }
+
+ // NamedParameter A get's bound to a volatile, so this should succeed.
+ [TestMethod]
+ public void TestOneNamedSingletonOKArgs()
+ {
+ IInjector i = tang.NewInjector();
+ i.BindVolatileParameter(GenericType<OneNamedSingletonArgs.A>.Class, i.GetInstance<MustBeSingleton>());
+ OneNamedSingletonArgs o = i.GetInstance<OneNamedSingletonArgs>();
+ Assert.IsNotNull(o);
+ }
+
+
+ [TestMethod]
+ public void TestRepeatedNamedArgs()
+ {
+ IInjector i = tang.NewInjector();
+ i.BindVolatileParameter(GenericType<RepeatedNamedSingletonArgs.A>.Class,
+ (MustBeSingleton) i.GetInstance(typeof (MustBeSingleton)));
+ i.BindVolatileParameter(GenericType<RepeatedNamedSingletonArgs.B>.Class,
+ (MustBeSingleton) i.GetInstance(typeof (MustBeSingleton)));
+ i.GetInstance(typeof (RepeatedNamedSingletonArgs));
+ }
+
+ [TestMethod]
+ public void testStraightforwardBuild()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<Interf>.Class, GenericType<Impl>.Class);
+ tang.NewInjector(cb.Build()).GetInstance(typeof (Interf));
+ }
+
+ [TestMethod]
+ public void TestOneNamedStringArgCantRebind()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ OneNamedStringArg a =
+ (OneNamedStringArg) tang.NewInjector(cb.Build()).GetInstance(typeof (OneNamedStringArg));
+ Assert.AreEqual("default", a.s);
+ cb.BindNamedParameter<OneNamedStringArg.A, string>(GenericType<OneNamedStringArg.A>.Class, "not default");
+ IInjector i = tang.NewInjector(cb.Build());
+ Assert.AreEqual("not default", ((OneNamedStringArg) i.GetInstance(typeof (OneNamedStringArg))).s);
+ string msg = null;
+ try
+ {
+ i.BindVolatileParameter(GenericType<OneNamedStringArg.A>.Class, "volatile");
+ msg =
+ "Attempt to re-bind named parameter Org.Apache.REEF.Tang.OneNamedStringArg$A. Old value was [not default] new value is [volatile]";
+ }
+ catch (Exception)
+ {
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestOneNamedStringArgBind()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ OneNamedStringArg a = tang.NewInjector(cb.Build()).GetInstance<OneNamedStringArg>();
+ Assert.AreEqual("default", a.s);
+ cb.BindNamedParameter<OneNamedStringArg.A, string>(GenericType<OneNamedStringArg.A>.Class, "not default");
+ IInjector i = tang.NewInjector(cb.Build());
+ Assert.AreEqual("not default", i.GetInstance<OneNamedStringArg>().s);
+ }
+
+ [TestMethod]
+ public void TestOneNamedStringArgVolatile()
+ {
+ OneNamedStringArg a = tang.NewInjector().GetInstance<OneNamedStringArg>();
+ Assert.AreEqual("default", a.s);
+ IInjector i = tang.NewInjector();
+ i.BindVolatileParameter(GenericType<OneNamedStringArg.A>.Class, "volatile");
+ Assert.AreEqual("volatile", i.GetInstance<OneNamedStringArg>().s);
+ }
+
+ [TestMethod]
+ public void TestTwoNamedStringArgsBind()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ TwoNamedStringArgs a = tang.NewInjector(cb.Build()).GetInstance<TwoNamedStringArgs>();
+ Assert.AreEqual("defaultA", a.a);
+ Assert.AreEqual("defaultB", a.b);
+ cb.BindNamedParameter<TwoNamedStringArgs.A, string>(GenericType<TwoNamedStringArgs.A>.Class, "not defaultA");
+ cb.BindNamedParameter<TwoNamedStringArgs.B, string>(GenericType<TwoNamedStringArgs.B>.Class, "not defaultB");
+ IInjector i = tang.NewInjector(cb.Build());
+ Assert.AreEqual("not defaultA",
+ i.GetInstance<TwoNamedStringArgs>().a);
+ Assert.AreEqual("not defaultB",
+ i.GetInstance<TwoNamedStringArgs>().b);
+ }
+
+ [TestMethod]
+ public void TestTwoNamedStringArgsBindVolatile()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ TwoNamedStringArgs a = tang.NewInjector(cb.Build()).GetInstance<TwoNamedStringArgs>();
+ Assert.AreEqual("defaultA", a.a);
+ Assert.AreEqual("defaultB", a.b);
+ IInjector i = tang.NewInjector(cb.Build());
+ i.BindVolatileParameter(GenericType<TwoNamedStringArgs.A>.Class, "not defaultA");
+ i.BindVolatileParameter(GenericType<TwoNamedStringArgs.B>.Class, "not defaultB");
+ Assert.AreEqual("not defaultA",
+ i.GetInstance<TwoNamedStringArgs>().a);
+ Assert.AreEqual("not defaultB",
+ i.GetInstance<TwoNamedStringArgs>().b);
+ }
+
+ [TestMethod]
+ public void TestTwoNamedStringArgsReBindVolatileFail()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ TwoNamedStringArgs a = tang.NewInjector(cb.Build()).GetInstance<TwoNamedStringArgs>();
+ Assert.AreEqual("defaultA", a.a);
+ Assert.AreEqual("defaultB", a.b);
+ cb.BindNamedParameter<TwoNamedStringArgs.A, string>(GenericType<TwoNamedStringArgs.A>.Class, "not defaultA");
+ cb.BindNamedParameter<TwoNamedStringArgs.B, string>(GenericType<TwoNamedStringArgs.B>.Class, "not defaultB");
+ IInjector i = tang.NewInjector(cb.Build());
+ string msg = null;
+ try
+ {
+ i.BindVolatileParameter(GenericType<TwoNamedStringArgs.A>.Class, "not defaultA");
+ i.BindVolatileParameter(GenericType<TwoNamedStringArgs.B>.Class, "not defaultB");
+ msg =
+ "Attempt to re-bind named parameter TwoNamedStringArgs+A. Old value was [not defaultA] new value is [not defaultA]";
+ }
+ catch (Exception)
+ {
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestBextendsAinjectA()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<BextendsAinjectA.A>.Class, GenericType<BextendsAinjectA.A>.Class);
+ BextendsAinjectA.A a = tang.NewInjector(cb.Build()).GetInstance<BextendsAinjectA.A>();
+ Assert.IsNotNull(a);
+ }
+
+ [TestMethod]
+ public void TestNamedImpl()
+ {
+ ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { FileNames.Examples });
+ cb.BindNamedParameter<AImplName, Aimpl, INamedImplA>(GenericType<AImplName>.Class, GenericType<Aimpl>.Class);
+ cb.BindNamedParameter<BImplName, Bimpl, INamedImplA>(GenericType<BImplName>.Class, GenericType<Bimpl>.Class);
+
+ IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
+ Aimpl a1 = (Aimpl) i.GetNamedInstance<AImplName, INamedImplA>(GenericType<AImplName>.Class);
+ Aimpl a2 = (Aimpl) i.GetNamedInstance<AImplName, INamedImplA>(GenericType<AImplName>.Class);
+ Bimpl b1 = (Bimpl) i.GetNamedInstance<BImplName, INamedImplA>(GenericType<BImplName>.Class);
+ Bimpl b2 = (Bimpl) i.GetNamedInstance<BImplName, INamedImplA>(GenericType<BImplName>.Class);
+ Assert.AreSame(a1, a2);
+ Assert.AreSame(b1, b2);
+ }
+
+ [TestMethod]
+ public void testThreeConstructors()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<ThreeConstructors.TCInt, Int32>(GenericType<ThreeConstructors.TCInt>.Class, "1");
+ cb.BindNamedParameter<ThreeConstructors.TCString, string>(GenericType<ThreeConstructors.TCString>.Class, "s");
+ ThreeConstructors tc = tang.NewInjector(cb.Build()).GetInstance<ThreeConstructors>();
+ Assert.AreEqual(1, tc.i);
+ Assert.AreEqual("s", tc.s);
+
+ cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<ThreeConstructors.TCInt, Int32>(GenericType<ThreeConstructors.TCInt>.Class, "1");
+ tc = tang.NewInjector(cb.Build()).GetInstance<ThreeConstructors>();
+ Assert.AreEqual(1, tc.i);
+ Assert.AreEqual("default", tc.s);
+
+ cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<ThreeConstructors.TCString, string>(GenericType<ThreeConstructors.TCString>.Class, "s");
+ tc = tang.NewInjector(cb.Build()).GetInstance<ThreeConstructors>();
+ Assert.AreEqual(-1, tc.i);
+ Assert.AreEqual("s", tc.s);
+
+ cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<ThreeConstructors.TCFloat, float>(GenericType<ThreeConstructors.TCFloat>.Class, "2");
+ tc = tang.NewInjector(cb.Build()).GetInstance<ThreeConstructors>();
+ Assert.AreEqual(-1, tc.i);
+ Assert.AreEqual("default", tc.s);
+ Assert.AreEqual(2.0f, tc.f, 1e-9);
+ }
+
+ [TestMethod]
+ public void TestThreeConstructorsAmbiguous()
+ {
+ string msg = null;
+
+ try
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<ThreeConstructors.TCString, string>(GenericType<ThreeConstructors.TCString>.Class, "s");
+ cb.BindNamedParameter<ThreeConstructors.TCFloat, float>(GenericType<ThreeConstructors.TCFloat>.Class, "-2");
+
+ // Ambiguous; there is a constructor that takes a string, and another that
+ // takes a float, but none that takes both.
+ tang.NewInjector(cb.Build()).GetInstance<ThreeConstructors>();
+ msg = @"Cannot inject Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null " +
+ "Ambiguous subplan Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null " +
+ "new Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors(System.String Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors+TCString = s) " +
+ "new Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors(System.Single Org.Apache.REEF.Tang.Tests.Tang.ThreeConstructors+TCFloat = -2) ";
+ }
+ catch (InjectionException e)
+ {
+ System.Diagnostics.Debug.WriteLine(e);
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestTwoConstructorsAmbiguous()
+ {
+ string msg = null;
+ try
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindNamedParameter<TwoConstructors.TCInt, Int32>(GenericType<TwoConstructors.TCInt>.Class, "1");
+ cb.BindNamedParameter<ThreeConstructors.TCString, string>(GenericType<ThreeConstructors.TCString>.Class, "s");
+ tang.NewInjector(cb.Build()).GetInstance<TwoConstructors>();
+ msg = @"Cannot inject Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null "+
+ "Ambiguous subplan Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" +
+ "new Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors(System.Int32 Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors+TCInt = 1, System.String Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors+TCString = s)" +
+ "new Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors(System.String Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors+TCString = s, System.Int32 Org.Apache.REEF.Tang.Tests.Tang.TwoConstructors+TCInt = 1)";
+ }
+ catch (InjectionException e)
+ {
+ System.Diagnostics.Debug.WriteLine(e);
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestSingletonWithMultipleConstructors()
+ {
+ ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<SMC>.Class, GenericType<SingletonMultiConst>.Class);
+ cb.BindNamedParameter<SingletonMultiConst.A, string>(GenericType<SingletonMultiConst.A>.Class, "foo");
+ IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
+ var o = i.GetInstance<SMC>();
+ Assert.IsNotNull(o);
+ }
+
+ [TestMethod]
+ public void TestSingletonWithMoreSpecificConstructors()
+ {
+ ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<SMC>.Class, GenericType<SingletonMultiConst>.Class);
+ cb.BindNamedParameter<SingletonMultiConst.A, string>(GenericType<SingletonMultiConst.A>.Class, "foo");
+ cb.BindNamedParameter<SingletonMultiConst.B, string>(GenericType<SingletonMultiConst.B>.Class, "bar");
+ IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
+ var o = i.GetInstance<SMC>();
+ Assert.IsNotNull(o);
+ }
+
+ [TestMethod]
+ public void TestInjectInjector()
+ {
+ IInjector i = TangFactory.GetTang().NewInjector();
+ var ii = (InjectInjector) i.GetInstance(typeof(InjectInjector));
+ //Assert.IsTrue(ii.i is IInjector);
+ Assert.AreNotSame(i, ii.i);
+ }
+
+ [TestMethod]
+ public void TestGenericEventHandlers()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ cba.BindNamedParameter<ABCName.XName, ABCName.XXBB, ABCName.X<ABCName.BB>>(GenericType<ABCName.XName>.Class, GenericType<ABCName.XXBB>.Class);
+ TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(ABCName.XName));
+
+ ICsConfigurationBuilder cbb = TangFactory.GetTang().NewConfigurationBuilder();
+ cbb.BindNamedParameter<ABCName.XName, ABCName.XBB, ABCName.X<ABCName.BB>>(GenericType<ABCName.XName>.Class, GenericType<ABCName.XBB>.Class);
+ TangFactory.GetTang().NewInjector(cbb.Build()).GetNamedInstance(typeof(ABCName.XName));
+ }
+
+ [TestMethod]
+ public void TestGenericEventHandlerDefaults()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ var xbb = TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(ABCName.XNameDB));
+ Assert.IsTrue(xbb is ABCName.XBB);
+ }
+
+ [TestMethod]
+ public void TestGenericEventHandlerDefaultsGoodTreeIndirection()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ var o = TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(ABCName.XNameDDAA));
+ Assert.IsTrue(o is ABCName.XXBB);
+ }
+
+ [TestMethod]
+ public void TestGenericUnrelatedGenericTypeParameters()
+ {
+ string msg = null;
+ try
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(WaterBottleName));
+ msg =
+ "class WaterBottleName defines a default class GasCan with a type that does not extend its target's type Water";
+ }
+ catch (ClassHierarchyException e)
+ {
+ System.Diagnostics.Debug.WriteLine(e);
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestGenericInterfaceUnboundTypeParametersName()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ var o = TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(FooEventHandler));
+ Assert.IsTrue(o is MyEventHandler<Foo>);
+ }
+
+ [TestMethod]
+ public void TestGenericInterfaceUnboundTypeParametersNameIface()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ var o = TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(IfaceEventHandler));
+ Assert.IsTrue(o is IEventHandler<SomeIface>);
+ }
+
+ [TestMethod]
+ public void TestGenericInterfaceUnboundTypeParametersIface()
+ {
+ string msg = null;
+ try
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ TangFactory.GetTang().NewInjector(cba.Build()).IsInjectable(typeof(MyEventHandlerIface));
+ msg =
+ "interface MyEventHandlerIface declares its default implementation to be non-subclass class MyEventHandler";
+ }
+ catch (ClassHierarchyException e)
+ {
+ System.Diagnostics.Debug.WriteLine(e);
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestWantSomeHandlers()
+ {
+ var o = TangFactory.GetTang().NewInjector().GetInstance<WantSomeHandlers>();
+ Assert.IsNotNull(o);
+ }
+
+ [TestMethod]
+ public void TestWantSomeHandlersBadOrder()
+ {
+ IInjector i = TangFactory.GetTang().NewInjector();
+ var o1 = i.GetInstance<IAHandler>();
+ var o2 = i.GetInstance<IBHandler>();
+ var o3 = i.GetInstance<WantSomeFutureHandlers>();
+ Assert.IsTrue(o1 is AHandlerImpl);
+ Assert.IsTrue(o2 is BHandlerImpl);
+ Assert.IsNotNull(o3);
+ }
+
+ [TestMethod]
+ public void TestWantSomeFutureHandlersAlreadyBoundVolatile()
+ {
+ IInjector i = TangFactory.GetTang().NewInjector();
+ i.BindVolatileInstance(GenericType<IAHandler>.Class, new AHandlerImpl());
+ i.BindVolatileInstance(GenericType<IBHandler>.Class, new BHandlerImpl());
+ i.GetInstance<WantSomeFutureHandlers>();
+ }
+
+ [TestMethod]
+ public void TestWantSomeFutureHandlers()
+ {
+ TangFactory.GetTang().NewInjector().GetInstance<WantSomeFutureHandlers>();
+ }
+
+ [TestMethod]
+ public void TestWantSomeFutureHandlersName()
+ {
+ TangFactory.GetTang().NewInjector().GetInstance<WantSomeFutureHandlersName>();
+ }
+
+ [TestMethod]
+ public void TestReuseFailedInjector()
+ {
+ IInjector i = TangFactory.GetTang().NewInjector();
+ try
+ {
+ i.GetInstance<Fail>();
+ Assert.Fail("Injecting Fail should not have worked!");
+ } catch (InjectionException)
+ {
+ i.GetInstance<Pass>();
+ }
+ }
+
+ [TestMethod]
+ public void TestMultipleLayersFromAbstractClass()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<MultiLayer>.Class, GenericType<LowerLayer>.Class);
+ MultiLayer o = tang.NewInjector(cb.Build()).GetInstance<MultiLayer>();
+ Assert.IsNotNull(o);
+ }
+
+ [TestMethod]
+ public void TestMultipleLayersFromInterface()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<IMultiLayer>.Class, GenericType<LowerLayerImpl>.Class);
+ IMultiLayer o = tang.NewInjector(cb.Build()).GetInstance<IMultiLayer>();
+ Assert.IsNotNull(o);
+ }
+ }
+
+ internal class InjectInjector
+ {
+ public IInjector i;
+
+ [Inject]
+ private InjectInjector(IInjector i)
+ {
+ this.i = i;
+ }
+ }
+
+ internal class MustBeSingleton
+ {
+ public static bool alreadyInstantiated;
+
+ [Inject]
+ public MustBeSingleton()
+ {
+ if (alreadyInstantiated)
+ {
+ throw new IllegalStateException("Can't instantiate me twice!");
+ }
+ alreadyInstantiated = true;
+ }
+ }
+
+ internal class SubSingleton
+ {
+ [Inject]
+ private SubSingleton(MustBeSingleton a)
+ {
+ // Does not call super
+ }
+ }
+
+ internal class TwoSingletons
+ {
+ [Inject]
+ private TwoSingletons(SubSingleton a, MustBeSingleton b)
+ {
+ }
+ }
+
+ internal class RepeatedAmbiguousArgs
+ {
+ [Inject]
+ private RepeatedAmbiguousArgs(int x, int y)
+ {
+ }
+ }
+
+ public class RepeatedNamedArgs
+ {
+ [NamedParameter]
+ public class A : Name<Int32>
+ {
+ }
+
+ [NamedParameter()]
+ public class B : Name<Int32>
+ {
+ }
+
+ [Inject]
+ public RepeatedNamedArgs([Parameter(typeof (A))] int x, [Parameter(Value = typeof (B))] int y)
+ {
+ }
+ }
+
+ internal class RepeatedNamedSingletonArgs
+ {
+ [NamedParameter()]
+ public class A : Name<MustBeSingleton>
+ {
+ }
+
+ [NamedParameter()]
+ public class B : Name<MustBeSingleton>
+ {
+ }
+
+ [Inject]
+ public RepeatedNamedSingletonArgs([Parameter(typeof (A))] MustBeSingleton a,
+ [Parameter(typeof (B))] MustBeSingleton b)
+ {
+ }
+ }
+
+ internal class OneNamedSingletonArgs
+ {
+ [NamedParameter()]
+ public class A : Name<MustBeSingleton>
+ {
+ }
+
+ [NamedParameter()]
+ public class B : Name<MustBeSingleton>
+ {
+ }
+
+ [Inject]
+ public OneNamedSingletonArgs([Parameter(typeof (A))] MustBeSingleton a)
+ {
+ }
+ }
+
+ [NamedParameter(Documentation = "woo", ShortName = "woo", DefaultValue = "42")]
+ internal class Param : Name<Int32>
+ {
+ }
+
+ internal interface Interf
+ {
+ }
+
+ internal class Impl : Interf
+ {
+ [Inject]
+ private Impl([Parameter(Value = typeof (Param))] int p)
+ {
+ }
+ }
+
+ internal class OneNamedStringArg
+ {
+ [NamedParameter(DefaultValue = "default")]
+ public class A : Name<string>
+ {
+ }
+
+ public string s;
+
+ [Inject]
+ private OneNamedStringArg([Parameter(typeof (A))] string s)
+ {
+ this.s = s;
+ }
+ }
+
+ internal class TwoNamedStringArgs
+ {
+ [NamedParameter(DefaultValue = "defaultA")]
+ public class A : Name<string>
+ {
+ }
+
+ [NamedParameter(DefaultValue = "defaultB")]
+ public class B : Name<string>
+ {
+ }
+
+ public string a;
+ public string b;
+
+ [Inject]
+ private TwoNamedStringArgs([Parameter(typeof (A))] string a, [Parameter(typeof (B))] String b)
+ {
+ this.a = a;
+ this.b = b;
+ }
+ }
+
+ internal class BextendsAinjectA
+ {
+ public class A
+ {
+ [Inject]
+ public A()
+ {
+ }
+ }
+
+ public class B : A
+ {
+ }
+ }
+
+ public interface INamedImplA
+ {
+ }
+
+ public interface INamedImplC
+ {
+ }
+
+ [NamedParameter]
+ public class AImplName : Name<INamedImplA>
+ {
+ }
+
+ [NamedParameter]
+ public class BImplName : Name<INamedImplA>
+ {
+ }
+
+ [NamedParameter]
+ public class CImplName : Name<INamedImplC>
+ {
+ }
+
+ public class Aimpl : INamedImplA
+ {
+ [Inject]
+ private Aimpl()
+ {
+ }
+ }
+
+ public class Bimpl : INamedImplA
+ {
+ [Inject]
+ private Bimpl()
+ {
+ }
+ }
+
+ public class Cimpl : INamedImplC
+ {
+ [Inject]
+ private Cimpl()
+ {
+ }
+ }
+
+ internal class NamedImpl
+ {
+ [NamedParameter]
+ public class AImplName : Name<A>
+ {
+ }
+
+ [NamedParameter]
+ public class BImplName : Name<A>
+ {
+ }
+
+ [NamedParameter]
+ public class CImplName : Name<C>
+ {
+ }
+
+ public interface A
+ {
+ }
+
+ public interface C
+ {
+ }
+
+ public class Aimpl : A
+ {
+ [Inject]
+ private Aimpl()
+ {
+ }
+ }
+
+ public class Bimpl : A
+ {
+ [Inject]
+ private Bimpl()
+ {
+ }
+ }
+
+ public class Cimpl : C
+ {
+ [Inject]
+ private Cimpl()
+ {
+ }
+ }
+
+ public class ABtaker
+ {
+ [Inject]
+ private ABtaker([Parameter(typeof (AImplName))] INamedImplA a, [Parameter(typeof (BImplName))] INamedImplA b)
+ {
+ //Assert.IsTrue(a is Aimpl, "AImplName must be instance of Aimpl");
+ //Assert.IsTrue(b is Bimpl, "BImplName must be instance of Bimpl");
+ }
+ }
+ }
+
+ class ThreeConstructors
+ {
+ public int i;
+ public string s;
+ public float f;
+
+ [NamedParameter]
+ public class TCInt : Name<Int32> {}
+
+ [NamedParameter]
+ public class TCString : Name<string> { }
+
+ [NamedParameter]
+ public class TCFloat : Name<float> {}
+
+ [Inject]
+ public ThreeConstructors([Parameter(typeof(TCInt))] int i, [Parameter(typeof(TCString))] string s)
+ {
+ this.i = i;
+ this.s = s;
+ this.f = -1.0f;
+ }
+
+ [Inject]
+ public ThreeConstructors([Parameter(typeof(TCString))] string s) : this(-1, s)
+ {
+ }
+
+ [Inject]
+ public ThreeConstructors([Parameter(typeof(TCInt))] int i) : this(i, "default")
+ {
+ }
+
+ [Inject]
+ public ThreeConstructors([Parameter(typeof(TCFloat))] float f)
+ {
+ this.i = -1;
+ this.s = "default";
+ this.f = f;
+ }
+ }
+
+ class TwoConstructors
+ {
+ public int i;
+ public string s;
+
+ [NamedParameter]
+ public class TCInt : Name<Int32> { }
+
+ [NamedParameter]
+ public class TCString : Name<string> { }
+
+
+ [Inject]
+ public TwoConstructors([Parameter(typeof(TCInt))] int i, [Parameter(typeof(TCString))] string s)
+ {
+ this.i = i;
+ this.s = s;
+ }
+
+ [Inject]
+ public TwoConstructors([Parameter(typeof(TCString))] string s, [Parameter(typeof(TCInt))] int i)
+ {
+ this.i = i;
+ this.s = s;
+ }
+ }
+
+ interface SMC { }
+
+ class SingletonMultiConst : SMC
+ {
+ [NamedParameter]
+ public class A : Name<string> { }
+
+ [NamedParameter]
+ public class B : Name<string> { }
+
+ [Inject]
+ public SingletonMultiConst([Parameter(typeof(A))] String a) { }
+
+ [Inject]
+ public SingletonMultiConst([Parameter(typeof(A))] string a, [Parameter(typeof(B))] string b) { }
+ }
+
+ internal class ABCName
+ {
+ public interface X<T>
+ {
+ }
+
+ [NamedParameter]
+ public class XName : Name<X<BB>>
+ {
+ }
+
+ //[NamedParameter(DefaultClass = typeof(XAA))]
+ //public class XNameDA : Name<X<BB>>
+ //{
+ //}
+
+ [NamedParameter(DefaultClass = typeof(XBB))]
+ public class XNameDB : Name<X<BB>>
+ {
+ }
+
+ //[NamedParameter(DefaultClass = typeof(XCC))]
+ //public class XNameDC : Name<X<BB>>
+ //{
+ //}
+
+ //[NamedParameter(DefaultClass = typeof(XCC))]
+ //public class XNameDAA : Name<XBB>
+ //{
+ //}
+
+ [NamedParameter(DefaultClass = typeof(XXBB))]
+ public class XNameDDAA : Name<XBB>
+ {
+ }
+
+ [DefaultImplementation(typeof(AA))]
+ public class AA
+ {
+ [Inject]
+ public AA()
+ {
+ }
+ }
+
+ [DefaultImplementation(typeof(BB))]
+ public class BB : AA
+ {
+ [Inject]
+ public BB()
+ {
+ }
+ }
+
+ [DefaultImplementation(typeof(CC))]
+ public class CC : BB
+ {
+ [Inject]
+ public CC()
+ {
+ }
+ }
+
+ public class XAA : X<AA>
+ {
+ [Inject]
+ public XAA(AA aa)
+ {
+ }
+ }
+
+ [DefaultImplementation(typeof(XBB))]
+ public class XBB : X<BB>
+ {
+ [Inject]
+ public XBB(BB aa)
+ {
+ }
+ }
+
+ public class XXBB : XBB
+ {
+ [Inject]
+ public XXBB(BB aa)
+ : base(aa)
+ {
+ }
+ }
+
+ public class XCC : X<CC>
+ {
+ [Inject]
+ public XCC(CC aa)
+ {
+ }
+ }
+ }
+
+ interface Bottle<Y> {
+
+ }
+ class WaterBottle : Bottle<Water>
+ {
+ }
+ class GasCan : Bottle<Gas>
+ {
+ }
+ class Water {}
+ class Gas {}
+
+ [NamedParameter(DefaultClass=typeof(GasCan))]
+ class WaterBottleName : Name<Bottle<Water>> { }
+
+ interface IEventHandler <T> { }
+ class MyEventHandler<T> : IEventHandler<T>
+ {
+ [Inject]
+ MyEventHandler () { }
+ }
+
+ [DefaultImplementation(typeof(MyEventHandler<Foo>))]
+ interface MyEventHandlerIface : IEventHandler<Foo> { }
+
+ [NamedParameter(DefaultClass = typeof(MyEventHandler<Foo>))]
+ class FooEventHandler : Name<IEventHandler<Foo>> { }
+
+ internal class Foo : Name<String>
+ {
+ }
+
+ interface SomeIface { }
+ [NamedParameter(DefaultClass = typeof(MyEventHandler<SomeIface>))]
+ class IfaceEventHandler : Name<IEventHandler<SomeIface>> { }
+
+ class AH
+ {
+ [Inject]
+ AH() {}
+ }
+ class BH
+ {
+ [Inject]
+ BH() {}
+ }
+
+ [DefaultImplementation(typeof(AHandlerImpl))]
+ interface IAHandler : IEventHandler<AH> { }
+
+ [DefaultImplementation(typeof(BHandlerImpl))]
+ interface IBHandler : IEventHandler<BH> { }
+
+ class AHandlerImpl : IAHandler
+ {
+ [Inject]
+ public AHandlerImpl() { }
+ }
+ class BHandlerImpl : IBHandler
+ {
+ [Inject]
+ public BHandlerImpl() { }
+ }
+
+ class WantSomeHandlers
+ {
+ [Inject]
+ WantSomeHandlers(IAHandler a, IBHandler b) { }
+ }
+ class WantSomeFutureHandlers
+ {
+ [Inject]
+ WantSomeFutureHandlers(IInjectionFuture<IAHandler> a, IInjectionFuture<IBHandler> b) { }
+ }
+
+ [NamedParameter(DefaultClass = typeof(AHandlerImpl))]
+ class AHandlerName : Name<IEventHandler<AH>> { }
+
+ [NamedParameter(DefaultClass = typeof(BHandlerImpl))]
+ class BHandlerName : Name<IEventHandler<BH>> { }
+
+ class WantSomeFutureHandlersName
+ {
+ [Inject]
+ WantSomeFutureHandlersName(
+ [Parameter(typeof (AHandlerName))] IInjectionFuture<IEventHandler<AH>> a,
+ [Parameter(typeof (BHandlerName))] IInjectionFuture<IEventHandler<BH>> b)
+ {
+ }
+ }
+
+ class Pass
+ {
+ [Inject]
+ public Pass()
+ {
+ }
+ }
+
+ class Fail
+ {
+ [Inject]
+ public Fail()
+ {
+ throw new NotSupportedException();
+ }
+ }
+
+ abstract class MultiLayer
+ {
+
+ }
+
+ class MiddleLayer : MultiLayer
+ {
+ [Inject]
+ public MiddleLayer() { }
+ }
+
+ class LowerLayer : MiddleLayer
+ {
+ [Inject]
+ public LowerLayer() { }
+ }
+
+ interface IMultiLayer
+ {
+
+ }
+
+ class MiddleLayerImpl : IMultiLayer
+ {
+ [Inject]
+ public MiddleLayerImpl() { }
+ }
+
+ class LowerLayerImpl : MiddleLayerImpl
+ {
+ [Inject]
+ public LowerLayerImpl() { }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/TestUtilities.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/TestUtilities.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/TestUtilities.cs
new file mode 100644
index 0000000..2b274a7
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/TestUtilities.cs
@@ -0,0 +1,294 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using Org.Apache.REEF.Tang.Formats;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Examples;
+
+namespace Org.Apache.REEF.Tang.Tests.Utilities
+{
+ [TestClass]
+ public class TestUtilities
+ {
+ [TestMethod]
+ public void TestIsAssignableFromIgnoreGeneric()
+ {
+ var result = ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(IExternalConstructor<>), typeof(Foo));
+ Assert.IsTrue(result);
+ }
+
+ [TestMethod]
+ public void TestIsAssignableFromIgnoreGenericNegtive()
+ {
+ var result = ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(ISet<>), typeof(Foo));
+ Assert.IsFalse(result);
+ }
+
+ [TestMethod]
+ public void TestIsInstanceOfGeneric()
+ {
+ var p1 = new OptionalParameter<int>();
+ bool r1 = ReflectionUtilities.IsInstanceOfGeneric(p1, typeof(OptionalParameter<>));
+ var p2 = new RequiredParameter<string>();
+ bool r2 = ReflectionUtilities.IsInstanceOfGeneric(p2, typeof(RequiredParameter<>));
+ Assert.IsTrue(r1);
+ Assert.IsTrue(r2);
+ }
+
+ [TestMethod]
+ public void TestGetInterfaceTargetForTypeInheritFromGeneric()
+ {
+ Type result = ReflectionUtilities.GetInterfaceTarget(typeof(IExternalConstructor<>), typeof(Foo));
+ Assert.AreEqual(result, typeof(Int32));
+ }
+
+ class Foo : IExternalConstructor<Int32>
+ {
+ public Int32 NewInstance()
+ {
+ return 3;
+ }
+ }
+
+ [TestMethod]
+ public void TestGetEnclosingClassShortNameByType()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type seconds = asm.GetType(FileNames.Seconds);
+ Type timer = asm.GetType(FileNames.Timer);
+
+ string[] pathSeconds = ReflectionUtilities.GetEnclosingClassNames(seconds);
+ Assert.AreEqual(pathSeconds[0], timer.AssemblyQualifiedName);
+ Assert.AreEqual(pathSeconds[1], seconds.AssemblyQualifiedName);
+
+ string[] pathTime = ReflectionUtilities.GetEnclosingClassNames(timer);
+ Assert.AreEqual(pathTime[0], timer.AssemblyQualifiedName);
+ }
+
+ [TestMethod]
+ public void TestGetName()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type B2 = asm.GetType(FileNames.B2);
+
+ string n = ReflectionUtilities.GetName(B2);
+ Assert.AreEqual(n, B2.FullName);
+ }
+
+ [TestMethod]
+ public void TestGetEnclosingTypesInclusive()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type B2 = asm.GetType(FileNames.B2);
+ Type[] ts = ReflectionUtilities.GetEnclosingClasses(B2);
+ Assert.AreEqual(ts[0], asm.GetType(FileNames.B));
+ Assert.AreEqual(ts[1], asm.GetType(FileNames.B1));
+ Assert.AreEqual(ts[2], asm.GetType(FileNames.B2));
+ }
+
+ [TestMethod]
+ public void TestGetEnclosingClassShortNameByName()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type b = asm.GetType(FileNames.B);
+ Type b1 = asm.GetType(FileNames.B1);
+ Type b2 = asm.GetType(FileNames.B2);
+
+ string[] path = ReflectionUtilities.GetEnclosingClassNames(FileNames.B2);
+ Assert.AreEqual(path[0], b.AssemblyQualifiedName);
+ Assert.AreEqual(path[1], b1.AssemblyQualifiedName);
+ Assert.AreEqual(path[2], b2.AssemblyQualifiedName);
+ }
+
+ [TestMethod]
+ public void TestGetEnclosingClassShortNameByFullName()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type c = asm.GetType(FileNames.B2);
+ Type b = asm.GetType(FileNames.B);
+ Type b1 = asm.GetType(FileNames.B1);
+ Type b2 = asm.GetType(FileNames.B2);
+ string[] path = ReflectionUtilities.GetEnclosingClassNames(c.FullName);
+ Assert.AreEqual(path[0], b.AssemblyQualifiedName);
+ Assert.AreEqual(path[1], b1.AssemblyQualifiedName);
+ Assert.AreEqual(path[2], b2.AssemblyQualifiedName);
+ }
+
+ [TestMethod]
+ public void TestGetEnclosingClassShortNameByAssemblyQualifiedName()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type c = asm.GetType(FileNames.B2);
+ Type b = asm.GetType(FileNames.B);
+ Type b1 = asm.GetType(FileNames.B1);
+ Type b2 = asm.GetType(FileNames.B2);
+
+ string[] path = ReflectionUtilities.GetEnclosingClassNames(c.AssemblyQualifiedName);
+
+ Assert.AreEqual(path[0], b.AssemblyQualifiedName);
+ Assert.AreEqual(path[1], b1.AssemblyQualifiedName);
+ Assert.AreEqual(path[2], b2.AssemblyQualifiedName);
+ }
+
+ [TestMethod]
+ public void AssemblyNamesTest()
+ {
+ var asm = Assembly.Load(FileNames.Examples);
+ Type seconds = asm.GetType(FileNames.Seconds);
+
+ var name = seconds.Name;
+ var fullName = seconds.FullName;
+ var assemblyName = seconds.AssemblyQualifiedName;
+
+ Type[] i = seconds.GetInterfaces();
+
+ foreach (Type t in i)
+ {
+ var name1 = t.Name;
+ var fullName1 = t.FullName;
+ var assemblyName1 = t.AssemblyQualifiedName;
+ }
+ }
+
+ [TestMethod]
+ public void TestGetInterfaceTargetForGenericType()
+ {
+ Type iface = typeof(ISet<>);
+ Type type = typeof(MySet<string>);
+ Type p = ReflectionUtilities.GetInterfaceTarget(iface, type);
+ Assert.IsTrue(p.Equals(typeof (string)));
+ }
+
+ [TestMethod]
+ public void TestGetInterfaceTargetForSystemGenericType()
+ {
+ Type iface = typeof(ISet<>);
+ Type type = typeof(ISet<int>);
+ Type p = ReflectionUtilities.GetInterfaceTarget(iface, type);
+ Assert.IsTrue(p.Equals(typeof(int)));
+ }
+ }
+
+ public class MySet<T> : ISet<T>
+ {
+ public bool Add(T item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void ExceptWith(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void IntersectWith(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IsProperSubsetOf(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IsProperSupersetOf(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IsSubsetOf(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IsSupersetOf(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool Overlaps(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool SetEquals(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SymmetricExceptWith(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void UnionWith(IEnumerable<T> other)
+ {
+ throw new NotImplementedException();
+ }
+
+ void ICollection<T>.Add(T item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Clear()
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool Contains(T item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int Count
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public bool IsReadOnly
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public bool Remove(T item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/Utilities.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/Utilities.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/Utilities.cs
new file mode 100644
index 0000000..48b90f5
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/Utilities.cs
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System.Collections.Generic;
+
+namespace Org.Apache.REEF.Tang.Tests.Utilities
+{
+ public class Utilities
+ {
+ public static bool Equals<T>(ICollection<T> s1, ISet<T> s2)
+ {
+ if (s1 == s2)
+ {
+ return true;
+ }
+ if (s1 == null || s2 == null)
+ {
+ return false;
+ }
+ if (s1.Count != s2.Count)
+ {
+ return false;
+ }
+ foreach (T t in s1)
+ {
+ if (!Contains<T>(s2, t))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static bool Contains<T>(ICollection<T> s, T t)
+ {
+ foreach (T t1 in s)
+ {
+ if (t1.Equals(t))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/evaluator.conf
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/evaluator.conf b/lang/cs/Org.Apache.REEF.Tang.Tests/evaluator.conf
new file mode 100644
index 0000000..67256f5
Binary files /dev/null and b/lang/cs/Org.Apache.REEF.Tang.Tests/evaluator.conf differ
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/packages.config
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/packages.config b/lang/cs/Org.Apache.REEF.Tang.Tests/packages.config
new file mode 100644
index 0000000..933b7e1
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/packages.config
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<packages>
+ <package id="Microsoft.Hadoop.Avro" version="1.4.0.0" targetFramework="net45" />
+ <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
+ <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
+</packages>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/simpleConstructorJavaProto.bin
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/simpleConstructorJavaProto.bin b/lang/cs/Org.Apache.REEF.Tang.Tests/simpleConstructorJavaProto.bin
new file mode 100644
index 0000000..f7bb871
Binary files /dev/null and b/lang/cs/Org.Apache.REEF.Tang.Tests/simpleConstructorJavaProto.bin differ
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tools/Org.Apache.REEF.Tang.Tools.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tools/Org.Apache.REEF.Tang.Tools.csproj b/lang/cs/Org.Apache.REEF.Tang.Tools/Org.Apache.REEF.Tang.Tools.csproj
new file mode 100644
index 0000000..9925d6e
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tools/Org.Apache.REEF.Tang.Tools.csproj
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{34A9CD98-0D15-4CA0-AEA5-E53593A31047}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Org.Apache.REEF.Tang.Tools</RootNamespace>
+ <AssemblyName>Org.Apache.REEF.Tang.Tools</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <RestorePackages>true</RestorePackages>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ </PropertyGroup>
+ <Import Project="$(SolutionDir)\Source\build.props" />
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>$(BinDir)\AnyCPU\Debug\Org.Apache.REEF.Tools\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\REEF\reef-tasks\Tasks\Tasks.csproj">
+ <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project>
+ <Name>Tasks</Name>
+ </ProjectReference>
+ <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Tang\Org.Apache.REEF.Tang.csproj">
+ <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project>
+ <Name>Org.Apache.REEF.Tang</Name>
+ </ProjectReference>
+ <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj">
+ <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project>
+ <Name>Org.Apache.REEF.Utilities</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Org.Apache.REEF.Common\Org.Apache.REEF.Common.csproj">
+ <Project>{545a0582-4105-44ce-b99c-b1379514a630}</Project>
+ <Name>Org.Apache.REEF.Common</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Org.Apache.REEF.Driver\Org.Apache.REEF.Driver.csproj">
+ <Project>{a6baa2a7-f52f-4329-884e-1bcf711d6805}</Project>
+ <Name>Org.Apache.REEF.Driver</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Org.Apache.REEF.Wake\Org.Apache.REEF.Wake.csproj">
+ <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project>
+ <Name>Org.Apache.REEF.Wake</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tools/Program.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tools/Program.cs b/lang/cs/Org.Apache.REEF.Tang.Tools/Program.cs
new file mode 100644
index 0000000..0e158b6
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tools/Program.cs
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using Org.Apache.REEF.Tasks;
+using Org.Apache.REEF.Tang.Implementations;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Protobuf;
+using Org.Apache.REEF.Tang.Types;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tools
+{
+ public class ClassHierarchyBuilder
+ {
+ /// <summary>
+ /// This program generates class hierarchy bin file for the list of dlls, plus a defalut list
+ /// The default list include: ITask, StreamTask1, HelloTask and ShellTask, please remove if not needed
+ /// </summary>
+ /// <param name="args"> additional dlls needed to build class hierarchy </param>
+ public static void Main(string[] args)
+ {
+ const string DllSubfix = ".dll";
+ const string ClassHierarchyBinFileName = "task.bin";
+
+ List<string> taskDlls = new List<string>();
+
+ foreach (string arg in args)
+ {
+ string assemblyName = arg;
+ if (!arg.EndsWith(DllSubfix, StringComparison.OrdinalIgnoreCase))
+ {
+ assemblyName += DllSubfix;
+ }
+ if (!File.Exists(assemblyName))
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "invalid argument: assembly {0} cannot be found", assemblyName));
+ }
+ taskDlls.Add(arg);
+ }
+
+ taskDlls.Add(GetAssemblyName(typeof(ITask)));
+ taskDlls.Add(GetAssemblyName(typeof(HelloTask)));
+ taskDlls.Add(GetAssemblyName(typeof(ShellTask)));
+ taskDlls.Add(GetAssemblyName(typeof(StreamTask1)));
+
+ IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(taskDlls.ToArray());
+
+ // the following is verification only
+ // to verify that a class indeeded has been added to the class hierarchy, check the class name
+ IClassNode streamTaskClassNode = (IClassNode)ns.GetNode(typeof(StreamTask1).AssemblyQualifiedName);
+ IClassNode helloTaskClassNode = (IClassNode)ns.GetNode(typeof(HelloTask).AssemblyQualifiedName);
+ IClassNode shellTaskClassNode = (IClassNode)ns.GetNode(typeof(ShellTask).AssemblyQualifiedName);
+
+ ProtocolBufferClassHierarchy.Serialize(ClassHierarchyBinFileName, ns);
+ IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize(ClassHierarchyBinFileName);
+
+ IClassNode retrievedStreamTaskClassNode = (IClassNode)ch.GetNode(typeof(StreamTask1).AssemblyQualifiedName);
+ IClassNode retrievedHelloTaskClassNode = (IClassNode)ch.GetNode(typeof(HelloTask).AssemblyQualifiedName);
+ IClassNode retrievedShellTaskClassNode = (IClassNode)ch.GetNode(typeof(ShellTask).AssemblyQualifiedName);
+
+ if (!streamTaskClassNode.GetFullName().Equals(retrievedStreamTaskClassNode.GetFullName()) ||
+ !helloTaskClassNode.GetFullName().Equals(retrievedHelloTaskClassNode.GetFullName()) ||
+ !shellTaskClassNode.GetFullName().Equals(retrievedShellTaskClassNode.GetFullName()))
+ {
+ Console.WriteLine("Node deseriliazed is not equal");
+ }
+ else
+ {
+ Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Class hierarchy written to [{0}].", Directory.GetCurrentDirectory()));
+ }
+ }
+
+ private static string GetAssemblyName(Type type)
+ {
+ return type.Assembly.GetName().Name;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tools/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tools/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Tang.Tools/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..a2db1ec
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tools/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Org.Apache.REEF.Tang.Tools")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Org.Apache.REEF.Tang.Tools")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("8a034f16-c6c7-497a-b3c0-f8cfea1635e9")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/DefaultImplementation.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/DefaultImplementation.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/DefaultImplementation.cs
new file mode 100644
index 0000000..cce2914
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/DefaultImplementation.cs
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ /// <summary>
+ /// DefaultImplementationAttribute
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
+ public class DefaultImplementationAttribute : System.Attribute
+ {
+ public Type Value { get; set; }
+ public string Name { get; set; }
+
+ public DefaultImplementationAttribute(Type val = null, string n = "")
+ {
+ Name = n;
+ Value = val;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/Inject.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/Inject.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/Inject.cs
new file mode 100644
index 0000000..21d26e6
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/Inject.cs
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ /// <summary>
+ /// InjectAttribute
+ /// </summary>
+ [System.AttributeUsage(System.AttributeTargets.Constructor)]
+ public class InjectAttribute : System.Attribute
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/Name.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/Name.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/Name.cs
new file mode 100644
index 0000000..4526755
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/Name.cs
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ /// <summary>
+ /// Base class for named parameters
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ public interface Name<T>
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/NamedParameter.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/NamedParameter.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/NamedParameter.cs
new file mode 100644
index 0000000..902f1fb
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/NamedParameter.cs
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ [System.AttributeUsage(System.AttributeTargets.Class)]
+ public class NamedParameterAttribute : System.Attribute
+ {
+ public string Documentation { get; set; }
+ public string ShortName { get; set; }
+ public string DefaultValue { get; set; }
+ public Type DefaultClass { get; set; }
+ public string[] DefaultValues { get; set; }
+ public Type[] DefaultClasses { get; set; }
+
+ public NamedParameterAttribute(string documentation = "", string shortName = "",
+ string defaultValue = "", Type defaultClass = null, string[] defaultValues = null, Type[] defaultClasses = null)
+ {
+ this.Documentation = documentation;
+ this.ShortName = shortName;
+ this.DefaultValue = defaultValue;
+ this.DefaultClass = defaultClass;
+ this.DefaultValues = defaultValues;
+ this.DefaultClasses = defaultClasses;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/Parameter.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/Parameter.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/Parameter.cs
new file mode 100644
index 0000000..1e4a7c1
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/Parameter.cs
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ /// <summary>
+ /// ParameterAttribute
+ /// </summary>
+ [System.AttributeUsage(System.AttributeTargets.Parameter)]
+ public class ParameterAttribute : System.Attribute
+ {
+ public ParameterAttribute()
+ {
+ }
+
+ public ParameterAttribute(Type value)
+ {
+ Value = value;
+ }
+
+ public Type Value { get; set; }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Annotations/Unit.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Annotations/Unit.cs b/lang/cs/Org.Apache.REEF.Tang/Annotations/Unit.cs
new file mode 100644
index 0000000..cfaac0d
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Annotations/Unit.cs
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+namespace Org.Apache.REEF.Tang.Annotations
+{
+ /// <summary>
+ /// UnitAttribute
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class, Inherited = false)]
+ public class UnitAttribute : System.Attribute
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Exceptions/BindException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Exceptions/BindException.cs b/lang/cs/Org.Apache.REEF.Tang/Exceptions/BindException.cs
new file mode 100644
index 0000000..032eda0
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Exceptions/BindException.cs
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+
+namespace Org.Apache.REEF.Tang.Exceptions
+{
+ public class BindException : SystemException
+ {
+ //private static readonly long serialVersionUID = 1L;
+ public BindException(String message)
+ : base(message)
+ {
+ }
+
+ public BindException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Exceptions/ClassHierarchyException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Exceptions/ClassHierarchyException.cs b/lang/cs/Org.Apache.REEF.Tang/Exceptions/ClassHierarchyException.cs
new file mode 100644
index 0000000..60697c2
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Exceptions/ClassHierarchyException.cs
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+
+namespace Org.Apache.REEF.Tang.Exceptions
+{
+ public class ClassHierarchyException : SystemException
+ {
+ public ClassHierarchyException(String msg) : base(msg)
+ {
+ }
+
+ public ClassHierarchyException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Exceptions/IllegalStateException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Exceptions/IllegalStateException.cs b/lang/cs/Org.Apache.REEF.Tang/Exceptions/IllegalStateException.cs
new file mode 100644
index 0000000..f62e207
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Exceptions/IllegalStateException.cs
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+
+namespace Org.Apache.REEF.Tang.Exceptions
+{
+ public class IllegalStateException : Exception
+ {
+ public IllegalStateException()
+ : base()
+ {
+ }
+
+ public IllegalStateException(String msg)
+ : base(msg)
+ {
+ }
+
+ public IllegalStateException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Exceptions/InjectionException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang/Exceptions/InjectionException.cs b/lang/cs/Org.Apache.REEF.Tang/Exceptions/InjectionException.cs
new file mode 100644
index 0000000..9b72c59
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang/Exceptions/InjectionException.cs
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+
+namespace Org.Apache.REEF.Tang.Exceptions
+{
+ public class InjectionException : Exception
+ {
+ public InjectionException(String msg)
+ : base(msg)
+ {
+ }
+
+ public InjectionException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}