コード例 #1
0
        /// <summary>
        /// Maps a basic property value.
        /// </summary>
        /// <param name="mapping">
        /// The mapping for the property value.  Cannot be null.
        /// </param>
        /// <param name="sourcePropertyType">
        /// The type of the first parameter being supplied to <paramref name="mapping"/>.
        /// Cannot be <c>null</c>.
        /// </param>
        /// <param name="sourcePropertyAlias">
        /// The alias of the node property to map from.  Required.
        /// </param>
        /// <param name="nodeMapper"></param>
        /// <param name="destinationProperty"></param>
        public BasicPropertyMapper(
            Func <object, object> mapping,
            Type sourcePropertyType,
            NodeMapper nodeMapper,
            PropertyInfo destinationProperty,
            string sourcePropertyAlias
            )
            : base(nodeMapper, destinationProperty)
        {
            if (sourcePropertyType == null && mapping != null)
            {
                throw new ArgumentNullException("sourcePropertyType", "Source property type must be specified when using a mapping");
            }

            if (sourcePropertyAlias == null)
            {
                sourcePropertyAlias = NodeMapper.GetPropertyAlias(destinationProperty);

                if (sourcePropertyAlias == null)
                {
                    throw new PropertyAliasNotFoundException(sourcePropertyType, destinationProperty, sourcePropertyAlias);
                }
            }

            SourcePropertyAlias = sourcePropertyAlias;
            RequiresInclude     = false;
            AllowCaching        = true;
            _mapping            = mapping;
            _sourcePropertyType = sourcePropertyType;
        }