public void CustomGenerateTest() { CustomObject o = TypeAccessor <CustomObject> .CreateInstanceEx(); Type type = o.GetType(); NonInheritedAttribute attr = (NonInheritedAttribute) Attribute.GetCustomAttribute(type, typeof(NonInheritedAttribute)); Assert.That(attr, Is.Not.Null); Assert.That(attr.Type, Is.EqualTo(typeof(int))); Assert.That(attr.NamedArgument, Is.EqualTo("NamedValue")); }
public void MainTest() { TestObject o = (TestObject)TypeAccessor.CreateInstance(typeof(TestObject)); Type type = o.GetType(); Assert.IsNull(Attribute.GetCustomAttribute(type.GetMethod("Method1"), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetMethod("Method2"), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetMethod("Method3"), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetMethod("Method4"), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetProperty("Prop1").GetGetMethod(), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetProperty("Prop1").GetSetMethod(), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetProperty("Prop2").GetGetMethod(), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetProperty("Prop2").GetSetMethod(), typeof(NonInheritedAttribute))); Assert.IsNotNull(Attribute.GetCustomAttribute(type.GetField("_prop3", BindingFlags.Instance | BindingFlags.NonPublic), typeof(NonInheritedAttribute))); NonInheritedAttribute attribute = (NonInheritedAttribute) Attribute.GetCustomAttribute(type.GetMethod("Method5"), typeof(NonInheritedAttribute)); Assert.IsNotNull(attribute); Assert.AreEqual("SomeValue", attribute.NamedArgument); }