/// <summary>
 /// Override to compare the state of this object with another.
 /// </summary>
 /// <param name="baseOther">This object will always be of the same type as current</param>
 protected override bool Equals(BaseField baseOther)
 {
     return true;
 }
Esempio n. 2
0
 protected override bool Equals(BaseField baseOther)
 {
     var other = (UtcDateTimeField)baseOther;
     return _deltaField.Equals(other._deltaField);
 }
Esempio n. 3
0
 // No need to override GetHashCode either
 protected override bool Equals(BaseField baseOther)
 {
     return true; // No state, any fields with the same type equal
 }
 protected override bool Equals(BaseField baseOther)
 {
     var other = (ScaledDeltaFloatField) baseOther;
     return _divider == other._divider && _multiplier == other._multiplier && _precision.Equals(other._precision);
 }
Esempio n. 5
0
 /// <summary>
 /// Every field must override 
 /// <see cref="GetHashCode"/> and  <see cref="Equals(NYurik.TimeSeriesDb.Serializers.BlockSerializer.BaseField)"/>,
 /// and combine base call with its own results.
 /// </summary>
 protected abstract bool Equals(BaseField baseOther);
        protected override bool Equals(BaseField baseOther)
        {
            var other = (ScaledDeltaFloatField)baseOther;

            return(_divider == other._divider && _multiplier == other._multiplier && _precision.Equals(other._precision));
        }
Esempio n. 7
0
 protected override bool Equals(BaseField baseOther)
 {
     var other = (ConstantField) baseOther;
     return Equals(_value, other._value);
 }
Esempio n. 8
0
 protected override bool Equals(BaseField baseOther)
 {
     var otherFld = ((ComplexField) baseOther)._fields;
     return ReferenceEquals(_fields, otherFld) ||
            (_fields != null && otherFld != null && _fields.SequenceEqual(otherFld));
 }
Esempio n. 9
0
        private void PopulateFieldsImpl(Mode mode)
        {
            if (_fields != null)
            {
                return;
            }

            ThrowOnInitialized();

            if (mode == Mode.Auto)
            {
                mode = 0;
                if (_constructor != null)
                {
                    mode |= Mode.Constructor;
                }
                else if (FieldType.GetFields(TypeUtils.AllInstanceMembers).Any(fi => fi.IsInitOnly))
                {
                    mode |= Mode.NonPublic | Mode.Constructor;
                }
                else
                {
                    mode |= Mode.NonPublic | Mode.Fields;
                }
            }

            IEnumerable <MemberInfo> members;

            if ((mode & Mode.Fields) == 0 && (mode & Mode.Properties) == 0)
            {
                mode |= Mode.Fields | Mode.Properties;
            }

            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public;

            if ((mode & Mode.NonPublic) != 0)
            {
                flags |= BindingFlags.NonPublic;
            }

            if ((mode & Mode.Constructor) != 0)
            {
                if (_constructor == null)
                {
                    _constructor = ChooseCtor();
                }

                members = _constructor.GetParameters()
                          .Select(i => FindMatchingMember(i, flags, mode));
            }
            else
            {
                members = (mode & Mode.Fields) != 0
                              ? FieldType.GetFields(flags).Where(i => !i.IsInitOnly)
                              : Enumerable.Empty <MemberInfo>();

                if ((mode & Mode.Properties) != 0)
                {
                    members = members.Concat(FieldType.GetProperties(flags).Where(i => i.CanWrite));
                }
            }

            IList <SubFieldInfo> fields = new List <SubFieldInfo>();

            foreach (MemberInfo mi in members)
            {
                bool isField = mi.MemberType == MemberTypes.Field;
                var  mType   = mi.PropOrFieldType();

                string name = StateName + "." + mi.Name;

                if (isField && mType.IsNested)
                {
                    object[] ca = mi.GetCustomAttributes(typeof(FixedBufferAttribute), false);
                    if (ca.Length > 0)
                    {
                        // ((FixedBufferAttribute)ca[0]).Length;
                        throw new NotImplementedException("Fixed arrays are not supported at this time");
                    }
                }

                BaseField fld = StateStore.CreateField(mType, name, true);
                fields.Add(new SubFieldInfo(mi, fld));
            }

            _fields = fields;
        }
Esempio n. 10
0
        public BaseField CreateField(Type valueType, string name, bool allowCustom)
        {
            if (valueType == null)
            {
                throw new ArgumentNullException("valueType");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (allowCustom && _fieldFactory != null)
            {
                BaseField fld = _fieldFactory(this, valueType, name);
                if (fld != null)
                {
                    return(fld);
                }
            }

            if (valueType.IsArray)
            {
                throw new SerializerException("Arrays are not supported ({0})", valueType);
            }

            if (valueType.IsPrimitive)
            {
                switch (Type.GetTypeCode(valueType))
                {
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Boolean:
                    return(new SimpleField(this, valueType, name));

                case TypeCode.Char:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                    return(new ScaledDeltaIntField(this, valueType, name));

                case TypeCode.Single:
                case TypeCode.Double:
                    return(new ScaledDeltaFloatField(this, valueType, name));

                default:
                    throw new SerializerException("Unsupported primitive type " + valueType);
                }
            }

            var srlzr = valueType.GetSingleAttribute <FieldAttribute>();

            if (srlzr != null)
            {
                try
                {
                    return(CreateFieldWithCtor(srlzr.Serializer, valueType, name));
                }
                catch (Exception ex)
                {
                    throw new SerializerException(
                              ex, "Custom field serializer {0} attached to type {1} failed.", srlzr.Serializer.ToDebugStr(),
                              valueType.ToDebugStr());
                }
            }

            return(new ComplexField(this, valueType, name));
        }
Esempio n. 11
0
 protected override bool Equals(BaseField baseOther)
 {
     var other = (ScaledDeltaIntField)baseOther;
     return _divider == other._divider;
 }