コード例 #1
0
        public void Reflex_PropertyHasAttribute_object_str_Type_ret_bool()
        {
            // Prepara
            ClasePruebaKeyField objeto = new ClasePruebaKeyField();

            // Ejecuta
            bool hasAttributeKey   = Reflex.PropertyHasAttribute(objeto, "FieldStr", typeof(KeyAttribute));
            bool hasAttributeField = Reflex.PropertyHasAttribute(objeto, "FieldStr", typeof(FieldAttribute));

            // Comprueba
            Assert.IsTrue(hasAttributeKey);
            Assert.IsFalse(hasAttributeField);
        }
コード例 #2
0
        public void Reflex_GetPropertiesNameAndValueWithAttributes_object_variosAtributos_ArrayType_ret_Dictionary_str_object()
        {
            // Prepara
            DateTime            dtAhora = DateTime.Now;
            ClasePruebaKeyField objeto  = new ClasePruebaKeyField
            {
                FieldBool = true,
                FieldDT   = dtAhora,
                FieldInt  = 115,
                FieldStr  = "Hello World!"
            };

            // Ejecuta
            Dictionary <string, object> dicProperties = Reflex.GetPropertiesNameAndValueWithAttributes(objeto, typeof(FieldAttribute), typeof(KeyAttribute));

            // Comprueba
            Assert.AreEqual(true, (bool)dicProperties["FieldBool"]);
            Assert.IsFalse(dicProperties.ContainsKey("FieldDT"));
            Assert.IsFalse(dicProperties.ContainsKey("FieldInt"));
            Assert.AreEqual("Hello World!", (string)dicProperties["FieldStr"]);
        }
コード例 #3
0
        public void Reflex_GetPropertiesInfoWithAttributes_object_variosAtributos_ArrayType_ret_ListPI()
        {
            // Prepara
            ClasePruebaKeyField objeto = new ClasePruebaKeyField
            {
                FieldBool = true,
                FieldDT   = DateTime.MinValue,
                FieldInt  = 0,
                FieldStr  = string.Empty
            };

            // Ejecuta
            List <PropertyInfo> pis = Reflex.GetPropertiesInfoWithAttributes(objeto, typeof(FieldAttribute), typeof(KeyAttribute));

            // Comprueba
            List <string> nombresProp = pis.ConvertAll(pi => pi.Name);

            Assert.IsTrue(nombresProp.IndexOf("FieldBool") >= 0);
            Assert.IsTrue(nombresProp.IndexOf("FieldDT") < 0);
            Assert.IsTrue(nombresProp.IndexOf("FieldInt") < 0);
            Assert.IsTrue(nombresProp.IndexOf("FieldStr") >= 0);
        }