private void Serialize(CsnTimeZone ctz, JsonTextWriter json) { json.WriteStartObject(); json.WritePropertyName(this.names[1]); json.WriteValue(ctz.Id); json.WritePropertyName(this.names[2]); json.WriteValue(ctz.DisplayName); json.WritePropertyName(this.names[3]); json.WriteValue(ctz.DaylightName); json.WritePropertyName(this.names[4]); json.WriteValue(ctz.StandardName); json.WritePropertyName(this.names[5]); json.WriteValue(ctz.HasDst); json.WritePropertyName(this.names[6]); json.WriteValue(ctz.UtcOffsetHours); if (ctz.Adjustments != null) { json.WritePropertyName(this.names[7]); json.WriteStartArray(); foreach (CsnAdjustment adj in ctz.Adjustments) { Serialize(adj, json); } json.WriteEndArray(); } json.WriteEndObject(); }
private long?WriteTz(CsnTimeZone x, Writer w, long tzType, long adjType, long ttType) { long?rcAdjArr = null; if (x.Adjustments != null) { var rcAdjs = x.Adjustments.Select(y => WriteAdj(y, w, adjType, ttType)); rcAdjArr = w.WriteArray().WRef(rcAdjs.ToArray()).Current; } return(w.WriteInstance(tzType).W(x.Id).W(x.DisplayName).W(x.DaylightName).W(x.StandardName).W(x.HasDst).W(x.UtcOffsetHours).WRef(rcAdjArr).Current); }
public void Serialize(CsnTimeZones ctzs, StreamWriter sw) { Writer w = new Writer(sw); // typedefs long ttType = w.WriteTypeDef("TransitionTime", "IsFixedDateRule", "Day", "Month", "TimeOfDay", "Week", "DayOfWeek").Current; long adjType = w.WriteTypeDef("Adjustment", "StartDate", "EndDate", "DaylightDeltaHours", "TransitionStart", "TransitionEnd").Current; long tzType = w.WriteTypeDef("TimeZone", "Id", "DisplayName", "DaylightName", "StandardName", "HasDst", "UtcOffsetHours", "Adjustments").Current; long tzsType = w.WriteTypeDef("TimeZones", "AllTimeZones").Current; int tzLen = ctzs.AllTimeZones.Length; long?[] rcTzsArr = new long?[tzLen]; for (int tzCtr = 0; tzCtr < tzLen; tzCtr++) { CsnTimeZone ctz = ctzs.AllTimeZones[tzCtr]; long? rcAdjArr = null; if (ctz.Adjustments != null) { int adjLen = ctz.Adjustments.Length; if (adjLen > 0) { long?[] arrAdjs = new long?[adjLen]; for (int adjCtr = 0; adjCtr < adjLen; adjCtr++) { CsnAdjustment adj = ctz.Adjustments[adjCtr]; long? rcTtStart = this.WriteTrTime(adj.TransitionStart, w, ttType); long? rcTtEnd = this.WriteTrTime(adj.TransitionEnd, w, ttType); arrAdjs[adjCtr] = w.WriteInstance(adjType).W(adj.StartDate).W(adj.EndDate).W(adj.DaylightDeltaHours).WRef(rcTtStart).WRef(rcTtEnd).Current; } rcAdjArr = w.WriteArray().WRef(arrAdjs).Current; } } rcTzsArr[tzCtr] = w.WriteInstance(tzType).W(ctz.Id).W(ctz.DisplayName).W(ctz.DaylightName).W(ctz.StandardName).W(ctz.HasDst).W(ctz.UtcOffsetHours).WRef(rcAdjArr).Current; } long rc = w.WriteArray().WRef(rcTzsArr).Current; w.WriteInstance(tzsType).WRef(rc); sw.Flush(); }