Exemplo n.º 1
0
    ///<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);
    }
Exemplo n.º 2
0
    public override void Execute()
    {
        Type typeOfWeapon = Type.GetType(nameof(Weapon));

        MyCustomAttribute myAttribute = (MyCustomAttribute)Attribute.GetCustomAttribute(typeOfWeapon, typeof(MyCustomAttribute));

        Console.WriteLine($"Class description: {myAttribute.Description}");
    }
Exemplo n.º 3
0
    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}");
    }
Exemplo n.º 4
0
    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)}");
    }
Exemplo n.º 5
0
            public void ShouldBeAbleToSeeCustomAttribute()
            {
                MyCustomAttribute attribute =
                    typeof(ReflectingOnAttributes)
                    .GetMethods()[0]
                    .GetCustomAttributes(false)[0] as MyCustomAttribute;
                string x = attribute.Value;

                FluentAssertions.AssertionExtensions.Should(x).Be("One");
            }
Exemplo n.º 6
0
    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}");
    }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
		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");
		}
Exemplo n.º 9
0
		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");
		}
Exemplo n.º 10
0
		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");
		}
Exemplo n.º 11
0
		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");
		}