public MemberConfigurationEntityCacheExpression <TSource, TDestination, TMember, TKey, TEntity> Entity <TEntity>(
            Expression <Func <TEntity, TMember> > entityValueExpression) where TEntity : class
        {
            var resolver =
                new EntityCacheMemberValueResolver <TSource, TDestination, TKey, TMember, TEntity>(
                    entityValueExpression);

            _memberConfigurationExpression.MapFrom(resolver, _sourceKeyMember);

            return(new MemberConfigurationEntityCacheExpression <TSource, TDestination, TMember, TKey, TEntity>(
                       resolver));
        }
        public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression)
        {
            var sourceMemberAttribute = memberConfigurationExpression.DestinationMember.GetCustomAttribute <SourceMemberAttribute>();

            if (sourceMemberAttribute != null)
            {
                memberConfigurationExpression.MapFrom(Type, sourceMemberAttribute.Name);
            }
            else
            {
                memberConfigurationExpression.MapFrom(Type);
            }
        }
Beispiel #3
0
        private void PropertyBuilder(IMemberConfigurationExpression <Product, ProductResponse, string> obj)
        {
            var url = "https://localhost:44306/content";

            obj.MapFrom(s => s.PictureUrl);
            obj.AddTransform(x => string.IsNullOrEmpty(x) ? "No url found.." : $"{url}/{x}");
        }
 private void DepartmentFamilies(IMemberConfigurationExpression <DepartmentEntity, DepartmentResource, CategoryFamily[]> opt)
 {
     opt.MapFrom((tr, a, b, map) => tr.CategoriesByFamily.Select(s => new CategoryFamily()
     {
         Name = s.Key, Categories = map.Mapper.Map <CategoryResource[]>(s.Value)
     }));
 }
Beispiel #5
0
 public static void MapFromPrice <TSource, TDestination, TMember>(
     this IMemberConfigurationExpression <TSource, TDestination, TMember> config,
     string listId)
     where TSource : ODataProductModel
 {
     config.MapFrom(model => model.GetPrice(listId));
 }
 public static void MapFromField <TSource, TDestination, TMember>(
     this IMemberConfigurationExpression <TSource, TDestination, TMember> config,
     string fieldId)
     where TSource : ODataProductModel
 {
     config.MapFrom((model, destination, member, context) => model.GetValue <TMember>(fieldId, context.GetMappingCulture()));
 }
 public static void MapFromField <TSource, TDestination, TMember>(
     this IMemberConfigurationExpression <TSource, TDestination, TMember> config,
     string fieldId,
     string culture)
     where TSource : ODataProductModel
 {
     config.MapFrom(model => model.GetValue <TMember>(fieldId, CultureInfo.GetCultureInfo(culture)));
 }
Beispiel #8
0
 private static void ResolveImageModelFromBlogPost <T>(IMemberConfigurationExpression <BlogPost, T, ImageViewModel> exp)
 {
     exp.MapFrom((blogPost, viewModel, image) =>
                 blogPost.Image == null ? null : new ImageViewModel()
     {
         UriPath = blogPost.Image.UriPath
     });
 }
Beispiel #9
0
 public void As <TResult>() where TResult : class
 {
     _configurationExpression.MapFrom(src =>
     {
         var session = _getSession();
         var id      = (object)_getSourceMember(src);
         return(session.Load <TResult>(id));
     });
 }
Beispiel #10
0
        public static void DropAndCreateCollection <TSource, TSourceItem, TDestination, TDestinationItem>
        (
            this IMemberConfigurationExpression <TSource, TDestination, ICollection <TDestinationItem> > config,
            Expression <Func <TSource, ICollection <TSourceItem> > > sourceCollectionSelector,
            Func <TSourceItem, TDestinationItem> projection = null,
            Action <TDestinationItem> removeCallback        = null,
            Func <TDestinationItem, bool> destinationFilter = null
        )
        {
            var dropAndCreateCollectionResolver = new DropAndCreateCollectionResolver <TSource, TSourceItem, TDestination, TDestinationItem>(projection, removeCallback, destinationFilter);

            config.MapFrom(dropAndCreateCollectionResolver, sourceCollectionSelector);
        }
    public static void NullSafeMapFrom <T, TResult>(this IMemberConfigurationExpression <T> opt, Expression <Func <T, TResult> > sourceMemberExpression)
    {
        var sourceMember = sourceMemberExpression.Compile();

        opt.MapFrom(src =>
        {
            try
            {
                return(sourceMember(src));
            }
            catch (NullReferenceException)
            {}
            return(default(TResult));
        });
    }
