예제 #1
0
        /// <summary>
        /// Map by a <see cref="ColumnAttribute"/> object.
        /// </summary>
        /// <param name="attribute">The <see cref="ColumnAttribute"/> object.</param>
        /// <returns>The mapper object.</returns>
        public Mapper Map(ColumnAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            if (attribute.Property != null)
            {
                attribute.MergeTo(Attributes);
            }
            else if (attribute.PropertyName != null)
            {
                if (DynamicAttributes.ContainsKey(attribute.PropertyName))
                {
                    DynamicAttributes[attribute.PropertyName].MergeFrom(attribute);
                }
                else
                {
                    // Ensures column name for the first time mapping.
                    if (attribute.Name == null)
                    {
                        attribute.Name = attribute.PropertyName;
                    }

                    DynamicAttributes[attribute.PropertyName] = attribute;
                }
            }
            else
            {
                throw new InvalidOperationException("Either PropertyName or Property should be specified for a valid mapping!");
            }

            return(this);
        }
예제 #2
0
        /// <summary>
        /// Additional operations to be performed when cloning an instance of <see cref="Sku"/> to an instance of <see cref="PSSku" />.
        /// </summary>
        /// <param name="sku">The SKU being cloned.</param>
        private void CloneAdditionalOperations(Sku sku)
        {
            if (sku.DynamicAttributes != null)
            {
                foreach (KeyValuePair <string, object> item in sku.DynamicAttributes)
                {
                    DynamicAttributes.Add(item.Key, item.Value);
                }
            }

            SkuId = sku.Id;
        }