Ejemplo n.º 1
0
        internal BinaryOrderedUdtNormalizer(Type t, bool isTopLevelUdt)
        {
            _skipNormalize = false;
            if (_skipNormalize)
            {
                // if skipping normalization, dont write the null
                // byte header for IsNull
                _isTopLevelUdt = true;
            }

            _isTopLevelUdt = true;

            // get all the fields
            FieldInfo[] fields = GetFields(t);

            FieldsToNormalize = new FieldInfoEx[fields.Length];

            int i = 0;

            foreach (FieldInfo fi in fields)
            {
                int offset = Marshal.OffsetOf(fi.DeclaringType, fi.Name).ToInt32();
                FieldsToNormalize[i++] = new FieldInfoEx(fi, offset, GetNormalizer(fi.FieldType));
            }

            //sort by offset
            Array.Sort(FieldsToNormalize);
            //if this is not a top-level udt, do setup for null values.
            //null values need to compare less than all other values,
            //so prefix a null byte indicator.
            if (!_isTopLevelUdt)
            {
                //get the null value for this type, special case for sql types, which
                //have a null field
                if (typeof(INullable).IsAssignableFrom(t))
                {
                    PropertyInfo pi = t.GetProperty("Null",
                                                    BindingFlags.Public | BindingFlags.Static);
                    if (pi == null || pi.PropertyType != t)
                    {
                        FieldInfo fi = t.GetField("Null", BindingFlags.Public | BindingFlags.Static);
                        if (fi == null || fi.FieldType != t)
                        {
                            throw new Exception("could not find Null field/property in nullable type " + t);
                        }
                        else
                        {
                            NullInstance = fi.GetValue(null);
                        }
                    }
                    else
                    {
                        NullInstance = pi.GetValue(null, null);
                    }
                    //create the padding buffer
                    _padBuffer = new byte[Size - 1];
                }
            }
        }
Ejemplo n.º 2
0
        // Sort fields by field offsets.
        public int CompareTo(object other)
        {
            FieldInfoEx otherF = other as FieldInfoEx;

            if (otherF == null)
            {
                return(-1);
            }
            return(Offset.CompareTo(otherF.Offset));
        }
        public int CompareTo(object other)
        {
            FieldInfoEx ex = other as FieldInfoEx;

            if (ex == null)
            {
                return(-1);
            }
            return(this.offset.CompareTo(ex.offset));
        }
Ejemplo n.º 4
0
        internal BinaryOrderedUdtNormalizer(Type t, bool isTopLevelUdt) {
            this.m_skipNormalize = false;
            if (this.m_skipNormalize) {
                //if skipping normalization, dont write the null
                //byte header for IsNull
                this.m_isTopLevelUdt = true;
            }
            //top level udt logic is disabled until we decide
            //what to do about nested udts
            this.m_isTopLevelUdt = true;
            //      else
            //        this.m_isTopLevelUdt = isTopLevelUdt;
            //get all the fields

            FieldInfo[] fields = GetFields (t);

            m_fieldsToNormalize = new FieldInfoEx[fields.Length];

            int i = 0;

            foreach (FieldInfo fi in fields) {
                int offset = Marshal.OffsetOf(fi.DeclaringType, fi.Name).ToInt32();
                m_fieldsToNormalize[i++] = new FieldInfoEx(fi, offset, GetNormalizer(fi.FieldType));
            }

            //sort by offset
            Array.Sort(m_fieldsToNormalize);
            //if this is not a top-level udt, do setup for null values.
            //null values need to compare less than all other values,
            //so prefix a null byte indicator.
            if (!this.m_isTopLevelUdt) {
                //get the null value for this type, special case for sql types, which
                //have a null field
                if (typeof(System.Data.SqlTypes.INullable).IsAssignableFrom(t)) {
                    PropertyInfo pi = t.GetProperty("Null",
                    BindingFlags.Public | BindingFlags.Static);
                    if (pi == null || pi.PropertyType != t) {
                        FieldInfo fi = t.GetField("Null", BindingFlags.Public | BindingFlags.Static);
                        if (fi == null || fi.FieldType != t)
                            throw new Exception("could not find Null field/property in nullable type " + t);
                        else
                            this.NullInstance = fi.GetValue(null);
                    }
                    else {
                        this.NullInstance = pi.GetValue(null, null);
                    }
                    //create the padding buffer
                    this.m_PadBuffer = new byte[this.Size-1];
                }
            }
        }