9using System.Reflection;
12using System.Diagnostics;
13using Microsoft.VisualStudio.TestTools.UnitTesting;
16using TestClass = NUnit.Framework.TestFixtureAttribute;
17using TestInitialize = NUnit.Framework.SetUpAttribute;
18using TestCleanup = NUnit.Framework.TearDownAttribute;
19using TestMethod = NUnit.Framework.TestAttribute;
31 var flags = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic;
33 var ctor = GetConstructor(obj.GetType(), flags,
null,
new Type[] { },
null);
34 Assert.IsNotNull(ctor);
35 Assert.IsTrue(ctor.IsStatic);
41 var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic;
43 var ctor = GetConstructor(obj.GetType(), flags,
null,
new Type[] { },
null);
44 Assert.IsNotNull(ctor);
45 Assert.IsFalse(ctor.IsStatic);
48 private static ConstructorInfo GetConstructor(Type t, BindingFlags bindingFlags,
object c, Type[] paramTypes,
object d)
50 if (paramTypes.Length > 0)
51 throw new NotImplementedException();
52 var ti = t.GetTypeInfo();
53 var m = ti.DeclaredConstructors.Where(r => r.GetParameters().Count() == 0);
54 if (!((bindingFlags & BindingFlags.Instance) > 0))
55 m = m.Where(r => r.IsStatic);
56 if (!((bindingFlags & BindingFlags.Static) > 0))
57 m = m.Where(r => !r.IsStatic);
58 if (!((bindingFlags & BindingFlags.Public) > 0))
59 m = m.Where(r => !r.IsPublic);
60 if (!((bindingFlags & BindingFlags.NonPublic) > 0))
61 m = m.Where(r => r.IsPublic);
62 return m.FirstOrDefault();
void GetsInstanceConstructor()
void GetsStaticConstructor()