Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public T MapToInstance(IMappedType data)
        {
            if (TryAndLoadClonedTypeAssembly())
            {
                object result = _objectsMapperTo.Map(data);
                return((T)result);
            }

            return(default(T));
        }
Пример #2
0
 public virtual T BytesToObject(byte[] bytes)
 {
     if (_useClonedType)
     {
         MethodInfo method = this.GetType().GetMethod("DeSerializeBytesToObject");
         method = method.MakeGenericMethod(new Type[] { Mapper.GetMappedType() });
         IMappedType clonedObj = (IMappedType)method.Invoke(this, new object[] { bytes });
         return(_mapper.MapToInstance(clonedObj));
     }
     return(DeSerializeBytesToObject <T>(bytes));
 }
Пример #3
0
 public virtual byte[] ObjectToBytes(T data)
 {
     if (_useClonedType)
     {
         IMappedType clonedObj = _mapper.MapFromInstance(data);
         MethodInfo  method    = this.GetType().GetMethod("SerializeObjectToBytes");
         method = method.MakeGenericMethod(new Type[] { Mapper.GetMappedType() });
         return((byte[])method.Invoke(this, new object[] { clonedObj }));
     }
     return(SerializeObjectToBytes <T>(data));
 }
Пример #4
0
        /// <summary>Adds a property/field to the mapping.</summary>
        /// <typeparam name="T">The <see cref="Type"/> associated with the column mapping.</typeparam>
        /// <param name="mappedType">
        ///     An instance of <see cref="IMappedType{T}"/> containing the current mapping.
        /// </param>
        /// <param name="propertyName">
        ///     An <see cref="Expression{T}"/> selecting the property/field to add to the mapping.
        /// </param>
        /// <returns>
        ///     An instance of <see cref="PropertyMapping{T}"/> mapped to the property/field
        ///     specified in the <paramref name="propertyName"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the <paramref name="mappedType"/> or <paramref name="propertyName"/> parameter is <c>null</c>.
        /// </exception>
        public static PropertyMapping <T> MapProperty <T>(this IMappedType <T> mappedType, Expression <Func <T, object> > propertyName)
        {
            if (mappedType == null)
            {
                throw new ArgumentNullException(nameof(mappedType));
            }

            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            return(mappedType.MapProperty(GetMemberName(propertyName)));
        }
Пример #5
0
        /// <summary>Adds a property/field to the mapping.</summary>
        /// <typeparam name="T">The <see cref="Type"/> associated with the column mapping.</typeparam>
        /// <param name="mappedType">
        ///     An instance of <see cref="IMappedType{T}"/> containing the current mapping.
        /// </param>
        /// <param name="propertyName">
        ///     The name of the property/field to add to the mapping.
        /// </param>
        /// <returns>
        ///     An instance of <see cref="PropertyMapping{T}"/> mapped to the property/field
        ///     specified in the <paramref name="propertyName"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the <paramref name="mappedType"/> or <paramref name="propertyName"/> parameter
        ///     is <c>null</c>, an empty string, or only consists of white-space characters.
        /// </exception>
        public static PropertyMapping <T> MapProperty <T>(this IMappedType <T> mappedType, string propertyName)
        {
            if (mappedType == null)
            {
                throw new ArgumentNullException(nameof(mappedType));
            }

            if (String.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            var propertyMapping = new PropertyMapping <T>() as IPropertyMapping <T>;

            propertyMapping.MappedType   = mappedType;
            propertyMapping.PropertyName = propertyName;

            return(propertyMapping as PropertyMapping <T>);
        }
Пример #6
0
        /// <summary>Copies the column mappings mapped from one <see cref="Type"/> to another.</summary>
        /// <typeparam name="T">The <see cref="Type"/> associated with the column mapping.</typeparam>
        /// <param name="destinationMappedType">
        ///     An instance of <see cref="MappedType{T}"/> where the column mappings are to be copied to.
        /// </param>
        /// <param name="sourceMappedType">
        ///     An instance of <see cref="IMappedType"/> containing the column mappings that are to be copied.
        /// </param>
        /// <returns>
        ///     The instance of <see cref="MappedType{T}"/> provided via the <paramref name="destinationMappedType"/>
        ///     parameter including copies of each of the column mappings defined in the <paramref name="mappings"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the <paramref name="destinationMappedType"/> or
        ///     <paramref name="sourceMappedType"/> parameter is <c>null</c>.
        /// </exception>
        public static MappedType <T> CopyMappingsFrom <T>(this MappedType <T> destinationMappedType, IMappedType sourceMappedType)
        {
            if (destinationMappedType == null)
            {
                throw new ArgumentNullException(nameof(destinationMappedType));
            }

            if (sourceMappedType == null)
            {
                throw new ArgumentNullException(nameof(sourceMappedType));
            }

            foreach (var mapping in sourceMappedType.MappedColumns)
            {
                if (destinationMappedType.MappedColumns.ContainsKey(mapping.Key))
                {
                    destinationMappedType.MappedColumns[mapping.Key] = mapping.Value;
                }
                else
                {
                    destinationMappedType.MappedColumns.Add(mapping.Key, mapping.Value);
                }
            }

            return(destinationMappedType);
        }