Exemple #1
0
        protected override void Initialize()
        {
            clazz =
                ReflectHelper.ClassForFullName(
                    TypeNameParser.Parse(meta.name, meta.rootMapping.@namespace, meta.rootMapping.assembly).ToString());
            classAttributes = meta.attributename == null
                                                ? new List <Attribute>(0)
                                                : new List <Attribute>(meta.attributename.Length);

            List <MemberInfo> lmembers = meta.property == null
                                                        ? new List <MemberInfo>(0)
                                                        : new List <MemberInfo>(meta.property.Length);

            if (meta.attributename != null)
            {
                log.Debug("Looking for class attributes");
                foreach (NhvmClassAttributename attributename in meta.attributename)
                {
                    log.Info("Attribute to look for = " + GetText(attributename));
                    Attribute classAttribute = RuleAttributeFactory.CreateAttributeFromClass(clazz, attributename);
                    classAttributes.Add(classAttribute);
                }
            }

            if (meta.property != null)
            {
                foreach (NhvmProperty property in meta.property)
                {
                    MemberInfo currentMember = TypeUtils.GetPropertyOrField(clazz, property.name);

                    if (currentMember == null)
                    {
                        throw new InvalidPropertyNameException(property.name, clazz);
                    }

                    log.Info("Looking for rules for property : " + property.name);
                    lmembers.Add(currentMember);

                    // creation of member attributes
                    foreach (object rule in property.Items)
                    {
                        Attribute thisAttribute = RuleAttributeFactory.CreateAttributeFromRule(rule, meta.rootMapping.assembly,
                                                                                               meta.rootMapping.@namespace);

                        if (thisAttribute != null)
                        {
                            log.Info(string.Format("Adding member {0} to dictionary with attribute {1}", currentMember.Name, thisAttribute));
                            if (!membersAttributesDictionary.ContainsKey(currentMember))
                            {
                                membersAttributesDictionary.Add(currentMember, new List <Attribute>());
                            }

                            membersAttributesDictionary[currentMember].Add(thisAttribute);
                        }
                    }
                }
            }
            members = lmembers.ToArray();
        }
        public void CreateAttributeFromRule()
        {
            // Testing exception when a new element is added in XSD but not in factory
            Assert.That(() => RuleAttributeFactory.CreateAttributeFromRule("AnyObject", "", ""), Throws.TypeOf <ValidatorConfigurationException>());

            // For wellKnownRules we can't do a sure tests because we don't have a way to auto-check all
            // classes derivered from serialization.
        }