Beispiel #12
0
        public static void Unflatten <TSource, TDestination, TMember>(this IMemberConfigurationExpression <TSource, TDestination, TMember> config)
        {
            config.MapFrom((source, destination, member, resolutionContext) =>
            {
                string prefix = typeof(TMember).Name;

                TMember resolvedObject = (TMember)Activator.CreateInstance(typeof(TMember));

                PropertyInfo[] targetProperties = resolvedObject.GetType().GetProperties();

                foreach (var sourceMember in source.GetType().GetProperties())
                {
                    // find the matching target property and populate it
                    PropertyInfo matchedProperty = targetProperties.FirstOrDefault(p => sourceMember.Name == prefix + p.Name);

                    matchedProperty?.SetValue(resolvedObject, sourceMember.GetValue(source));
                }

                return(resolvedObject);
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TDestination"></typeparam>
        /// <typeparam name="TMember"></typeparam>
        /// <param name="config"></param>
        /// <param name="fieldId"></param>
        /// <param name="culture">If null, will take culture from the mapping context (i.e use together with .MapWithCultureTo(...)</param>
        public static void MapFromTextOptionLabel <TSource, TDestination, TMember>(
            this IMemberConfigurationExpression <TSource, TDestination, TMember> config,
            string fieldId,
            string culture = null)
            where TSource : ODataProductModel
        {
            Func <ODataProductModel, TDestination, TMember, ResolutionContext, string> mapping = (model, destination, member, context) =>
            {
                var field = IoC.Resolve <FieldDefinitionService>().Get <ProductArea>(fieldId);
                if (field == null)
                {
                    return(null);
                }
                var options = field.Option as TextOption;
                if (options == null)
                {
                    return(null);
                }

                var value = model.GetValue <object>(fieldId);

                var result = new List <string>();
                if (value is IList <string> values)
                {
                    foreach (var i in values)
                    {
                        AddLabel(options, i, culture ?? context.GetMappingCulture(), result);
                    }
                }
                else if (value != null)
                {
                    AddLabel(options, (string)value, culture ?? context.GetMappingCulture(), result);
                }

                return(string.Join(",", result));
            };

            config.MapFrom(mapping);
        }
Beispiel #14
0
 public static void SyncCollectionByKey <TSource, TSourceItem, TDestination, TDestinationItem, TKey>
 (
     this IMemberConfigurationExpression <TSource, TDestination, ICollection <TDestinationItem> > config,
     Expression <Func <TSource, ICollection <TSourceItem> > > sourceCollectionSelector,
     Func <TSourceItem, TKey> sourceKeySelector,
     Func <TDestinationItem, TKey> destinationSelector,
     Func <TSourceItem, TDestinationItem> createFunction   = null,
     Action <TSourceItem, TDestinationItem> updateFunction = null,
     Action <TDestinationItem> removeFunction        = null,
     bool keepRemovedItemsInDestinationCollection    = false,
     Func <TDestinationItem, bool> destinationFilter = null
 )
 {
     config.MapFrom(new SyncByKeyCollectionResolver <TSource, TSourceItem, TDestination, TDestinationItem, TKey>()
     {
         SourceKeySelector      = sourceKeySelector,
         DestinationKeySelector = destinationSelector,
         CreateFunction         = createFunction,
         UpdateFunction         = updateFunction,
         RemoveFunction         = removeFunction,
         KeepRemovedItemsInDestinationCollection = keepRemovedItemsInDestinationCollection,
         DestinationFilter = destinationFilter ?? (_ => true)
     }, sourceCollectionSelector);
 }
 private void MapFromMicrosoftPosters(IMemberConfigurationExpression <Post> opt)
 {
     opt.MapFrom(x => x.Comments.Where(c => c.Email.Contains("@microsoft.com")).Select(c => c.Email));
 }
Beispiel #16
0
        private void MapFileName(IMemberConfigurationExpression <BuildableProject, BuildableProjectDto, string> memberConfigurationExpression)
        {
            var pathProxy = ProvisioningServiceSingleton.Instance.GetService <IPathProxy>();

            memberConfigurationExpression.MapFrom(f => pathProxy.GetFileName(f.FilePath));
        }
Beispiel #17
0
 public static void ReadAsNumber(this IMemberConfigurationExpression <IDataReader> opt, string fieldName)
 {
     opt.MapFrom(reader => reader.GetDecimal(reader.GetOrdinal(fieldName)));
 }
Beispiel #18
0
 public static void ReadAsBoolean(this IMemberConfigurationExpression <IDataReader> opt, string fieldName)
 {
     opt.MapFrom(reader => reader.GetString(reader.GetOrdinal(fieldName)).ToUpper() == "Y");
 }
Beispiel #19
0
 /// <summary>
 /// 加载实体对象。
 /// <remarks></remarks>
 /// </summary>
 public void LoadEntity <TSource, TMember, TKey>(IMemberConfigurationExpression <TSource> opt,
                                                 Func <TSource, TKey> getId, Func <TKey, TMember> doLoad) where TMember : class
 {
     opt.Condition(src => (getId(src) != null));
     opt.MapFrom(src => CheckIdIsValid <TKey>(getId(src)) ? null : doLoad(getId(src)));
 }
 private void MapFromClaimType(IMemberConfigurationExpression <IEnumerable <Claim>, User, string> opts,
                               string claimType)
 {
     opts.MapFrom(src => src.First(c => c.Type == claimType).Value);
 }
Beispiel #21
0
 // Summary:
 //     Resolve destination member using a custom value resolver callback. Used instead
 //     of MapFrom when not simply redirecting a source member This method cannot be
 //     used in conjunction with LINQ query projection
 //
 // Parameters:
 //   resolver:
 //     Callback function to resolve against source type
 public static void ResolveUsing <TSource, TDestination, TMember, TResult>(this IMemberConfigurationExpression <TSource, TDestination, TMember> member, Func <TSource, TResult> resolver) => member.MapFrom((Func <TSource, TDestination, TResult>)((src, dest) => resolver(src)));
Beispiel #22
0
 public static void MapFromField <TSource, TDestination, TMember>(this IMemberConfigurationExpression <TSource, TDestination, TMember> config, string fieldId) where TSource : FieldFrameworkModel
 {
     config.MapFrom(model => model.GetValue <TMember>(fieldId));
 }