Ejemplo n.º 1
0
 public TDestination Map <TDestination>(object source, TDestination destination = null)
     where TDestination : class
 {
     if (destination != null)
     {
         return(source.Adapt(destination));
     }
     return(source.Adapt <TDestination>());
 }
Ejemplo n.º 2
0
        public static ValidationErrors Value(object target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            // Self validation should be tried first; then the validator should be created
            ISelfValidation sv = target.Adapt <ISelfValidation>();

            if (sv != null)
            {
                return(sv.Validate());
            }

            Validator v = Validator.CreateSelfValidator(target.GetType());

            if (v != null)
            {
                return(v.Validate(target));
            }

            v = Validator.Create(target.GetType());
            if (v != null)
            {
                return(v.Validate(target));
            }

            throw ValidationFailure.ValidationNotDefined();
        }
        private EntityCore GetByType(object src)
        {
            EntityCore res = new EntityCore();

            if (src.GetType() == typeof(LeadViewModel))
            {
                res = src.Adapt <Lead>(config);
            }

            if (src.GetType() == typeof(ContactViewModel))
            {
                res = src.Adapt <Contact>(config);
            }

            return(res);
        }
Ejemplo n.º 4
0
        public TDestination Map <TDestination>(object source)
        {
            Type sourceType = source.GetType().Namespace == "System.Data.Entity.DynamicProxies"
                ? source.GetType().BaseType
                : source.GetType();

            return((TDestination)source.Adapt(sourceType, typeof(TDestination), _mapsterConfiguration.Configuration));
        }
 private T AdaptTypeToDesirableType <T>(object item)
 {
     if (item.GetType() == typeof(T))
     {
         return((T)item);
     }
     return(item.Adapt <T>());
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Imports / maps the given Poco to the current Bean.
        /// Poco properties and Bean properties must match exactly.
        /// </summary>
        /// <param name="poco">Simple Poco instance</param>
        public Bean ImportPoco(object poco)
        {
            var config = new TypeAdapterConfig();

            config.ForType(poco.GetType(), typeof(Dictionary <string, object>)).IgnoreNullValues(true);

            return(Import(poco.Adapt <Dictionary <string, object> >(config)));
        }
Ejemplo n.º 7
0
        public static T MapTo <T>(this object obj)
        {
            if (obj == null)
            {
                return(default(T));
            }

            return(obj.Adapt <T>());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 对象映射
        /// </summary>
        /// <typeparam name="TDestination"></typeparam>
        /// <param name="source"></param>
        /// <param name="ignoreNames">忽略字段</param>
        /// <returns></returns>
        public static TDestination MapTo <TDestination>(this object source, IEnumerable <string> ignoreNames)
        {
            if (source == null)
            {
                return(default(TDestination));
            }
            var setting = new TypeAdapterConfig().NewConfig(source.GetType(), typeof(TDestination)).Ignore(ignoreNames.ToArray());

            return(source.Adapt <TDestination>(setting.Config));
        }
Ejemplo n.º 9
0
        private Object ConvertEntityCollectionToDto(object elements)
        {
            var type1 = elements.GetType();

            genericListType = listType.MakeGenericType(this.dtoType);

            var array = elements.Adapt(type1, this.genericListType);

            return(array);
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Converts an object to another using Mapster library. Creates a new object of
 ///     <typeparamref name="TDestination" />.
 ///     There must be a mapping between objects before calling this method.
 /// </summary>
 /// <typeparam name="TDestination">Type of the destination object</typeparam>
 /// <param name="source">Source object</param>
 public static TDestination MapTo <TDestination>([NotNull] this object source)
 {
     return(source.Adapt <TDestination>(TypeAdapterConfig.GlobalSettings));
 }
Ejemplo n.º 11
0
 public TTarget Map <TTarget>(object source)
 {
     return(source.Adapt <TTarget>());
 }
Ejemplo n.º 12
0
        private object ConvertIt(object @object, Type from, Type to)
        {
            var toObject = @object.Adapt(from, to);

            return(toObject);
        }
 public static List <TTarget> MapToList <TTarget>(this object source)
 {
     return(source.Adapt <List <TTarget> >());
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 对象映射
 /// </summary>
 /// <param name="source"></param>
 /// <param name="destination"></param>
 /// <param name="sourceType"></param>
 /// <param name="destinationType"></param>
 /// <returns></returns>
 public static object MapTo(this object source, object destination, Type sourceType, Type destinationType)
 {
     return(source.Adapt(destination, sourceType, destinationType));
 }
Ejemplo n.º 15
0
 public void Map(object source, object target)
 {
     source.Adapt(target);
 }
Ejemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TDestination"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public TDestination Map <TDestination>(object source)
 {
     return(source.Adapt <TDestination>());
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Converts an object to another using Mapster library. Creates a new object of
 ///     <typeparamref name="TDestination" />.
 ///     There must be a mapping between objects before calling this method.
 /// </summary>
 /// <typeparam name="TDestination">Type of the destination object</typeparam>
 /// <param name="source">Source object</param>
 public static TDestination MapTo <TDestination>(this object source)
 {
     return(source.Adapt <TDestination>());
 }
Ejemplo n.º 18
0
        /// <summary>
        /// 对象映射
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="sourceType"></param>
        /// <param name="destinationType"></param>
        /// <param name="ignoreNames">忽略字段</param>
        /// <returns></returns>
        public static object MapTo(this object source, object destination, Type sourceType, Type destinationType, params string[] ignoreNames)
        {
            var setting = new TypeAdapterConfig().NewConfig(sourceType, destinationType).Ignore(ignoreNames);

            return(source.Adapt(destination, sourceType, destinationType, setting.Config));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 对象映射
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="sourceType"></param>
        /// <param name="destinationType"></param>
        /// <param name="ignoreNames">忽略字段</param>
        /// <returns></returns>
        public static object MapTo(this object source, object destination, Type sourceType, Type destinationType, IEnumerable <string> ignoreNames)
        {
            var setting = new TypeAdapterConfig().NewConfig(sourceType, destinationType).Ignore(ignoreNames.ToArray());

            return(source.Adapt(destination, sourceType, destinationType, setting.Config));
        }
Ejemplo n.º 20
0
 public Task <TD> Map <TD>(object message)
 {
     return(Task.FromResult(message.Adapt <TD>()));
 }
Ejemplo n.º 21
0
 public TDestination MapTo <TDestination>(object source) => source.Adapt <TDestination>();
Ejemplo n.º 22
0
 /// <summary>
 /// Adapt extension of Mapster
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static T MapType <T>(this object obj)
 => obj.Adapt <T>();
Ejemplo n.º 23
0
 public static TTarget MapTo <TTarget>(this object source)
 {
     return(source.Adapt <TTarget>());
 }
Ejemplo n.º 24
0
 public TTarget Map <TTarget>(object source) where TTarget : class
 {
     return(source.Adapt <TTarget>());
 }
Ejemplo n.º 25
0
 public TDestination Map <TDestination>(object source)
 {
     return(source.Adapt <TDestination>(_mapsterConfiguration.Configuration));
 }
Ejemplo n.º 26
0
 public object Map(object source, Type targetType)
 {
     return(source.Adapt(source.GetType(), targetType));
 }
Ejemplo n.º 27
0
        public TDestination Map <TDestination>(object source)
        {
            TypeAdapterConfig typeAdapterConfig = TypeAdapterConfig <object, TDestination> .NewConfig().PreserveReference(true).Config;

            return(source.Adapt <TDestination>(typeAdapterConfig));
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Mapping to an existing object.
 ///
 /// </summary>
 /// <typeparam name="TDestination"></typeparam>
 /// <param name="source"></param>
 /// <param name="destination"></param>
 /// <returns></returns>
 public static TDestination MapTo <TDestination>(this object source, TDestination destination)
 {
     return(source.Adapt(destination));
 }