Exemple #1
0
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var scConfig = args.PropertyConfiguration as SitecoreInfoConfiguration;

            this.ReadOnly = scConfig.Type != SitecoreInfoType.DisplayName && scConfig.Type != SitecoreInfoType.Name;
            base.Setup(args);
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        /// <exception cref="Glass.Mapper.MapperException">No mapper to handle type {0} on property {1} class {2}.Formatted(type.FullName, property.Name,
        ///                                                                                        property.ReflectedType.FullName)</exception>
        public override void Setup(DataMapperResolverArgs args)
        {
            base.Setup(args);

            var config = Configuration as UmbracoPropertyConfiguration;

            var property = args.PropertyConfiguration.PropertyInfo;
            var type     = Utilities.GetGenericArgument(property.PropertyType);

            var configCopy = config.Copy();

            configCopy.PropertyInfo = new FakePropertyInfo(type, property.Name, property.DeclaringType);

            Mapper =
                args.DataMappers.FirstOrDefault(
                    x => x.CanHandle(configCopy, args.Context) && x is AbstractUmbracoPropertyMapper)
                as AbstractUmbracoPropertyMapper;

            if (Mapper == null)
            {
                throw new MapperException(
                          "No mapper to handle type {0} on property {1} class {2}".Formatted(type.FullName, property.Name,
                                                                                             property.ReflectedType.FullName));
            }

            Mapper.Setup(new DataMapperResolverArgs(args.Context, configCopy));
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args"></param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var config = args.PropertyConfiguration as UmbracoInfoConfiguration;

            this.ReadOnly = config.Type != UmbracoInfoType.Name;
            base.Setup(args);
        }
        public void SetField_ListContainsNoValues_SetsEmptyField()
        {
            //Assign
            var expected = string.Empty;
            var item     = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIEnumerableMapper/SetField");
            var field    = item.Fields[FieldName];
            var value    = new List <double>();

            var config = new SitecoreFieldConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("IList");

            var mapper    = new SitecoreFieldIEnumerableMapper();
            var subMapper = new SitecoreFieldDoubleMapper();

            var args = new DataMapperResolverArgs(null, config);

            args.DataMappers = new[] { subMapper };

            mapper.Setup(args);

            using (new ItemEditing(item, true))
            {
                field.Value = string.Empty;
            }

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, value, config, null);
            }
            //Assert
            Assert.AreEqual(expected, field.Value);
        }
        public override void Setup(DataMapperResolverArgs args)
        {
            if (args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(Guid))
            {
                _getValue = (item) => item.ID.Guid;
            }
            else if (args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(ID) || args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(object))
            {
                _getValue = (item) => item.ID;
            }
            else if (typeof(Sitecore.ContentSearch.IIndexableId).IsAssignableFrom(args.PropertyConfiguration.PropertyInfo.PropertyType) ||
                     args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(string))
            {
                _getValue = (item) => item.ID.ToShortID();
            }
            else
            {
                throw new NotSupportedException("The type {0} on {1}.{2} is not supported by SitecoreIdMapper".Formatted
                                                    (args.PropertyConfiguration.PropertyInfo.PropertyType.FullName,
                                                    args.PropertyConfiguration.PropertyInfo.ReflectedType.FullName,
                                                    args.PropertyConfiguration.PropertyInfo.Name));
            }

            base.Setup(args);
        }
        public void GetField_EmptyField_ReturnsEmptyList()
        {
            //Assign
            var fieldValue = "";
            var item       = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIEnumerableMapper/GetField");
            var field      = item.Fields[FieldName];

            var config = new SitecoreFieldConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("IList");

            var mapper    = new SitecoreFieldIEnumerableMapper();
            var subMapper = new SitecoreFieldDoubleMapper();

            var args = new DataMapperResolverArgs(null, config);

            args.DataMappers = new[] { subMapper };

            mapper.Setup(args);

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act

            var result = mapper.GetField(field, config, null) as List <double>;

            //Assert
            Assert.AreEqual(0, result.Count);
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var scConfig = args.PropertyConfiguration as SitecoreFieldConfiguration;

            IsLazy    = (scConfig.Setting & SitecoreFieldSettings.DontLoadLazily) != SitecoreFieldSettings.DontLoadLazily;
            InferType = (scConfig.Setting & SitecoreFieldSettings.InferType) == SitecoreFieldSettings.InferType;
            base.Setup(args);
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args"></param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var config = args.PropertyConfiguration as UmbracoPropertyConfiguration;

            IsLazy    = (config.Setting & UmbracoPropertySettings.DontLoadLazily) != UmbracoPropertySettings.DontLoadLazily;
            InferType = (config.Setting & UmbracoPropertySettings.InferType) == UmbracoPropertySettings.InferType;
            base.Setup(args);
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var scConfig = args.PropertyConfiguration as SitecoreInfoConfiguration;

            if (scConfig == null)
            {
                throw new NullReferenceException("Configuration has not been set.");
            }

            ReadOnly = scConfig.Type != SitecoreInfoType.DisplayName && scConfig.Type != SitecoreInfoType.Name;
            base.Setup(args);
        }
        public void Execute(DataMapperResolverArgs args)
        {
            if (args.Result != null)
            {
                var fieldMapper = args.Result as AbstractSitecoreFieldMapper;

                if (fieldMapper != null)
                {
                    var scConfig = args.Result.Configuration as SitecoreFieldConfiguration;
                    scConfig.FieldName = GetFieldName(scConfig.FieldName);
                }
            }
        }
 /// <summary>
 /// Executes the specified args.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <exception cref="Glass.Mapper.MapperException">Could not find data mapper to handler property {0}.Formatted(args.PropertyConfiguration)</exception>
 public void Execute(DataMapperResolverArgs args)
 {
     if (args.Result == null)
     {
         var mapper = args.DataMappers.FirstOrDefault(x => x.CanHandle(args.PropertyConfiguration, args.Context));
         
         if(mapper == null) 
             throw new MapperException("Could not find a data mapper to handle property {0}".Formatted(args.PropertyConfiguration));
         
         mapper.Setup(args);
         args.Result = mapper;
     }
 }
        public override void Execute(DataMapperResolverArgs args)
        {

            if (args.Result == null)
            {
                AbstractDataMapper mapper;

                var propertyInfo = args.PropertyConfiguration.PropertyInfo;

                var attribute  = propertyInfo.GetCustomAttribute<DataMapperAttribute>();

                if (attribute == null || attribute.DataMapperType == null)
                {
                    Next(args);
                    return;
                }

                var mapperType = attribute.DataMapperType;
                var isAbstractDataMapper = typeof(AbstractDataMapper).IsAssignableFrom(attribute.DataMapperType);
                if (!isAbstractDataMapper)
                {
                    throw new MapperException(
                        "Specified data mapper {0} does not inherit from AbstractDataMapper. {1}".Formatted(mapperType.FullName, args.PropertyConfiguration));
                }

                // Look through registered mappers first
                mapper = args.DataMappers.FirstOrDefault(x => x.GetType() == mapperType);

                if (mapper == null)
                {
                    // Create new instance using the default constructor
                    var constructor = mapperType.GetConstructor(Type.EmptyTypes);
                    if (constructor == null)
                    {
                        throw new NotSupportedException(
                            ErrorNoConstructor.Formatted(mapperType.FullName, args.PropertyConfiguration));
                    }

                    mapper = (AbstractDataMapper)Activator.CreateInstance(mapperType);
                }

                if (!mapper.CanHandle(args.PropertyConfiguration, args.Context))
                {
                    throw new MapperException(
                        "Specified data mapper {0} cannot handle this property. {1}".Formatted(mapperType.FullName, args.PropertyConfiguration));
                }

                args.Result= mapper;
                return;
            }
        }
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        /// <exception cref="Glass.Mapper.MapperException">No mapper to handle type {0} on property {1} class {2}.Formatted(type.FullName, property.Name,
        ///                                                                                        property.ReflectedType.FullName)</exception>
        public override void Setup(DataMapperResolverArgs args)
        {
            base.Setup(args);

            var fieldConfiguration = this.Configuration as SitecoreFieldConfiguration;

            PropertyInfo propertyInfo = args.PropertyConfiguration.PropertyInfo;

            Type[] genericArguments = propertyInfo.PropertyType.GetGenericArguments();

            this.KeyMapper = this.GetMapper(genericArguments[0], fieldConfiguration, propertyInfo, args);

            this.ValueMapper = this.GetMapper(genericArguments[1], fieldConfiguration, propertyInfo, args);
        }
        public override void Execute(DataMapperResolverArgs args)
        {
            if (args.Result == null)
            {
                AbstractDataMapper mapper;

                var propertyInfo = args.PropertyConfiguration.PropertyInfo;

                var attribute = propertyInfo.GetCustomAttribute <DataMapperAttribute>();

                if (attribute == null || attribute.DataMapperType == null)
                {
                    Next(args);
                    return;
                }

                var mapperType           = attribute.DataMapperType;
                var isAbstractDataMapper = typeof(AbstractDataMapper).IsAssignableFrom(attribute.DataMapperType);
                if (!isAbstractDataMapper)
                {
                    throw new MapperException(
                              "Specified data mapper {0} does not inherit from AbstractDataMapper. {1}".Formatted(mapperType.FullName, args.PropertyConfiguration));
                }

                // Look through registered mappers first
                mapper = args.DataMappers.FirstOrDefault(x => x.GetType() == mapperType);

                if (mapper == null)
                {
                    // Create new instance using the default constructor
                    var constructor = mapperType.GetConstructor(Type.EmptyTypes);
                    if (constructor == null)
                    {
                        throw new NotSupportedException(
                                  ErrorNoConstructor.Formatted(mapperType.FullName, args.PropertyConfiguration));
                    }

                    mapper = (AbstractDataMapper)Activator.CreateInstance(mapperType);
                }

                if (!mapper.CanHandle(args.PropertyConfiguration, args.Context))
                {
                    throw new MapperException(
                              "Specified data mapper {0} cannot handle this property. {1}".Formatted(mapperType.FullName, args.PropertyConfiguration));
                }

                args.Result = mapper;
                return;
            }
        }
