Beispiel #1
0
        public void OnPropertyChanged(string propertyName, object before, object after)
        {
            if (propertyName == nameof(SelectedIdol))
            {
                SendToSlotCommand.RaiseCanExecuteChanged();
                CopyIidCommand.RaiseCanExecuteChanged();
            }
            else if (propertyName == nameof(UnitName))
            {
                SaveCommand.RaiseCanExecuteChanged();
            }
            else if (propertyName == nameof(SelectedUnit))
            {
                if (SelectedUnit != null)
                {
                    TemporalUnit.CopyFrom(SelectedUnit);
                }
                DeleteCommand.RaiseCanExecuteChanged();
            }

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
Beispiel #2
0
        //-----------------------------------------------------------------------
        public ChronoLocalDateTimeImpl <D> Plus(long amountToAdd, TemporalUnit unit)
        {
            if (unit is ChronoUnit)
            {
                ChronoUnit f = (ChronoUnit)unit;
                switch (f)
                {
                case NANOS:
                    return(PlusNanos(amountToAdd));

                case MICROS:
                    return(PlusDays(amountToAdd / MICROS_PER_DAY).PlusNanos((amountToAdd % MICROS_PER_DAY) * 1000));

                case MILLIS:
                    return(PlusDays(amountToAdd / MILLIS_PER_DAY).PlusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000));

                case SECONDS:
                    return(PlusSeconds(amountToAdd));

                case MINUTES:
                    return(PlusMinutes(amountToAdd));

                case HOURS:
                    return(PlusHours(amountToAdd));

                case HALF_DAYS:                         // no overflow (256 is multiple of 2)
                    return(PlusDays(amountToAdd / 256).PlusHours((amountToAdd % 256) * 12));
                }
                return(With(Date.Plus(amountToAdd, unit), Time));
            }
            return(ChronoLocalDateTimeImpl.EnsureValid(Date.Chronology, unit.AddTo(this, amountToAdd)));
        }
Beispiel #3
0
        public static LocalDateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "local date time");

            LocalDate truncatedDate = pair.First();
            LocalTime truncatedTime = pair.Other();

            DateTime truncatedLDT = new DateTime(truncatedDate, truncatedTime);

            if (fields.Size() == 0)
            {
                return(LocalDateTime(truncatedLDT));
            }
            else
            {
                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedLDT, (mapValue, localDateTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return LocalDateTime(LocalDateTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("datetime", LocalDateTime(LocalDateTime)), defaultZone);
                    }
                }));
            }
        }
Beispiel #4
0
        public static TimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            OffsetTime time        = input.getTimePart(defaultZone);
            OffsetTime truncatedOT = AssertValidUnit(() => time.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(time(truncatedOT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    ZonedDateTime currentDT     = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), TimezoneOf(timezone)));
                    ZoneOffset    currentOffset = currentDT.Offset;
                    truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return time(offsetTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
                    }
                }));
            }
        }
Beispiel #5
0
        public static DurationValue Between(TemporalUnit unit, Temporal from, Temporal to)
        {
            if (unit == null)
            {
                return(DurationBetween(from, to));
            }
            else if (unit is ChronoUnit)
            {
                switch (( ChronoUnit )unit)
                {
                case MONTHS:
                    return(NewDuration(AssertValidUntil(from, to, unit), 0, 0, 0));

                case DAYS:
                    return(NewDuration(0, AssertValidUntil(from, to, unit), 0, 0));

                case SECONDS:
                    return(DurationInSecondsAndNanos(from, to));

                default:
                    throw new UnsupportedTemporalUnitException("Unsupported unit: " + unit);
                }
            }
            else
            {
                throw new UnsupportedTemporalUnitException("Unsupported unit: " + unit);
            }
        }
Beispiel #6
0
            internal Between(string unit)
            {
                string unitString;

                switch (unit)
                {
                case "between":
                    this.Unit  = null;
                    unitString = "logical units";
                    break;

                case "inMonths":
                    this.Unit  = ChronoUnit.MONTHS;
                    unitString = "months";
                    break;

                case "inDays":
                    this.Unit  = ChronoUnit.DAYS;
                    unitString = "days";
                    break;

                case "inSeconds":
                    this.Unit  = ChronoUnit.SECONDS;
                    unitString = "seconds";
                    break;

                default:
                    throw new System.InvalidOperationException("Unsupported unit: " + unit);
                }
                this.Signature = new UserFunctionSignature(new QualifiedName(new string[] { "duration" }, unit), SignatureConflict, Neo4jTypes.NTDuration, null, new string[0], string.format(DESCRIPTION, unitString), true);
            }
