Пример #1
0
        /// <summary>
        /// Returns the highest precedence data type
        /// </summary>
        /// <param name="Affinity">A collection of cell afffinities</param>
        /// <returns>The highest cell precedence</returns>
        public static CellAffinity Highest(IEnumerable <CellAffinity> Affinity)
        {
            if (Affinity.Count() == 0)
            {
                return(CellAffinity.BOOL);
            }
            else if (Affinity.Count() == 1)
            {
                return(Affinity.First());
            }

            CellAffinity a = CellAffinity.BOOL;

            foreach (CellAffinity b in Affinity)
            {
                a = CellAffinityHelper.Highest(a, b);
            }
            return(a);
        }
Пример #2
0
        public static int Compare(Cell A, Cell B)
        {
            if (A.NULL == 1 && B.NULL == 1)
            {
                return(0);
            }
            else if (A.NULL == 1)
            {
                return(1);
            }
            else if (B.NULL == 1)
            {
                return(-1);
            }

            CellAffinity max = CellAffinityHelper.Highest(A.AFFINITY, B.AFFINITY);

            if (A.AFFINITY == B.AFFINITY)
            {
                if (A.AFFINITY == CellAffinity.BOOL)
                {
                    return(A.BOOL == B.BOOL ? 0 : (A.BOOL ? 1 : -1));
                }

                else if (A.AFFINITY == CellAffinity.DATE_TIME)
                {
                    return(DateTime.Compare(A.DATE, B.DATE));
                }

                else if (A.AFFINITY == CellAffinity.BYTE)
                {
                    return(A.BYTE == B.BYTE ? 0 : (A.BYTE < B.BYTE ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.SHORT)
                {
                    return(A.SHORT == B.SHORT ? 0 : (A.SHORT < B.SHORT ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.INT)
                {
                    return(A.INT == B.INT ? 0 : (A.INT < B.INT ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.LONG)
                {
                    return(A.LONG == B.LONG ? 0 : (A.LONG < B.LONG ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.SINGLE)
                {
                    return(A.SINGLE == B.SINGLE ? 0 : (A.SINGLE < B.SINGLE ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.DOUBLE)
                {
                    return(A.DOUBLE == B.DOUBLE ? 0 : (A.DOUBLE < B.DOUBLE ? -1 : 1));
                }

                else if (A.AFFINITY == CellAffinity.BINARY)
                {
                    return(ByteArrayCompare(A.BINARY, B.BINARY));
                }

                else if (A.AFFINITY == CellAffinity.BSTRING)
                {
                    return(BString.CompareStrict(A.BSTRING, B.BSTRING));
                }

                else if (A.Affinity == CellAffinity.CSTRING || A.Affinity == CellAffinity.TREF)
                {
                    return(StringComparer.OrdinalIgnoreCase.Compare(A.CSTRING, B.CSTRING));
                }

                else if (A.AFFINITY == CellAffinity.ARRAY)
                {
                    // Minimums //
                    if ((A.ARRAY.IsMin && !B.ARRAY.IsMin) || (!A.ARRAY.IsMax && B.ARRAY.IsMax))
                    {
                        return(-1);
                    }
                    if ((!A.ARRAY.IsMin && B.ARRAY.IsMin) || (A.ARRAY.IsMax && !B.ARRAY.IsMax))
                    {
                        return(1);
                    }
                    if ((A.ARRAY.IsMin && B.ARRAY.IsMin) || (A.ARRAY.IsMax && B.ARRAY.IsMax))
                    {
                        return(01);
                    }


                    if (A.ARRAY.Count != B.ARRAY.Count)
                    {
                        return(A.ARRAY.Count > B.ARRAY.Count ? 1 : -1);
                    }
                    for (int i = 0; i < A.ARRAY.Count; i++)
                    {
                        int v = Compare(A.ARRAY[i], B.ARRAY[i]);
                        if (v != 0)
                        {
                            return(v);
                        }
                    }
                    return(0);
                }
            }
            else
            {
                if (max == CellAffinity.ARRAY)
                {
                    return(1);
                }

                if (max == CellAffinity.TREF)
                {
                    return(StringComparer.OrdinalIgnoreCase.Compare(A.valueTREF, B.valueTREF));
                }

                if (max == CellAffinity.CSTRING)
                {
                    return(StringComparer.OrdinalIgnoreCase.Compare(A.valueCSTRING, B.valueCSTRING));
                }

                else if (max == CellAffinity.BSTRING)
                {
                    return(BString.CompareStrict(A.valueBSTRING, B.valueBSTRING));
                }

                else if (max == CellAffinity.BINARY)
                {
                    return(ByteArrayCompare(A.valueBINARY, B.valueBINARY));
                }

                else if (max == CellAffinity.DOUBLE)
                {
                    return(A.valueDOUBLE == B.valueDOUBLE ? 0 : (A.valueDOUBLE < B.valueDOUBLE ? -1 : 1));
                }

                else if (max == CellAffinity.SINGLE)
                {
                    return(A.valueSINGLE == B.valueSINGLE ? 0 : (A.valueSINGLE < B.valueSINGLE ? -1 : 1));
                }

                else if (max == CellAffinity.LONG)
                {
                    return(A.valueLONG == B.valueLONG ? 0 : (A.valueLONG < B.valueLONG ? -1 : 1));
                }

                else if (max == CellAffinity.INT)
                {
                    return(A.valueINT == B.valueINT ? 0 : (A.valueINT < B.valueINT ? -1 : 1));
                }

                else if (max == CellAffinity.SHORT)
                {
                    return(A.valueSHORT == B.valueSHORT ? 0 : (A.valueSHORT < B.valueSHORT ? -1 : 1));
                }

                else if (max == CellAffinity.BYTE)
                {
                    return(A.valueBYTE == B.valueBYTE ? 0 : (A.valueBYTE < B.valueBYTE ? -1 : 1));
                }

                else if (max == CellAffinity.DATE_TIME)
                {
                    return(DateTime.Compare(A.valueDATE_TIME, B.valueDATE_TIME));
                }

                else if (max == CellAffinity.BOOL)
                {
                    return(A.valueBOOL == B.valueBOOL ? 0 : (A.valueBOOL ? 1 : -1));
                }
            }

            return(0);
        }