Exemple #15
0
        /// <summary>
        /// Executes the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <exception cref="Glass.Mapper.MapperException">Could not find data mapper to handler property {0}.Formatted(args.PropertyConfiguration)</exception>
        public void Execute(DataMapperResolverArgs args)
        {
            if (args.Result == null)
            {
                var mapper = args.DataMappers.FirstOrDefault(x => x.CanHandle(args.PropertyConfiguration, args.Context));

                if (mapper == null)
                {
                    throw new MapperException("Could not find a data mapper to handle property {0}".Formatted(args.PropertyConfiguration));
                }

                mapper.Setup(args);
                args.Result = mapper;
            }
        }
Exemple #16
0
        public void Execute_NoDataMapperAttribute_NoMatchingMapper_ThrowsMapperException()
        {
            //Assign
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("NoAttributeProperty");

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = Enumerable.Empty <AbstractDataMapper>();

            //Act
            Assert.Throws <MapperException>(() => _task.Execute(args));

            //Assert
        }
Exemple #17
0
        public void SetField_ListContainsNoValues_SetsEmptyField()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { "Field", "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var expected = string.Empty;
                var item     =
                    database.GetItem("/sitecore/content/Target");
                var field = item.Fields["Field"];
                var value = new List <double>();

                var config = new SitecoreFieldConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("IList");

                var mapper    = new SitecoreFieldIEnumerableMapper();
                var subMapper = new SitecoreFieldDoubleMapper();

                var args = new DataMapperResolverArgs(null, config);
                args.DataMappers = new[] { subMapper };

                mapper.Setup(args);

                using (new ItemEditing(item, true))
                {
                    field.Value = string.Empty;
                }

                //Act
                using (new ItemEditing(item, true))
                {
                    mapper.SetField(field, value, config, null);
                }
                //Assert
                Assert.AreEqual(expected, field.Value);
            }
        }
