public void TestGetAttributeOfEnum() { Assert.IsNull(ReflectionHelper.GetAttributeOfEnum<Attributes.DescriptionAttribute, MyEnum>(MyEnum.NoAttribute)); Assert.IsInstanceOfType(ReflectionHelper.GetAttributeOfEnum<Attributes.DescriptionAttribute, MyEnum>(MyEnum.WithAttribute), typeof(Attributes.DescriptionAttribute)); var myModel = new MyModel {EnumProperty = MyEnum.WithAttribute}; Assert.IsNotNull(ReflectionHelper.GetAttributeOfEnum<Attributes.DescriptionAttribute, MyEnum>(myModel.EnumProperty)); Assert.IsInstanceOfType(ReflectionHelper.GetAttributeOfEnum<Attributes.DescriptionAttribute, MyEnum>(myModel.EnumProperty), typeof(Attributes.DescriptionAttribute)); }
public void TestGetAttributeOfProperty() { var myModel = new MyModel(); Assert.IsNull(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.NoAttribute)); Assert.IsInstanceOfType(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.WithAttribute), typeof(Attributes.DescriptionAttribute)); myModel.WithAttribute = "hallo welt"; Assert.IsInstanceOfType(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.WithAttribute), typeof(Attributes.DescriptionAttribute)); myModel = new MyModel(); Assert.IsNull(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.FieldNoAttribute)); Assert.IsNull(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.FieldWithAttribute)); myModel.FieldWithAttribute = "hallo welt"; Assert.IsNull(ReflectionHelper.GetAttributeOfProperty<Attributes.DescriptionAttribute>(() => myModel.FieldWithAttribute)); }
public void TestGetAttributeOfMethod() { var myModel = new MyModel(); Assert.IsNull(ReflectionHelper.GetAttributeOfMethod<Attributes.DescriptionAttribute>(() => myModel.MethodNoAttribute())); Assert.IsInstanceOfType(ReflectionHelper.GetAttributeOfMethod<Attributes.DescriptionAttribute>(() => myModel.MethodWithAttribute()), typeof(Attributes.DescriptionAttribute)); }