Example #1
0
        /// <inheritdoc />
        public Skin Convert(SkinDTO value, object state)
        {
            var entity = new UnknownSkin();

            this.Merge(entity, value, state);
            return(entity);
        }
        /// <summary>Converts the given object of type <see cref="SkinDataContract"/> to an object of type <see cref="Skin"/>.</summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="state"></param>
        /// <returns>The converted value.</returns>
        public Skin Convert(SkinDataContract value, object state)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "Precondition: value != null");
            }

            Skin skin;
            IConverter <SkinDataContract, Skin> converter;

            if (this.typeConverters.TryGetValue(value.Type, out converter))
            {
                skin = converter.Convert(value, state);
            }
            else
            {
                skin = new UnknownSkin();
            }

            skin.Name = value.Name;

            var flags = value.Flags;

            if (flags != null)
            {
                skin.Flags = this.converterForSkinFlags.Convert(flags, state);
            }

            var restrictions = value.Restrictions;

            if (restrictions != null)
            {
                skin.Restrictions = this.converterForItemRestrictions.Convert(restrictions, state);
            }

            int iconFileId;

            if (int.TryParse(value.IconFileId, out iconFileId))
            {
                skin.IconFileId = iconFileId;
            }

            // Set the icon file signature
            skin.IconFileSignature = value.IconFileSignature;

            // Set the icon file URL
            const string IconUrlTemplate = @"https://render.guildwars2.com/file/{0}/{1}.{2}";
            var          iconUrl         = string.Format(IconUrlTemplate, value.IconFileSignature, value.IconFileId, "png");

            skin.IconFileUrl = new Uri(iconUrl, UriKind.Absolute);

            return(skin);
        }
Example #3
0
 // Implement this method in a buddy class to set properties that are specific to 'UnknownSkin' (if any)
 partial void Merge(UnknownSkin entity, SkinDTO dto, object state);