Exemple #18
0
        public void GetField_ContainsPipeSeparatedValues_ReturnsListOfValues()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { "Field", "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var fieldValue = "1|2|3";
                var item       =
                    database.GetItem("/sitecore/content/Target");
                var field = item.Fields["Field"];

                var config = new SitecoreFieldConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("IList");

                var mapper    = new SitecoreFieldIEnumerableMapper();
                var subMapper = new SitecoreFieldDoubleMapper();

                var args = new DataMapperResolverArgs(null, config);
                args.DataMappers = new[] { subMapper };

                mapper.Setup(args);

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

                //Act

                var result = mapper.GetField(field, config, null) as List <double>;

                //Assert
                Assert.AreEqual(1D, result.Skip(0).First());
                Assert.AreEqual(2D, result.Skip(1).First());
                Assert.AreEqual(3D, result.Skip(2).First());
            }
        }
Exemple #19
0
        /// <summary>
        /// Processes the properties.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <exception cref="System.NullReferenceException">Could not find data mapper for property {0} on type {1}
        ///                         .Formatted(property.PropertyInfo.Name,property.PropertyInfo.ReflectedType.FullName)</exception>
        private void ProcessProperties(IEnumerable <AbstractPropertyConfiguration> properties)
        {
            DataMapperResolver runner = new DataMapperResolver(DependencyResolver.ResolveAll <IDataMapperResolverTask>());

            foreach (var property in properties)
            {
                DataMapperResolverArgs args = new DataMapperResolverArgs(this, property);
                args.PropertyConfiguration = property;
                args.DataMappers           = DependencyResolver.ResolveAll <AbstractDataMapper>();
                runner.Run(args);
                if (args.Result == null)
                {
                    throw new NullReferenceException(
                              "Could not find data mapper for property {0} on type {1}"
                              .Formatted(property.PropertyInfo.Name, property.PropertyInfo.ReflectedType.FullName));
                }
                property.Mapper = args.Result;
            }
        }
        public override void Setup(DataMapperResolverArgs args)
        {
            if (args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(Guid))
            {
                _getValue = (item) => item.ID.Guid;
            }
            else if (args.PropertyConfiguration.PropertyInfo.PropertyType == typeof(ID))
            {
                _getValue = (item) => item.ID;
            }
            else
            {
                throw new NotSupportedException("The type {0} on {0}.{1} is not supported by SitecoreIdMapper".Formatted
                                                    (args.PropertyConfiguration.PropertyInfo.ReflectedType.FullName,
                                                    args.PropertyConfiguration.PropertyInfo.Name));
            }

            base.Setup(args);
        }
        public void Setup_SubMapperIsAssigned()
        {
            //Assign
            var config = new SitecoreFieldConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("IList");

            var mapper    = new SitecoreFieldIEnumerableMapper();
            var subMapper = new SitecoreFieldDoubleMapper();

            var args = new DataMapperResolverArgs(null, config);

            args.DataMappers = new[] { subMapper };

            //Act
            mapper.Setup(args);

            //Assert
            Assert.AreEqual(subMapper, mapper.Mapper);
        }
        public void Execute_DataMapperAttribute_SetsResultToSpecifiedMapper()
        {
            //Assign

            var task          = new DataMapperAttributeResolverTask();
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = Enumerable.Empty <AbstractDataMapper>();

            //Act
            task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.IsTrue(args.Result.GetType() == typeof(StubMapper));
        }
        public void Execute_DataMapperAttributeMapperMissingConstructor_SetsResultToSpecifiedMapper()
        {
            //Assign

            var task          = new DataMapperAttributeResolverTask();
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("MissingConstructorStubMapperProperty");

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = Enumerable.Empty <AbstractDataMapper>();

            //Act
            Assert.Throws <NotSupportedException>(() =>
            {
                task.Execute(args);
            });

            //Assert
        }