Beispiel #7
0
        //-----------------------------------------------------------------------
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @SuppressWarnings("unchecked") public D plus(long amountToAdd, java.time.temporal.TemporalUnit unit)
        public virtual D Plus(long amountToAdd, TemporalUnit unit)
        {
            if (unit is ChronoUnit)
            {
                ChronoUnit f = (ChronoUnit)unit;
                switch (f)
                {
                case DAYS:
                    return(PlusDays(amountToAdd));

                case WEEKS:
                    return(PlusDays(Math.MultiplyExact(amountToAdd, 7)));

                case MONTHS:
                    return(PlusMonths(amountToAdd));

                case YEARS:
                    return(PlusYears(amountToAdd));

                case DECADES:
                    return(PlusYears(Math.MultiplyExact(amountToAdd, 10)));

                case CENTURIES:
                    return(PlusYears(Math.MultiplyExact(amountToAdd, 100)));

                case MILLENNIA:
                    return(PlusYears(Math.MultiplyExact(amountToAdd, 1000)));

                case ERAS:
                    return(With(ERA, Math.AddExact(GetLong(ERA), amountToAdd)));
                }
                throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
            }
            return((D)ChronoLocalDate.this.plus(amountToAdd, unit));
        }
Beispiel #8
0
 public void RemoveIdolFromUnits(OwnedIdol idol)
 {
     TemporalUnit.RemoveIdol(idol);
     foreach (var x in Units)
     {
         x.RemoveIdol(idol);
     }
 }
		//-----------------------------------------------------------------------
		public override ChronoZonedDateTime<D> Plus(long amountToAdd, TemporalUnit unit)
		{
			if (unit is ChronoUnit)
			{
				return with(DateTime.Plus(amountToAdd, unit));
			}
			return ChronoZonedDateTimeImpl.EnsureValid(Chronology, unit.AddTo(this, amountToAdd)); /// TODO: Generics replacement Risk!
		}
Beispiel #10
0
 private void CopyIidFromSlot(string slot)
 {
     try
     {
         Clipboard.SetText(((IIdol)TemporalUnit.GetType().GetProperty(slot).GetValue(TemporalUnit)).Iid.ToString("x8"));
     }
     catch
     {
     }
 }
Beispiel #11
0
        public DurationValue Plus(long amount, TemporalUnit unit)
        {
            if (unit is ChronoUnit)
            {
                switch (( ChronoUnit )unit)
                {
                case NANOS:
                    return(Duration(_months, _days, _seconds, _nanos + amount));

                case MICROS:
                    return(Duration(_months, _days, _seconds, _nanos + amount * 1000));

                case MILLIS:
                    return(Duration(_months, _days, _seconds, _nanos + amount * 1000_000));

                case SECONDS:
                    return(Duration(_months, _days, _seconds + amount, _nanos));

                case MINUTES:
                    return(Duration(_months, _days, _seconds + amount * 60, _nanos));

                case HOURS:
                    return(Duration(_months, _days, _seconds + amount * 3600, _nanos));

                case HALF_DAYS:
                    return(Duration(_months, _days, _seconds + amount * 12 * 3600, _nanos));

                case DAYS:
                    return(Duration(_months, _days + amount, _seconds, _nanos));

                case WEEKS:
                    return(Duration(_months, _days + amount * 7, _seconds, _nanos));

                case MONTHS:
                    return(Duration(_months + amount, _days, _seconds, _nanos));

                case YEARS:
                    return(Duration(_months + amount * 12, _days, _seconds, _nanos));

                case DECADES:
                    return(Duration(_months + amount * 120, _days, _seconds, _nanos));

                case CENTURIES:
                    return(Duration(_months + amount * 1200, _days, _seconds, _nanos));

                case MILLENNIA:
                    return(Duration(_months + amount * 12000, _days, _seconds, _nanos));

                default:
                    break;
                }
            }
            throw new System.NotSupportedException("Unsupported unit: " + unit);
        }
Beispiel #12
0
 private static Temporal AssertValidPlus(Temporal temporal, long amountToAdd, TemporalUnit unit)
 {
     try
     {
         return(temporal.plus(amountToAdd, unit));
     }
     catch (Exception e) when(e is DateTimeException || e is ArithmeticException)
     {
         throw new TemporalArithmeticException(e.Message, e);
     }
 }
