public static SerializationColumnResponse ConvertFrom(SerializationColumn serializationColumn) { return(new SerializationColumnResponse { Index = serializationColumn.Index, Tags = serializationColumn.Tags, DerivedTags = serializationColumn.DerivedTags, Name = serializationColumn.Name, DataType = serializationColumn.DataType, Comment = serializationColumn.Comment, IsKey = serializationColumn.IsKey, IsUnique = serializationColumn.IsUnique, AllowNull = serializationColumn.AllowNull, AutoIncrement = serializationColumn.AutoIncrement, ReadOnly = serializationColumn.ReadOnly }); }
private void WriteField(BinaryWriter writer, SerializationColumn dataColumn, object value, SerializationType[] types) { if (dataColumn.DataType == typeof(bool).GetTypeName()) { writer.Write((bool)value); } else if (dataColumn.DataType == typeof(string).GetTypeName()) { writer.Write(this.GetStringID(value as string)); } else if (dataColumn.DataType == typeof(float).GetTypeName()) { writer.Write((float)value); } else if (dataColumn.DataType == typeof(double).GetTypeName()) { writer.Write((double)value); } else if (dataColumn.DataType == typeof(sbyte).GetTypeName()) { writer.Write((sbyte)value); } else if (dataColumn.DataType == typeof(byte).GetTypeName()) { writer.Write((byte)value); } else if (dataColumn.DataType == typeof(int).GetTypeName()) { writer.Write((int)value); } else if (dataColumn.DataType == typeof(uint).GetTypeName()) { writer.Write((uint)value); } else if (dataColumn.DataType == typeof(short).GetTypeName()) { writer.WriteValue((short)value); } else if (dataColumn.DataType == typeof(ushort).GetTypeName()) { writer.WriteValue((ushort)value); } else if (dataColumn.DataType == typeof(long).GetTypeName()) { writer.Write((long)value); } else if (dataColumn.DataType == typeof(ulong).GetTypeName()) { writer.Write((ulong)value); } else if (dataColumn.DataType == typeof(DateTime).GetTypeName()) { var dateTime = (DateTime)value; var delta = dateTime - new DateTime(1970, 1, 1); var seconds = Convert.ToInt64(delta.TotalSeconds); writer.Write(seconds); } else if (dataColumn.DataType == typeof(TimeSpan).GetTypeName()) { if (value is TimeSpan timeSpanValue) { writer.Write(timeSpanValue.Ticks); } else if (value is long longValue) { writer.Write(longValue); } else { throw new InvalidOperationException($"{value.GetType()} is invalid timespan type"); } } else if (dataColumn.DataType == typeof(string).GetTypeName()) { writer.Write(this.GetStringID(value.ToString())); } else { var type = types.First(item => dataColumn.DataType == item.CategoryPath + item.Name); writer.Write((int)type.ConvertFromString(value.ToString())); } }