public void SetDecodeDate(String propName, PropertySwift property, IndentedStringBuilder indented) { var modelType = property.ModelType as PrimaryTypeSwift; var formatString = String.Empty; if (modelType != null) { switch (modelType.KnownPrimaryType) { case KnownPrimaryType.Date: formatString = "date"; break; case KnownPrimaryType.DateTime: formatString = "dateTime"; break; case KnownPrimaryType.DateTimeRfc1123: formatString = "dateTimeRfc1123"; break; default: throw new Exception("Date format unknown"); } indented.Append($" self.{propName} = DateConverter.fromString(dateStr: (try container.decode(String?.self, forKey: .{propName})), format: .{formatString})" + (property.IsRequired ? "!" : "") + "\r\n"); return; } throw new Exception("Date format unknown"); }
public void SetEncodeDate(String propName, PropertySwift property, IndentedStringBuilder indented) { var modelType = property.ModelType as PrimaryTypeSwift; var formatString = String.Empty; if (modelType != null) { switch (modelType.KnownPrimaryType) { case KnownPrimaryType.Date: formatString = "date"; break; case KnownPrimaryType.DateTime: formatString = "dateTime"; break; case KnownPrimaryType.DateTimeRfc1123: formatString = "dateTimeRfc1123"; break; default: throw new Exception("Date format unknown"); } if (property.IsRequired) { indented.Append($"try container.encode(DateConverter.toString(date: self.{propName}, format: .{formatString}), forKey: .{propName})\r\n"); } else { indented.Append($"if self.{propName} != nil {{\r\n"); indented.Append($" try container.encode(DateConverter.toString(date: self.{propName}!, format: .{formatString}), forKey: .{propName})\r\n"); indented.Append($"}}\r\n"); } return; } throw new Exception("Date format unknown"); }