Beispiel #13
0
 private void SendToSlot(string slot)
 {
     if (TemporalUnit.AlreadyInUnit(SelectedIdol))
     {
         MessageBox.Show("選択したアイドルはすでにこのユニットに編成されています");
     }
     else
     {
         TemporalUnit.GetType().GetProperty(slot).SetValue(TemporalUnit, SelectedIdol);
     }
 }
Beispiel #14
0
        //-----------------------------------------------------------------------
        public long Until(Temporal endExclusive, TemporalUnit unit)
        {
            Objects.RequireNonNull(endExclusive, "endExclusive");
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
            ChronoLocalDateTime <D> end = (ChronoLocalDateTime <D>)Chronology.localDateTime(endExclusive);

            if (unit is ChronoUnit)
            {
                if (unit.TimeBased)
                {
                    long amount = end.getLong(EPOCH_DAY) - Date.GetLong(EPOCH_DAY);
                    switch ((ChronoUnit)unit)
                    {
                    case NANOS:
                        amount = Math.MultiplyExact(amount, NANOS_PER_DAY);
                        break;

                    case MICROS:
                        amount = Math.MultiplyExact(amount, MICROS_PER_DAY);
                        break;

                    case MILLIS:
                        amount = Math.MultiplyExact(amount, MILLIS_PER_DAY);
                        break;

                    case SECONDS:
                        amount = Math.MultiplyExact(amount, SECONDS_PER_DAY);
                        break;

                    case MINUTES:
                        amount = Math.MultiplyExact(amount, MINUTES_PER_DAY);
                        break;

                    case HOURS:
                        amount = Math.MultiplyExact(amount, HOURS_PER_DAY);
                        break;

                    case HALF_DAYS:
                        amount = Math.MultiplyExact(amount, 2);
                        break;
                    }
                    return(Math.AddExact(amount, Time.Until(end.ToLocalTime(), unit)));
                }
                ChronoLocalDate endDate = end.ToLocalDate();
                if (end.ToLocalTime().IsBefore(Time))
                {
                    endDate = endDate.minus(1, ChronoUnit.DAYS);
                }
                return(Date.Until(endDate, unit));
            }
            Objects.RequireNonNull(unit, "unit");
            return(unit.Between(this, end));
        }
Beispiel #15
0
        private void MoveToSlot(string target)
        {
            var s      = target.Split(',');
            var source = s[0];
            var dest   = s[1];

            var srcIdol = TemporalUnit.GetType().GetProperty(source).GetValue(TemporalUnit);
            var dstIdol = TemporalUnit.GetType().GetProperty(dest).GetValue(TemporalUnit);

            TemporalUnit.GetType().GetProperty(source).SetValue(TemporalUnit, dstIdol);
            TemporalUnit.GetType().GetProperty(dest).SetValue(TemporalUnit, srcIdol);
        }
		//-----------------------------------------------------------------------
		public override long Until(Temporal endExclusive, TemporalUnit unit)
		{
			Objects.RequireNonNull(endExclusive, "endExclusive");
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) getChronology().zonedDateTime(endExclusive);
			ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) Chronology.zonedDateTime(endExclusive);
			if (unit is ChronoUnit)
			{
				end = end.WithZoneSameInstant(Offset_Renamed);
				return DateTime.Until(end.ToLocalDateTime(), unit);
			}
			Objects.RequireNonNull(unit, "unit");
			return unit.Between(this, end);
		}
Beispiel #17
0
        public static DateValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            LocalDate localDate = input.DatePart;
            DateValue truncated = Date(TruncateTo(localDate, unit));

            if (fields.Size() == 0)
            {
                return(truncated);
            }
            else
            {
                MapValue updatedFields = fields.UpdatedWith("date", truncated);
                return(Build(updatedFields, defaultZone));
            }
        }
Beispiel #18
0
 private static long AssertValidUntil(Temporal from, Temporal to, TemporalUnit unit)
 {
     try
     {
         return(from.until(to, unit));
     }
     catch (UnsupportedTemporalTypeException e)
     {
         throw new UnsupportedTemporalUnitException(e.Message, e);
     }
     catch (DateTimeException e)
     {
         throw new InvalidValuesArgumentException(e.Message, e);
     }
 }
Beispiel #19
0
        private void Save()
        {
            var target = Units.FirstOrDefault(x => x.Name == UnitName);

            if (target == null)
            {
                var newUnit = TemporalUnit.Clone();
                newUnit.Name = UnitName;
                Units.Insert(0, newUnit);
                SelectedUnit = newUnit;
            }
            else
            {
                target.CopyFrom(TemporalUnit);
            }
            m_config.Save();
        }
Beispiel #20
0
 internal static LocalDate TruncateTo(LocalDate value, TemporalUnit unit)
 {
     if (unit == ChronoUnit.MILLENNIA)
     {
         return(value.with(Neo4JTemporalField.YearOfMillennium, 0));
     }
     else if (unit == ChronoUnit.CENTURIES)
     {
         return(value.with(Neo4JTemporalField.YearOfCentury, 0));
     }
     else if (unit == ChronoUnit.DECADES)
     {
         return(value.with(Neo4JTemporalField.YearOfDecade, 0));
     }
     else if (unit == ChronoUnit.YEARS)
     {
         return(value.with(TemporalAdjusters.firstDayOfYear()));
     }
     else if (unit == IsoFields.WEEK_BASED_YEARS)
     {
         return(value.with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1));
     }
     else if (unit == IsoFields.QUARTER_YEARS)
     {
         return(value.with(IsoFields.DAY_OF_QUARTER, 1));
     }
     else if (unit == ChronoUnit.MONTHS)
     {
         return(value.with(TemporalAdjusters.firstDayOfMonth()));
     }
     else if (unit == ChronoUnit.WEEKS)
     {
         return(value.with(TemporalAdjusters.previousOrSame(DayOfWeek.Monday)));
     }
     else if (unit == ChronoUnit.DAYS)
     {
         return(value);
     }
     else
     {
         throw new UnsupportedTemporalUnitException("Unit too small for truncation: " + unit);
     }
 }
Beispiel #21
0
 //-----------------------------------------------------------------------
 public long Get(TemporalUnit unit)
 {
     if (unit == ChronoUnit.YEARS)
     {
         return(Years);
     }
     else if (unit == ChronoUnit.MONTHS)
     {
         return(Months);
     }
     else if (unit == ChronoUnit.DAYS)
     {
         return(Days);
     }
     else
     {
         throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
     }
 }
Beispiel #22
0
        //-----------------------------------------------------------------------
        public virtual long Until(Temporal endExclusive, TemporalUnit unit)
        {
            Objects.RequireNonNull(endExclusive, "endExclusive");
            ChronoLocalDate end = Chronology.Date(endExclusive);

            if (unit is ChronoUnit)
            {
                switch ((ChronoUnit)unit)
                {
                case DAYS:
                    return(DaysUntil(end));

                case WEEKS:
                    return(DaysUntil(end) / 7);

                case MONTHS:
                    return(MonthsUntil(end));

                case YEARS:
                    return(MonthsUntil(end) / 12);

                case DECADES:
                    return(MonthsUntil(end) / 120);

                case CENTURIES:
                    return(MonthsUntil(end) / 1200);

                case MILLENNIA:
                    return(MonthsUntil(end) / 12000);

                case ERAS:
                    return(end.GetLong(ERA) - GetLong(ERA));
                }
                throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
            }
            Objects.RequireNonNull(unit, "unit");
            return(unit.Between(this, end));
        }
Beispiel #23
0
        public override long Get(TemporalUnit unit)
        {
            if (unit is ChronoUnit)
            {
                switch (( ChronoUnit )unit)
                {
                case MONTHS:
                    return(_months);

                case DAYS:
                    return(_days);

                case SECONDS:
                    return(_seconds);

                case NANOS:
                    return(_nanos);

                default:
                    break;
                }
            }
            throw new UnsupportedTemporalUnitException("Unsupported unit: " + unit);
        }
Beispiel #24
0
        public static DateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "date time");

            LocalDate truncatedDate = pair.First();
            LocalTime truncatedTime = pair.Other();

            ZoneId        zoneId       = input.supportsTimeZone() ? input.getZoneId(defaultZone) : defaultZone();
            ZonedDateTime truncatedZDT = ZonedDateTime.of(truncatedDate, truncatedTime, zoneId);

            if (fields.Size() == 0)
            {
                return(Datetime(truncatedZDT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    truncatedZDT = truncatedZDT.withZoneSameLocal(TimezoneOf(timezone));
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedZDT, (mapValue, zonedDateTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return Datetime(zonedDateTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("datetime", Datetime(zonedDateTime)), defaultZone);
                    }
                }));
            }
        }
