コード例 #1
0
        public void ClassAttributes()
        {
            IClassMapping rm = new AttributeOverXmlClassMapping(GetXmlClassMapping(typeof (MixAddress)));
            var mi = new List<Attribute>(rm.GetClassAttributes());
            Assert.AreEqual(0, mi.Count);

            rm = new AttributeOverXmlClassMapping(GetXmlClassMapping(typeof (MixSuricato)));
            mi = new List<Attribute>(rm.GetClassAttributes());
            Assert.AreEqual(2, mi.Count);

            rm = new XmlOverAttributeClassMapping(GetXmlClassMapping(typeof (MixSuricato)));
            mi = new List<Attribute>(rm.GetClassAttributes());
            Assert.AreEqual(2, mi.Count);
        }
コード例 #2
0
        public void MemberAttributes()
        {
            IClassMapping rm = new AttributeOverXmlClassMapping(GetXmlClassMapping(typeof (MixAddress)));
            MemberInfo mi = typeof (MixAddress).GetField("floor");
            var mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(1, mas.Count);

            mi = typeof (MixAddress).GetProperty("Zip");
            mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(3, mas.Count);

            mi = typeof (MixAddress).GetProperty("Id");
            mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(2, mas.Count);
            foreach (var ma in mas)
            {
                var ra = ma as RangeAttribute;
                if (ra != null)
                {
                    Assert.AreEqual(2000, ra.Max);
                }
            }

            rm = new XmlOverAttributeClassMapping(GetXmlClassMapping(typeof (MixAddress)));
            mi = typeof (MixAddress).GetField("floor");
            mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(1, mas.Count);

            mi = typeof (MixAddress).GetProperty("Zip");
            mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(3, mas.Count);

            mi = typeof (MixAddress).GetProperty("Id");
            mas = new List<Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual(2, mas.Count);
            foreach (var ma in mas)
            {
                var ra = ma as RangeAttribute;
                if (ra != null)
                {
                    Assert.AreEqual(9999, ra.Max);
                }
            }
        }
コード例 #3
0
 public IClassMapping GetClassMapping(System.Type clazz, ValidatorMode mode)
 {
     IClassMapping externalDefinition;
     IClassMapping result = null;
     switch (mode)
     {
         case ValidatorMode.UseAttribute:
             break;
         case ValidatorMode.UseExternal:
             result = GetExternalDefinitionFor(clazz);
             if (result == null)
             {
                 log.Warn(string.Format("External definition not foud for class {0} in ValidatorMode.UseExternal mode.", clazz.FullName));
                 return null; // <<<<<===
             }
             break;
         case ValidatorMode.OverrideAttributeWithExternal:
             externalDefinition = GetExternalDefinitionFor(clazz);
             if (externalDefinition != null)
             {
                 log.Debug("XmlOverAttribute applied for " + clazz.FullName);
                 result = new XmlOverAttributeClassMapping(externalDefinition);
             }
             break;
         case ValidatorMode.OverrideExternalWithAttribute:
             externalDefinition = GetExternalDefinitionFor(clazz);
             if (externalDefinition != null)
             {
                 log.Debug("AttributeOverXml applied for " + clazz.FullName);
                 result = new AttributeOverXmlClassMapping(externalDefinition);
             }
             break;
     }
     if(result != null)
     {
         return result;
     }
     else
     {
         log.Debug("Reflection applied for " + clazz.FullName);
         return new ReflectionClassMapping(clazz);
     }
 }
コード例 #4
0
        public void Members()
        {
            IClassMapping rm = new AttributeOverXmlClassMapping(GetXmlClassMapping(typeof (MixAddress)));
            var mi = new List<MemberInfo>(rm.GetMembers());
            Assert.AreEqual(16, mi.Count); // the members of the class by reflection

            rm = new XmlOverAttributeClassMapping(GetXmlClassMapping(typeof (MixAddress)));
            mi = new List<MemberInfo>(rm.GetMembers());
            Assert.AreEqual(16, mi.Count);
        }
コード例 #5
0
 public void GetEntityType()
 {
     IClassMapping rm = new XmlOverAttributeClassMapping(GetXmlClassMapping(typeof (MixAddress)));
     Assert.AreEqual(typeof (MixAddress), rm.EntityType);
 }
コード例 #6
0
 public static IClassMapping GetClassMapping(Type type, ValidatorMode mode)
 {
     IClassMapping result = null;
     switch (mode) {
         case ValidatorMode.UseAttribute:
             break;
         case ValidatorMode.UseXml:
             result = new XmlClassMapping(GetXmlDefinitionFor(type));
             break;
         case ValidatorMode.OverrideAttributeWithXml:
             var xmlDefinition = GetXmlDefinitionFor(type);
             if (xmlDefinition != null)
                 result = new XmlOverAttributeClassMapping(xmlDefinition);
             break;
         case ValidatorMode.OverrideXmlWithAttribute:
             var xmlDefinition2 = GetXmlDefinitionFor(type);
             if (xmlDefinition2 != null)
                 result = new AttributeOverXmlClassMapping(xmlDefinition2);
             break;
     }
     return result ?? new ReflectionClassMapping(type);
 }