FieldAssignedValue() private method

private FieldAssignedValue ( Field field ) : void
field Field
return void
Exemplo n.º 1
0
        public override void ValueFromJson(JsonReader reader, Row row, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            Int32 v;

            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                _setValue(row, null);
                break;

            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Boolean:
                v = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture);
                if (EnumType == null)
                {
                    _setValue(row, v);
                }
                else
                {
                    _setValue(row, (Int32)ConvertEnumFromInt(EnumType, v));
                }
                break;

            case JsonToken.String:
                string s = ((string)reader.Value).TrimToNull();
                if (s == null)
                {
                    _setValue(row, null);
                }
                else if (EnumType == null)
                {
                    _setValue(row, Convert.ToInt32(s, CultureInfo.InvariantCulture));
                }
                else
                {
                    _setValue(row, (Int32)ConvertEnumFromString(EnumType, s));
                }
                break;

            default:
                throw JsonUnexpectedToken(reader);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 2
0
        public override void ValueFromJson(JsonReader reader, Row row, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                _setValue(row, null);
                break;

            case JsonToken.Date:
                var      obj = reader.Value;
                DateTime value;
                if (obj is DateTime)
                {
                    value = (DateTime)obj;
                }
                else if (obj is DateTimeOffset)
                {
                    _setValue(row, ToDateTimeKind((DateTimeOffset)obj));
                    break;
                }
                else
                {
                    value = Convert.ToDateTime(obj, CultureInfo.InvariantCulture);
                }

                _setValue(row, ToDateTimeKind(value));
                break;

            case JsonToken.String:
                var s = ((string)reader.Value).TrimToNull();
                if (s == null)
                {
                    _setValue(row, null);
                }
                else
                {
                    _setValue(row, ToDateTimeKind(Convert.ToDateTime(s, CultureInfo.InvariantCulture)));
                }
                break;

            default:
                throw JsonUnexpectedToken(reader);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 3
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                byte[] a;
#if COREFX
                if (reader.GetType().Name == "SqliteDataReader")
                {
                    a = (byte[])reader.GetValue(index);
                }
                else if (reader.GetType().Name == "MySqlDataReader")
                {
                    a = (byte[])reader.GetValue(index);
                }
                else
                {
#endif
                long available = reader.GetBytes(index, (long)0, null, 0, 0);
                a = new byte[available];
                if (a.Length > 0)
                {
                    reader.GetBytes(index, (long)0, a, 0, a.Length);
                }
#if COREFX
            }
#endif


                if (a.Length == 25)
                {
                    _setValue(row, new Geometry(a));
                }
                else
                {
                    var          ms     = new MemoryStream(a);
                    StreamReader sr     = new StreamReader(ms);
                    var          geoStr = sr.ReadToEnd();
                    _setValue(row, new Geometry(geoStr));
                }
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 4
0
        public override void Copy(Row source, Row target)
        {
            var value = _getValue(source);

            if (value != null)
            {
                value = Clone(value);
            }

            _setValue((Row)(target), value);
            if (target.tracking)
            {
                target.FieldAssignedValue(this);
            }
        }
Exemplo n.º 5
0
 public new TEnum? this[Row row]
 {
     get
     {
         CheckUnassignedRead(row);
         return((TEnum?)(object)_getValue(row));
     }
     set
     {
         _setValue(row, (Int32?)(object)value);
         if (row.tracking)
         {
             row.FieldAssignedValue(this);
         }
     }
 }
Exemplo n.º 6
0
        public override void AsObject(Row row, object value)
        {
            if (value == null)
            {
                _setValue(row, null);
            }
            else
            {
                _setValue(row, (TimeSpan)value);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 7
0
        public override void AsObject(Row row, object value)
        {
            if (value == null)
            {
                _setValue(row, null);
            }
            else
            {
                _setValue(row, ToDateTimeKind((DateTime)value));
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 8
0
 public TValue? this[Row row]
 {
     get
     {
         CheckUnassignedRead(row);
         return(_getValue(row));
     }
     set
     {
         _setValue(row, value);
         if (row.tracking)
         {
             row.FieldAssignedValue(this);
         }
     }
 }
Exemplo n.º 9
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                _setValue(row, GetFromReader(reader, index));
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 10
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                _setValue(row, JsonConvert.DeserializeObject <TValue>(reader.GetString(index), Settings ?? JsonSettings.Strict));
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 11
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                _setValue(row, Convert.ToInt64(reader.GetValue(index), CultureInfo.InvariantCulture));
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                byte[] a;
#if COREFX
                if (reader.GetType().Name == "SqliteDataReader")
                {
                    a = (byte[])reader.GetValue(index);
                }
                else
                {
#endif
                long available = reader.GetBytes(index, (long)0, null, 0, 0);
                a = new byte[available];
                if (a.Length > 0)
                {
                    reader.GetBytes(index, (long)0, a, 0, a.Length);
                }
#if COREFX
            }
#endif

                _setValue(row, a);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 13
0
        public override void AsObject(Row row, object value)
        {
            if (value == null)
            {
                _setValue(row, null);
            }
            else
            {
                try
                {
                    _setValue(row, (TValue)value);
                } catch (InvalidCastException ex)
                {
                    throw new InvalidCastException($"Invalid cast exception while trying to set the value of {this.Name} field on {row.GetType().Name} as object.", ex);
                }
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 14
0
        public override void ValueFromJson(JsonReader reader, Row row, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                _setValue(row, null);
                break;

            case JsonToken.Date:
                _setValue(row, DateTimeOffset.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture));
                break;

            case JsonToken.String:
                var s = ((string)reader.Value).TrimToNull();
                if (s == null)
                {
                    _setValue(row, null);
                }
                else
                {
                    _setValue(row, DateTimeOffset.Parse(s, CultureInfo.InvariantCulture));
                }
                break;

            default:
                throw JsonUnexpectedToken(reader);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 15
0
        public new TEnum? this[Row row]
        {
            get
            {
                CheckUnassignedRead(row);
                var value = _getValue(row);
                if (value == null)
                {
                    return(null);
                }

                return((TEnum)(object)value);
            }
            set
            {
                Int32?v = value == null ? (Int32?)null : Convert.ToInt32(value);
                _setValue(row, v);
                if (row.tracking)
                {
                    row.FieldAssignedValue(this);
                }
            }
        }
Exemplo n.º 16
0
 public new DateTime? this[Row row]
 {
     get
     {
         CheckUnassignedRead(row);
         return(_getValue(row));
     }
     set
     {
         if (value != null)
         {
             _setValue(row, ToDateTimeKind(value.Value));
         }
         else
         {
             _setValue(row, value);
         }
         if (row.tracking)
         {
             row.FieldAssignedValue(this);
         }
     }
 }
Exemplo n.º 17
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                long   available = reader.GetBytes(index, (long)0, null, 0, 0);
                byte[] a         = new byte[available];
                reader.GetBytes(index, (long)0, a, 0, a.Length);
                _setValue(row, new MemoryStream(a));
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 18
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                var      value = reader.GetValue(index);
                TimeSpan timeSpan;
                if (value is TimeSpan)
                {
                    timeSpan = (TimeSpan)value;
                }
                else if (value is DateTime)
                {
                    timeSpan = ((DateTime)value).TimeOfDay;
                }
                else
                {
                    timeSpan = TimeSpan.Parse(value.ToString(), CultureInfo.InvariantCulture);
                }

                _setValue(row, timeSpan);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 19
0
        public override void GetFromReader(IDataReader reader, int index, Row row)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.IsDBNull(index))
            {
                _setValue(row, null);
            }
            else
            {
                DateTimeOffset dto;
                var            value = reader.GetValue(index);
                if (value is DateTime)
                {
                    dto = (DateTimeOffset)(DateTime)value;
                }
                else if (value is DateTimeOffset)
                {
                    dto = (DateTimeOffset)value;
                }
                else
                {
                    dto = DateTimeOffset.Parse(value.ToString());
                }

                _setValue(row, dto);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Exemplo n.º 20
0
        public override void ValueFromJson(JsonReader reader, Row row, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                _setValue(row, null);
                break;

            default:
                _setValue(row, ValueFromJson(reader, serializer));
                break;
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }