コード例 #1
0
        public AddedMapContext CreateMap <DestMember, Source, Dest, TService>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config)
            where TService : class, IYuzuTypeFactory <DestMember>
        {
            var settings = baseSettings as YuzuPropertyFactoryMapperSettings;

            if (settings != null)
            {
                config.AddActiveManualMap <TService, Dest>(settings.DestPropertyName);

                Func <Source, Dest, object, ResolutionContext, DestMember> mappingFunction = (Source m, Dest v, object o, ResolutionContext context) =>
                {
                    var propertyResolver = factory.GetInstance(typeof(TService)) as TService;
                    var yuzuContext      = contextFactory.From <UmbracoMappingContext>(context.Items);
                    return(propertyResolver.Create(yuzuContext));
                };

                var map = mapContext.AddOrGet <Source, Dest>(cfg);

                map.ForMember(settings.DestPropertyName, opt => opt.MapFrom(mappingFunction));

                return(mapContext);
            }
            else
            {
                throw new Exception("Mapping settings not of type YuzuPropertyFactoryMapperSettings");
            }
        }
コード例 #2
0
        public AddedMapContext CreateMap <Source, Dest, TService>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config)
            where TService : class, IYuzuTypeConvertor <Source, Dest>
        {
            var settings = baseSettings as YuzuTypeConvertorMapperSettings;

            if (settings != null)
            {
                config.AddActiveManualMap <TService, Dest>();

                if (settings.IgnoreReturnType)
                {
                    importConfig.IgnoreViewmodels.Add(typeof(Dest).Name);
                }

                var map = mapContext.AddOrGet <Source, Dest>(cfg);

                Func <Source, Dest, ResolutionContext, Dest> mappingFunction = (Source source, Dest dest, ResolutionContext context) =>
                {
                    var typeConvertor = factory.GetInstance(typeof(TService)) as TService;
                    var yuzuContext   = contextFactory.From <UmbracoMappingContext>(context.Items);

                    return(typeConvertor.Convert(source, yuzuContext));
                };
                map.ConvertUsing(mappingFunction);

                return(mapContext);
            }
            else
            {
                throw new Exception("Mapping settings not of type YuzuTypeMappingSettings");
            }
        }
コード例 #3
0
        public AddedMapContext CreateMap <Source, Dest, Resolver>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config)
            where Resolver : class, IYuzuTypeAfterConvertor <Source, Dest>
        {
            var settings = baseSettings as YuzuTypeAfterMapperSettings;

            if (settings != null)
            {
                config.AddActiveManualMap <Resolver, Dest>();

                var map = mapContext.AddOrGet <Source, Dest>(cfg);

                Action <Source, Dest, ResolutionContext> mappingFunction = (Source source, Dest dest, ResolutionContext context) =>
                {
                    var typeConvertor = factory.GetInstance(typeof(Resolver)) as Resolver;
                    var yuzuContext   = contextFactory.From <UmbracoMappingContext>(context.Items);

                    typeConvertor.Apply(source, dest, yuzuContext);
                };
                map.AfterMap(mappingFunction);

                return(mapContext);
            }
            else
            {
                throw new Exception("Mapping settings not of type YuzuTypeMappingSettings");
            }
        }
コード例 #4
0
        public AddedMapContext CreateMap <Source, DestMember, Dest, Resolver>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config)
            where Resolver : class, IYuzuPropertyReplaceResolver <Source, DestMember>
        {
            var settings = baseSettings as YuzuPropertyMapperSettings;

            if (settings != null)
            {
                config.AddActiveManualMap <Resolver, Dest>(settings.DestPropertyName);

                if (settings.IgnoreProperty)
                {
                    importConfig.IgnorePropertiesInViewModels.Add(new KeyValuePair <string, string>(typeof(Dest).Name, settings.DestPropertyName));
                }

                if (settings.IgnoreReturnType)
                {
                    if (typeof(DestMember).IsGenericType)
                    {
                        importConfig.IgnoreViewmodels.Add(typeof(DestMember).GetGenericArguments().Select(x => x.Name).FirstOrDefault());
                    }
                    else
                    {
                        importConfig.IgnoreViewmodels.Add(typeof(DestMember).Name);
                    }
                }


                if (!string.IsNullOrEmpty(settings.GroupName))
                {
                    cfg.RecognizePrefixes(settings.GroupName);
                }

                Func <Source, Dest, object, ResolutionContext, DestMember> mappingFunction = (Source m, Dest v, object o, ResolutionContext context) =>
                {
                    var propertyResolver = factory.GetInstance(typeof(Resolver)) as Resolver;
                    var yuzuContext      = contextFactory.From <UmbracoMappingContext>(context.Items);
                    return(propertyResolver.Resolve(m, yuzuContext));
                };

                var map = mapContext.AddOrGet <Source, Dest>(cfg);

                map.ForMember(settings.DestPropertyName, opt => opt.MapFrom(mappingFunction));

                return(mapContext);
            }
            else
            {
                throw new Exception("Mapping settings not of type YuzuPropertyMappingSettings");
            }
        }
コード例 #5
0
        public E Run <E>(IDictionary <string, object> items = null)
        {
            if (config.ViewmodelFactories.ContainsKey(typeof(E)))
            {
                var typeFactory = config.ViewmodelFactories[typeof(E)]() as IYuzuTypeFactory <E>;

                if (typeFactory != null)
                {
                    if (items == null)
                    {
                        items = new Dictionary <string, object>();
                    }
                    return(typeFactory.Create(contextFactory.From <UmbracoMappingContext>(items)));
                }
            }

            return(default(E));
        }