///<summary> /// DEMO ///</summary> private void _doDemoOfAttribute_MyCustomAttribute() { //SOME CODE... object[] attributes_object = this.GetType().GetCustomAttributes(typeof(MyCustomAttribute), true); MyCustomAttribute myCustomAttribute = attributes_object[0] as MyCustomAttribute; Debug.Log(" CustomAttribute: " + myCustomAttribute.message_string); }
public override void Execute() { Type typeOfWeapon = Type.GetType(nameof(Weapon)); MyCustomAttribute myAttribute = (MyCustomAttribute)Attribute.GetCustomAttribute(typeOfWeapon, typeof(MyCustomAttribute)); Console.WriteLine($"Class description: {myAttribute.Description}"); }
public override void Execute() { string revisionAsString = this.Data[0]; Type typeOfWeapon = Type.GetType(nameof(Weapon)); MyCustomAttribute myAttr = (MyCustomAttribute)Attribute.GetCustomAttribute(typeOfWeapon, typeof(MyCustomAttribute)); Console.WriteLine($"{revisionAsString}: {myAttr.Revision}"); }
public override void Execute() { string reviewersString = this.Data[0]; Type type = Type.GetType(nameof(Weapon)); MyCustomAttribute myAttr = (MyCustomAttribute)Attribute.GetCustomAttribute(type, typeof(MyCustomAttribute)); Console.WriteLine($"{reviewersString}: {string.Join(", ", myAttr.Reviewers)}"); }
public void ShouldBeAbleToSeeCustomAttribute() { MyCustomAttribute attribute = typeof(ReflectingOnAttributes) .GetMethods()[0] .GetCustomAttributes(false)[0] as MyCustomAttribute; string x = attribute.Value; FluentAssertions.AssertionExtensions.Should(x).Be("One"); }
public override void Execute() { string author = this.Data[0]; Type weaponType = Type.GetType(nameof(Weapon)); MyCustomAttribute myAttr = (MyCustomAttribute)Attribute.GetCustomAttribute(weaponType, typeof(MyCustomAttribute)); Console.WriteLine($"{author}: {myAttr.Author}"); }
public void ShouldCollectTypeAttributes() { List <Attribute> attributes = MetadataRepository.GetAttributes(new MyEntity()).ToList(); Assert.AreEqual <int>(1, attributes.Count); MyCustomAttribute attr = attributes[0] as MyCustomAttribute; Assert.IsNotNull(attr); Assert.AreEqual <string>("MyEntity", attr.Name); }
public void NonEmptyNonOverridenGetHashCode () { MyCustomAttribute a1 = new MyCustomAttribute (null); MyCustomAttribute a2 = new MyCustomAttribute (null); Assert.AreEqual (a1.GetHashCode (), a2.GetHashCode (), "identical arguments"); Assert.AreEqual (a1.GetHashCode (), a1.TypeId.GetHashCode (), "TypeId"); MyCustomAttribute a3 = new MyCustomAttribute ("a"); MyCustomAttribute a4 = new MyCustomAttribute ("b"); Assert.AreNotEqual (a3.GetHashCode (), a4.GetHashCode (), "non-identical-arguments"); MyOwnCustomAttribute b1 = new MyOwnCustomAttribute (null); Assert.AreNotEqual (a1.GetHashCode (), b1.GetHashCode (), "non-identical-types"); }
public void TestEquality () { MyCustomAttribute a = new MyCustomAttribute ("one"); MyCustomAttribute b = new MyCustomAttribute ("two"); MyCustomAttribute c = new MyCustomAttribute ("one"); MyCustomAttribute d = a; Assert.IsTrue (a.Equals (c), "#1"); Assert.IsTrue (c.Equals (a), "#2"); Assert.IsFalse (c.Equals (b), "#3"); Assert.IsFalse (b.Equals (a), "#4"); Assert.IsFalse (b.Equals (c), "#5"); Assert.IsTrue (a.Equals (a), "#6"); Assert.IsTrue (a.Equals (d), "#7"); Assert.IsFalse (a.Equals (null), "#8"); }