예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="element"></param>
        /// <param name="mappingNamespace">Namespace informado no mapeamento.</param>
        /// <param name="mappingAssembly">Assembly informado no mapeamento.</param>
        public PropertyMapping(XmlElement element, string mappingNamespace, string mappingAssembly)
        {
            Name   = GetAttributeString(element, "name", true);
            Column = GetAttributeString(element, "column", Name);
            var value = GetAttributeString(element, "parameterType", "Field");

            ParameterType = (PersistenceParameterType)Enum.Parse(typeof(PersistenceParameterType), value, true);
            value         = GetAttributeString(element, "size");
            var size = 0;

            if (Helper.GDAHelper.TryParse(value, out size))
            {
                Size = size;
            }
            bool option = false;

            if (Helper.GDAHelper.TryParse(GetAttributeString(element, "not-persists"), out option))
            {
                IsNotPersists = option;
            }
            if (Helper.GDAHelper.TryParse(GetAttributeString(element, "not-null"), out option))
            {
                IsNotNull = option;
            }
            value     = GetAttributeString(element, "direction", "InputOutput");
            Direction = (DirectionParameter)Enum.Parse(typeof(DirectionParameter), value, true);
            var gkElement = FirstOrDefault <XmlElement>(element.GetElementsByTagName("generator"));

            if (gkElement != null)
            {
                GeneratorKeyName = GetAttributeString(gkElement, "name", true);
            }
            var fkElement = FirstOrDefault <XmlElement>(element.GetElementsByTagName("foreignKey"));

            if (fkElement != null)
            {
                ForeignKey = new ForeignKeyMapping(fkElement, mappingNamespace, mappingAssembly);
            }
            var fmElement = FirstOrDefault <XmlElement>(element.GetElementsByTagName("foreignMember"));

            if (fmElement != null)
            {
                ForeignMember = new ForeignMemberMapping(fmElement, mappingNamespace, mappingAssembly);
            }
            Validators = new List <ValidatorMapping>();
            foreach (XmlElement i in element.GetElementsByTagName("validator"))
            {
                var vm = new ValidatorMapping(i);
                if (!Validators.Exists(f => f.Name == vm.Name))
                {
                    Validators.Add(vm);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Constrói uma instancia do mapeamento da propriedade.
 /// </summary>
 /// <param name="name">Nome da propriedade</param>
 /// <param name="column">Nome da coluna relacionada com a propriedade.</param>
 /// <param name="parameterType">Tipo do parametro do mapeamento.</param>
 /// <param name="size">Tamanho da coluna.</param>
 /// <param name="isNotPersists">Identifica se a propriedade não para ser persistida.</param>
 /// <param name="isNotNull">Identifica se a propriedade aceita valores nulos.</param>
 /// <param name="direction">Direção do mapeamento da propriedade.</param>
 /// <param name="generatorKeyName">Nome do gerador de chave usado pela propriedade.</param>
 /// <param name="foreignKey">Dados da chave estrangeira relacionada.</param>
 /// <param name="foreignMember">Dados do membro estrangeiro relacionado.</param>
 /// <param name="validators">Validadores aplicados a propriedade.</param>
 public PropertyMapping(string name, string column, PersistenceParameterType parameterType, int size, bool isNotPersists, bool isNotNull, DirectionParameter direction, string generatorKeyName, ForeignKeyMapping foreignKey, ForeignMemberMapping foreignMember, IEnumerable <ValidatorMapping> validators)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     this.Name             = name;
     this.Column           = string.IsNullOrEmpty(column) ? name : column;
     this.ParameterType    = parameterType;
     this.Size             = size;
     this.IsNotPersists    = isNotPersists;
     this.IsNotNull        = isNotNull;
     this.Direction        = direction;
     this.GeneratorKeyName = generatorKeyName;
     this.ForeignKey       = foreignKey;
     this.ForeignMember    = foreignMember;
     Validators            = new List <ValidatorMapping>();
     if (validators != null)
     {
         foreach (var i in validators)
         {
             if (!Validators.Exists(f => f.Name == i.Name))
             {
                 Validators.Add(i);
             }
         }
     }
 }