Beispiel #25
0
        public static LocalTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            LocalTime localTime   = input.LocalTimePart;
            LocalTime truncatedLT = AssertValidUnit(() => localTime.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(localTime(truncatedLT));
            }
            else
            {
                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedLT, (mapValue, localTime1) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return localTime(localTime1);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", localTime(localTime1)), defaultZone);
                    }
                }));
            }
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Gets the value of the specified unit.
 /// <para>
 /// This will return a value for the years, months and days units.
 /// Note that weeks are not included.
 /// All other units throw an exception.
 /// </para>
 /// <para>
 /// This method implements <seealso cref="TemporalAmount"/>.
 /// It is not intended to be called directly.
 ///
 /// </para>
 /// </summary>
 /// <param name="unit">  the unit to query </param>
 /// <returns> the value of the unit </returns>
 /// <exception cref="UnsupportedTemporalTypeException"> if the unit is not supported </exception>
 public override long get(TemporalUnit unit)
 {
     return(period.get(unit));
 }
Beispiel #27
0
 protected internal override LocalTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
 {
     return(LocalTimeValue.truncate(unit, input, fields, defaultZone));
 }
Beispiel #28
0
 public override MinguoDate Minus(long amountToAdd, TemporalUnit unit)
 {
     return(base.Minus(amountToAdd, unit));
 }
Beispiel #29
0
 public MinguoDate Plus(long amountToAdd, TemporalUnit unit)
 {
     return(base.Plus(amountToAdd, unit));
 }
Beispiel #30
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("coupon"); // Start: coupon

            xmlWriter.WriteElementString("coupon_code", CouponCode);
            xmlWriter.WriteElementString("name", Name);
            xmlWriter.WriteElementString("hosted_description", HostedDescription);
            xmlWriter.WriteElementString("invoice_description", InvoiceDescription);

            if (RedeemByDate.HasValue)
            {
                xmlWriter.WriteElementString("redeem_by_date", RedeemByDate.Value.ToString("s"));
            }

            if (SingleUse.HasValue)
            {
                xmlWriter.WriteElementString("single_use", SingleUse.Value.AsString());
            }

            if (AppliesForMonths.HasValue)
            {
                xmlWriter.WriteElementString("applies_for_months", AppliesForMonths.Value.AsString());
            }
            if (Duration != null)
            {
                xmlWriter.WriteElementString("duration", Duration.ToString().EnumNameToTransportCase());
            }
            if (TemporalUnit != null)
            {
                xmlWriter.WriteElementString("temporal_unit", TemporalUnit.ToString().EnumNameToTransportCase());
            }
            if (TemporalAmount.HasValue)
            {
                xmlWriter.WriteElementString("temporal_amount", TemporalAmount.Value.ToString());
            }

            if (AppliesToAllPlans.HasValue)
            {
                xmlWriter.WriteElementString("applies_to_all_plans", AppliesToAllPlans.Value.AsString());
            }

            if (AppliesToNonPlanCharges.HasValue)
            {
                xmlWriter.WriteElementString("applies_to_non_plan_charges", AppliesToNonPlanCharges.Value.AsString());
            }

            if (MaxRedemptions.HasValue)
            {
                xmlWriter.WriteElementString("max_redemptions", MaxRedemptions.Value.AsString());
            }

            if (MaxRedemptionsPerAccount.HasValue)
            {
                xmlWriter.WriteElementString("max_redemptions_per_account", MaxRedemptionsPerAccount.Value.AsString());
            }

            xmlWriter.WriteElementString("discount_type", DiscountType.ToString().EnumNameToTransportCase());

            xmlWriter.WriteElementString("redemption_resource", RedemptionResource.ToString().EnumNameToTransportCase());

            xmlWriter.WriteElementString("coupon_type", Type.ToString().EnumNameToTransportCase());

            if (Type == CouponType.Bulk)
            {
                xmlWriter.WriteElementString("unique_code_template", UniqueCodeTemplate);
            }

            if (CouponDiscountType.Percent == DiscountType && DiscountPercent.HasValue)
            {
                xmlWriter.WriteElementString("discount_percent", DiscountPercent.Value.AsString());
            }

            if (CouponDiscountType.Dollars == DiscountType)
            {
                xmlWriter.WriteIfCollectionHasAny("discount_in_cents", DiscountInCents, pair => pair.Key,
                                                  pair => pair.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("plan_codes", Plans, s => "plan_code", s => s);

            if (FreeTrialAmount.HasValue)
            {
                xmlWriter.WriteElementString("free_trial_amount", FreeTrialAmount.Value.AsString());
            }

            if (FreeTrialUnit.HasValue)
            {
                xmlWriter.WriteElementString("free_trial_unit", FreeTrialUnit.Value.ToString().EnumNameToTransportCase());
            }

            xmlWriter.WriteEndElement(); // End: coupon
        }