Exemple #24
0
        public void Execute_DataMapperAttribute_SetsResultToMatchingRegisteredMapper()
        {
            //Assign
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var mapper = new StubMapper();
            var args   = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = new List <AbstractDataMapper> {
                mapper
            };

            //Act
            _task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
        public void Execute_DataMapperAttributeLoadedFromMapperCollection_SetsResultToSpecifiedMapper()
        {
            //Assign

            var task          = new DataMapperAttributeResolverTask();
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var mapper = new StubMapper();

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = new AbstractDataMapper[] { mapper };

            //Act
            task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
Exemple #26
0
        public void Setup_SubMapperMissing_ExceptionThrown()
        {
            //Assign
            var config = new SitecoreFieldConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("IEnumerable");

            var mapper    = new SitecoreFieldIEnumerableMapper();
            var subMapper = new SitecoreFieldDoubleMapper();

            var args = new DataMapperResolverArgs(null, config);

            args.DataMappers = new[] { subMapper };

            //Act
            Assert.Throws <MapperException>(() =>
            {
                mapper.Setup(args);
            });

            //Assert
        }
Exemple #27
0
        public void Execute_InvokesMapperSetup()
        {
            //Assign
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("NoAttributeProperty");

            var mapper = Substitute.For <AbstractDataMapper>();

            mapper.CanHandle(configuration, null).Returns(true);

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = new List <AbstractDataMapper> {
                mapper
            };

            //Act
            _task.Execute(args);

            //Assert
            mapper.Received().Setup(args);
        }
Exemple #28
0
 public override void Setup(DataMapperResolverArgs args)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Sets up the data mapper for a particular property
 /// </summary>
 /// <param name="args">The args.</param>
 public override void Setup(DataMapperResolverArgs args)
 {
     _baseMapper.Setup(args);
     base.Setup(args);
 }
Exemple #30
0
        /// <summary>
        /// Sets up the data mapper for a particular property
        /// </summary>
        /// <param name="args">The args.</param>
        public override void Setup(DataMapperResolverArgs args)
        {
            var scConfig = args.PropertyConfiguration as SitecoreInfoConfiguration;

            if (scConfig == null)
            {
                throw new NullReferenceException("Configuration has not been set.");
            }

            ReadOnly = scConfig.Type != SitecoreInfoType.DisplayName && scConfig.Type != SitecoreInfoType.Name;


            switch (scConfig.Type)
            {
            case SitecoreInfoType.ContentPath:
                _getValue = item => item.Paths.ContentPath;
                break;

            case SitecoreInfoType.DisplayName:
                _getValue = item => item[Global.Fields.DisplayName];
                break;

            case SitecoreInfoType.FullPath:
                _getValue = item => item.Paths.FullPath;
                break;

            case SitecoreInfoType.Name:
                _getValue = item => item.Name;
                break;

            case SitecoreInfoType.Key:
                _getValue = item => item.Key;
                break;

            case SitecoreInfoType.MediaUrl:
                _getValue = item =>
                {
                    var mediaUrlOptions = _mediaUrlOptionsResolver.GetMediaUrlOptions(scConfig.MediaUrlOptions);
                    var media           = new MediaItem(item);
                    return(MediaManager.GetMediaUrl(media, mediaUrlOptions));
                };
                break;

            case SitecoreInfoType.Path:
                _getValue = item => item.Paths.Path;
                break;

            case SitecoreInfoType.TemplateId:
                _getValue = item =>
                {
                    if (scConfig.PropertyInfo != null && scConfig.PropertyInfo.PropertyType == typeof(ID))
                    {
                        return(item.TemplateID);
                    }
                    return(item.TemplateID.Guid);
                };
                break;

            case SitecoreInfoType.TemplateName:
                _getValue = item => item.TemplateName;
                break;

            case SitecoreInfoType.Url:
                _getValue = item =>
                {
                    var urlOptions = _urlOptionsResolver.CreateUrlOptions(scConfig.UrlOptions);
                    if (UrlOptionsResolver.FlagCheck(scConfig.UrlOptions, SitecoreInfoUrlOptions.UseItemLanguage))
                    {
                        urlOptions.Language = item.Language;
                    }
                    else
                    {
                        urlOptions.Language = null;
                    }
                    return(LinkManager.GetItemUrl(item, urlOptions));
                };
                break;

            case SitecoreInfoType.Version:
                _getValue = item =>
                {
                    if (scConfig.PropertyInfo != null && scConfig.PropertyInfo.PropertyType == typeof(string))
                    {
                        return(item.Version.Number.ToString());
                    }
                    return(item.Version.Number);
                };
                break;

            case SitecoreInfoType.Language:
                _getValue = item =>
                {
                    if (scConfig.PropertyInfo != null && scConfig.PropertyInfo.PropertyType == typeof(string))
                    {
                        return(item.Language.Name);
                    }
                    return(item.Language);
                };
                break;

            case SitecoreInfoType.BaseTemplateIds:
                _getValue = item =>
                {
                    Template template = TemplateManager.GetTemplate(item.TemplateID, item.Database);
                    if (scConfig.PropertyInfo != null &&
                        scConfig.PropertyInfo.PropertyType == typeof(IEnumerable <ID>))
                    {
                        return(template.GetBaseTemplates().Select(x => x.ID));
                    }
                    return(template.GetBaseTemplates().Select(x => x.ID.Guid));
                };
                break;

            case SitecoreInfoType.ItemUri:
                _getValue = item => new ItemUri(item.ID, item.Language, item.Version, item.Database);
                break;

#if (SC81 || SC82 || SC90)
            case SitecoreInfoType.OriginalLanguage:
                _getValue = item => item.OriginalLanguage;
                break;

            case SitecoreInfoType.OriginatorId:
                _getValue = item => item.OriginatorId;
                break;
#endif
            default:
                throw new MapperException("SitecoreInfoType {0} not supported".Formatted(scConfig.Type));
            }


            base.Setup(args);
        }
 /// <summary>
 /// Sets up the data mapper for a particular property
 /// </summary>
 /// <param name="args">The args.</param>
 public virtual void Setup(DataMapperResolverArgs args)
 {
     Configuration = args.PropertyConfiguration;
 }
        private AbstractSitecoreFieldMapper GetMapper(Type genericArgument, SitecoreFieldConfiguration fieldConfiguration, PropertyInfo propertyInfo, DataMapperResolverArgs args)
        {
            AbstractPropertyConfiguration configCopy = fieldConfiguration.Copy();

            configCopy.PropertyInfo = new FakePropertyInfo(genericArgument, propertyInfo.Name, propertyInfo.DeclaringType);

            var mapper = args.DataMappers.FirstOrDefault(
                x => x.CanHandle(configCopy, args.Context) && x is AbstractSitecoreFieldMapper)
                         as AbstractSitecoreFieldMapper;

            if (mapper == null)
            {
                throw new MapperException(Glass.Mapper.ExtensionMethods.Formatted(
                                              "No mapper to handle type {0} on property {1} class {2}",
                                              (object)genericArgument.FullName,
                                              (object)propertyInfo.Name,
                                              (object)propertyInfo.ReflectedType.FullName));
            }
            else
            {
                mapper.Setup(new DataMapperResolverArgs(args.Context, configCopy));
            }

            return(mapper);
        }