Exemplo n.º 1
0
        public static T InstanciarEntidad(DtoBase entidad, Dictionary <Type,
                                                                       string> _diccionario)
        {
            if (!_diccionario.TryGetValue(entidad.GetType(), out var tipoEntidad))
            {
                throw new Exception($"No hay {entidad.GetType()} para Instanciar.");
            }
            var T = InstanciarEntidad(tipoEntidad);

            if (T == null)
            {
                throw new Exception($"Ocurrió un error al Instanciar { entidad.GetType() }");
            }
            return(T);
        }
Exemplo n.º 2
0
        public static void TrimStringProperties(this DtoBase entity)
        {
            var dtoType = entity.GetType();

            foreach (var prop in dtoType.GetProperties())
            {
                if (prop.PropertyType == typeof(string))
                {
                    var originalValue = prop.GetValue(entity)?.ToString();
                    if (originalValue != null)
                    {
                        var trimmed = originalValue.Trim();
                        prop.SetValue(entity, trimmed);
                    }
                }
                else if (prop.PropertyType.IsSubclassOf(typeof(DtoBase)))
                {
                    var dtoForSave = prop.GetValue(entity);
                    if (dtoForSave != null)
                    {
                        (dtoForSave as DtoBase).TrimStringProperties();
                    }
                }
                else
                {
                    var propType  = prop.PropertyType;
                    var isDtoList = propType.IsList() &&
                                    propType.GenericTypeArguments[0].IsSubclassOf(typeof(DtoBase));

                    if (isDtoList)
                    {
                        var dtoList = prop.GetValue(entity);
                        if (dtoList != null)
                        {
                            foreach (var dto in dtoList.Enumerate <DtoBase>())
                            {
                                dto.TrimStringProperties();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public virtual bool Equals(DtoBase other)
 {
     return (null != other) && (this.GetType() == other.GetType()) && (other.Id == this.Id);
 }