Beispiel #1
0
        protected VariantBase(EnumType type, string value)
        {
            switch (type)
            {
            case EnumType.Any:
                Value = new VariantAny(value);
                break;

            case EnumType.String:
                Value = new VariantPrimitive <String>(value);
                break;

            case EnumType.Boolean:
                Value = new VariantPrimitive <bool>(ParseBoolean(value));
                break;

            case EnumType.Int32:
                Value = new VariantPrimitive <Int32>(Int32.Parse(value));
                break;

            case EnumType.UInt32:
                Value = new VariantPrimitive <UInt32>(UInt32.Parse(value));
                break;

            case EnumType.Int64:
                Value = new VariantPrimitive <Int64>(Int64.Parse(value));
                break;

            case EnumType.UInt64:
                Value = new VariantPrimitive <UInt64>(UInt64.Parse(value));
                break;

            case EnumType.Float:
                Value = new VariantPrimitive <float>(ParseSingle(value));
                break;

            case EnumType.Double:
                Value = new VariantPrimitive <double>(ParseDouble(value));
                break;

            case EnumType.DateTime:
                Value = new VariantPrimitive <DateTime>(ParseDateTime(value));
                break;

            case EnumType.Time:
                Value = new VariantPrimitive <TimeSpan>(ParseTime(value));
                break;

            default:
                throw new VariantException(string.Format("Unable to construct variant of type {0} from string", Type));
            }
        }
Beispiel #2
0
 public int CompareTo(IVariantData rhs)
 {
     IVariantObject rhsObj = ((VariantObjectData)rhs).Value;
     if (Value.Class != rhsObj.Class)
     {
         return Value.Class.CompareTo(rhsObj.Class);
     }
     if (Value.Version != rhsObj.Version)
     {
         return Value.Version.CompareTo(rhsObj.Version);
     }
     return Value.Deflate().CompareTo(rhsObj.Deflate());
 }
Beispiel #3
0
        public int CompareTo(IVariantData rhs)
        {
            IVariantObject rhsObj = ((VariantObjectData)rhs).Value;

            if (Value.Class != rhsObj.Class)
            {
                return(Value.Class.CompareTo(rhsObj.Class));
            }
            if (Value.Version != rhsObj.Version)
            {
                return(Value.Version.CompareTo(rhsObj.Version));
            }
            return(Value.Deflate().CompareTo(rhsObj.Deflate()));
        }
 public int CompareTo(IVariantData rhs)
 {
     VariantExceptionInfo rhsEx = (VariantExceptionInfo)rhs;
     if (Class != rhsEx.Class)
     {
         return Class.CompareTo(rhsEx.Class);
     }
     if (Message != rhsEx.Message)
     {
         return Message.CompareTo(rhsEx.Message);
     }
     if (Source != rhsEx.Source)
     {
         return Source.CompareTo(rhsEx.Source);
     }
     return Stack.CompareTo(rhsEx.Stack);
 }
Beispiel #5
0
        public int CompareTo(IVariantData rhs)
        {
            VariantExceptionInfo rhsEx = (VariantExceptionInfo)rhs;

            if (Class != rhsEx.Class)
            {
                return(Class.CompareTo(rhsEx.Class));
            }
            if (Message != rhsEx.Message)
            {
                return(Message.CompareTo(rhsEx.Message));
            }
            if (Source != rhsEx.Source)
            {
                return(Source.CompareTo(rhsEx.Source));
            }
            return(Stack.CompareTo(rhsEx.Stack));
        }
Beispiel #6
0
 public int CompareTo(IVariantData rhs)
 {
     return(Value.CompareTo(((VariantPrimitive <T>)rhs).Value));
 }
Beispiel #7
0
 public int CompareTo(IVariantData rhs)
 {
     return(Value.CompareTo(((VariantAny)rhs).Value));
 }
Beispiel #8
0
 public int CompareTo(IVariantData rhs)
 {
     return(SequenceComparer.Compare(Value, ((VariantBuffer)rhs).Value));
 }
Beispiel #9
0
 public int CompareTo(IVariantData rhs)
 {
     return(0);
 }
Beispiel #10
0
        protected VariantBase(VariantBase rhs)
        {
            EnumType type = rhs.Type;

            switch (type)
            {
            case EnumType.None:
                Value = new VariantNone();
                break;

            case EnumType.Boolean:
                Value = new VariantPrimitive <bool>(rhs.Value as VariantPrimitive <bool>);
                break;

            case EnumType.Double:
                Value = new VariantPrimitive <double>(rhs.Value as VariantPrimitive <double>);
                break;

            case EnumType.Int32:
                Value = new VariantPrimitive <Int32>(rhs.Value as VariantPrimitive <Int32>);
                break;

            case EnumType.UInt32:
                Value = new VariantPrimitive <UInt32>(rhs.Value as VariantPrimitive <UInt32>);
                break;

            case EnumType.Int64:
                Value = new VariantPrimitive <Int64>(rhs.Value as VariantPrimitive <Int64>);
                break;

            case EnumType.UInt64:
                Value = new VariantPrimitive <UInt64>(rhs.Value as VariantPrimitive <UInt64>);
                break;

            case EnumType.DateTime:
                Value = new VariantPrimitive <DateTime>(rhs.Value as VariantPrimitive <DateTime>);
                break;

            case EnumType.Time:
                Value = new VariantPrimitive <TimeSpan>(rhs.Value as VariantPrimitive <TimeSpan>);
                break;

            case EnumType.String:
                Value = new VariantPrimitive <String>(rhs.Value as VariantPrimitive <String>);
                break;

            case EnumType.Any:
                Value = new VariantAny(rhs.Value as VariantAny);
                break;

            case EnumType.List:
                Value = new VariantList(rhs.Value as VariantList);
                break;

            case EnumType.Dictionary:
                Value = new VariantDictionary(rhs.Value as VariantDictionary);
                break;

            case EnumType.Bag:
                Value = new VariantBag(rhs.Value as VariantBag);
                break;

            case EnumType.TimeSeries:
                Value = new VariantTimeSeries(rhs.Value as VariantTimeSeries);
                break;

            case EnumType.Tuple:
                Value = new VariantTuple(rhs.Value as VariantTuple);
                break;

            case EnumType.Buffer:
                Value = new VariantBuffer(rhs.Value as VariantBuffer);
                break;

            case EnumType.Exception:
                Value = new VariantExceptionInfo(rhs.Value as VariantExceptionInfo);
                break;

            default:
                throw new VariantException("Cannot copy variant of type: " + type.ToString());
            }
        }
Beispiel #11
0
        public int CompareTo(IVariantData value)
        {
            TypedArray rhsValue = ((TypedArray)value);

            if (Value.Length != rhsValue.Value.Length)
            {
                return Value.Length.CompareTo(rhsValue.Value.Length);
            }
            else if (ElementType != rhsValue.ElementType)
            {
                return ElementType.CompareTo(rhsValue.ElementType);
            }
            else
            {
                CompareDelegate comparer = null;

                switch (ElementType)
                {
                    case VariantBase.EnumType.Float:
                        comparer = delegate(object lhs, object rhs) { return ((float)lhs).CompareTo((float)rhs); };
                        break;
                    case VariantBase.EnumType.Double:
                        comparer = delegate(object lhs, object rhs) { return ((double)lhs).CompareTo((double)rhs); };
                        break;
                    case VariantBase.EnumType.Boolean:
                        comparer = delegate(object lhs, object rhs) { return ((bool)lhs).CompareTo((bool)rhs); };
                        break;
                    case VariantBase.EnumType.String:
                        comparer = delegate(object lhs, object rhs) { return ((string)lhs).CompareTo((string)rhs); };
                        break;
                    case VariantBase.EnumType.Int32:
                        comparer = delegate(object lhs, object rhs) { return ((Int32)lhs).CompareTo((Int32)rhs); };
                        break;
                    case VariantBase.EnumType.UInt32:
                        comparer = delegate(object lhs, object rhs) { return ((UInt32)lhs).CompareTo((UInt32)rhs); };
                        break;
                    case VariantBase.EnumType.Int64:
                        comparer = delegate(object lhs, object rhs) { return ((Int64)lhs).CompareTo((Int64)rhs); };
                        break;
                    case VariantBase.EnumType.UInt64:
                        comparer = delegate(object lhs, object rhs) { return ((UInt64)lhs).CompareTo((UInt64)rhs); };
                        break;
                    case VariantBase.EnumType.Time:
                        comparer = delegate(object lhs, object rhs) { return ((TimeSpan)lhs).CompareTo((TimeSpan)rhs); };
                        break;
                    case VariantBase.EnumType.DateTime:
                        comparer = delegate(object lhs, object rhs) { return ((DateTime)lhs).CompareTo((DateTime)rhs); };
                        break;
                    default:
                        throw new VariantException("Case exhaustion: " + ElementType);
                }

                for (int i = 0; i < Value.Length; ++i)
                {
                    int cmp = comparer(Value[i], rhsValue.Value[i]);
                    if (cmp != 0)
                    {
                        return cmp;
                    }
                }
            }
            return 0;
        }
Beispiel #12
0
        public int CompareTo(IVariantData value)
        {
            TypedArray rhsValue = ((TypedArray)value);

            if (Value.Length != rhsValue.Value.Length)
            {
                return(Value.Length.CompareTo(rhsValue.Value.Length));
            }
            else if (ElementType != rhsValue.ElementType)
            {
                return(ElementType.CompareTo(rhsValue.ElementType));
            }
            else
            {
                CompareDelegate comparer = null;

                switch (ElementType)
                {
                case VariantBase.EnumType.Float:
                    comparer = delegate(object lhs, object rhs) { return(((float)lhs).CompareTo((float)rhs)); };
                    break;

                case VariantBase.EnumType.Double:
                    comparer = delegate(object lhs, object rhs) { return(((double)lhs).CompareTo((double)rhs)); };
                    break;

                case VariantBase.EnumType.Boolean:
                    comparer = delegate(object lhs, object rhs) { return(((bool)lhs).CompareTo((bool)rhs)); };
                    break;

                case VariantBase.EnumType.String:
                    comparer = delegate(object lhs, object rhs) { return(((string)lhs).CompareTo((string)rhs)); };
                    break;

                case VariantBase.EnumType.Int32:
                    comparer = delegate(object lhs, object rhs) { return(((Int32)lhs).CompareTo((Int32)rhs)); };
                    break;

                case VariantBase.EnumType.UInt32:
                    comparer = delegate(object lhs, object rhs) { return(((UInt32)lhs).CompareTo((UInt32)rhs)); };
                    break;

                case VariantBase.EnumType.Int64:
                    comparer = delegate(object lhs, object rhs) { return(((Int64)lhs).CompareTo((Int64)rhs)); };
                    break;

                case VariantBase.EnumType.UInt64:
                    comparer = delegate(object lhs, object rhs) { return(((UInt64)lhs).CompareTo((UInt64)rhs)); };
                    break;

                case VariantBase.EnumType.Time:
                    comparer = delegate(object lhs, object rhs) { return(((TimeSpan)lhs).CompareTo((TimeSpan)rhs)); };
                    break;

                case VariantBase.EnumType.DateTime:
                    comparer = delegate(object lhs, object rhs) { return(((DateTime)lhs).CompareTo((DateTime)rhs)); };
                    break;

                default:
                    throw new VariantException("Case exhaustion: " + ElementType);
                }

                for (int i = 0; i < Value.Length; ++i)
                {
                    int cmp = comparer(Value[i], rhsValue.Value[i]);
                    if (cmp != 0)
                    {
                        return(cmp);
                    }
                }
            }
            return(0);
        }
Beispiel #13
0
 protected VariantBase()
 {
     Value = new VariantNone();
 }
Beispiel #14
0
        public int CompareTo(IVariantData value)
        {
            #if !DISABLE_DATATABLE
            DataTable rhsValue = ((VariantDataTable)value).Value;

            if (Value.Columns.Count != rhsValue.Columns.Count)
            {
                return Value.Columns.Count.CompareTo(rhsValue.Columns.Count);
            }
            else if (Value.Rows.Count != rhsValue.Rows.Count)
            {
                return Value.Rows.Count.CompareTo(rhsValue.Rows.Count);
            }
            else
            {
                CompareDelegate[] comparers = new CompareDelegate[Value.Columns.Count];

                for (int i = 0; i < Value.Columns.Count; ++i)
                {
                    if (Value.Columns[i].ColumnName != rhsValue.Columns[i].ColumnName)
                    {
                        return Value.Columns[i].ColumnName.CompareTo(rhsValue.Columns[i].ColumnName);
                    }
                    else
                    {
                        Variant.EnumType lhsType = VariantPrimitiveBase.TypeToEnum(Value.Columns[i].DataType);
                        Variant.EnumType rhsType = VariantPrimitiveBase.TypeToEnum(rhsValue.Columns[i].DataType);

                        if (lhsType != rhsType)
                        {
                            return lhsType.CompareTo(rhsType);
                        }
                        else
                        {
                            switch(lhsType)
                            {
                                case VariantBase.EnumType.Float:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((float)lhs).CompareTo((float)rhs); };
                                    break;
                                case VariantBase.EnumType.Double:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((double)lhs).CompareTo((double)rhs); };
                                    break;
                                case VariantBase.EnumType.Boolean:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((bool)lhs).CompareTo((bool)rhs); };
                                    break;
                                case VariantBase.EnumType.String:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((string)lhs).CompareTo((string)rhs); };
                                    break;
                                case VariantBase.EnumType.Int32:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((Int32)lhs).CompareTo((Int32)rhs); };
                                    break;
                                case VariantBase.EnumType.UInt32:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((UInt32)lhs).CompareTo((UInt32)rhs); };
                                    break;
                                case VariantBase.EnumType.Int64:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((Int64)lhs).CompareTo((Int64)rhs); };
                                    break;
                                case VariantBase.EnumType.UInt64:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((UInt64)lhs).CompareTo((UInt64)rhs); };
                                    break;
                                case VariantBase.EnumType.Time:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((TimeSpan)lhs).CompareTo((TimeSpan)rhs); };
                                    break;
                                case VariantBase.EnumType.DateTime:
                                    comparers[i] = delegate(object lhs, object rhs) { return ((DateTime)lhs).CompareTo((DateTime)rhs); };
                                    break;
                                default:
                                    throw new VariantException("Case exhaustion: " + lhsType);
                            }
                        }
                    }
                }

                for (int i = 0; i < Value.Rows.Count; ++i)
                {
                    DataRow lhsRow = Value.Rows[i];
                    DataRow rhsRow = rhsValue.Rows[i];
                    for (int j = 0; j < Value.Columns.Count; ++j)
                    {
                        int cmp = comparers[j](lhsRow[j], rhsRow[j]);
                        if (cmp != 0)
                        {
                            return cmp;
                        }
                    }
                }

                return 0;

            }
            #else
            throw new NotSupportedException("Datatables are not supported on this platform.");
            #endif
        }
Beispiel #15
0
 public int CompareTo(IVariantData rhs)
 {
     return(SequenceComparer.Compare(Value, ((VariantBag)rhs).Value, new KeyValuePairComparer <string, Variant>()));
 }
Beispiel #16
0
 public int CompareTo(IVariantData rhs)
 {
     return(Value.Compare(((VariantDictionary)rhs).Value, new KeyValuePairComparer <string, Variant>()));
 }
Beispiel #17
0
 public int CompareTo(IVariantData rhs)
 {
     return(SequenceComparer.Compare(Value, ((VariantTimeSeries)rhs).Value, new KeyValuePairComparer <DateTime, Variant>()));
 }
Beispiel #18
0
        public int CompareTo(IVariantData value)
        {
#if !DISABLE_DATATABLE
            DataTable rhsValue = ((VariantDataTable)value).Value;

            if (Value.Columns.Count != rhsValue.Columns.Count)
            {
                return(Value.Columns.Count.CompareTo(rhsValue.Columns.Count));
            }
            else if (Value.Rows.Count != rhsValue.Rows.Count)
            {
                return(Value.Rows.Count.CompareTo(rhsValue.Rows.Count));
            }
            else
            {
                CompareDelegate[] comparers = new CompareDelegate[Value.Columns.Count];

                for (int i = 0; i < Value.Columns.Count; ++i)
                {
                    if (Value.Columns[i].ColumnName != rhsValue.Columns[i].ColumnName)
                    {
                        return(Value.Columns[i].ColumnName.CompareTo(rhsValue.Columns[i].ColumnName));
                    }
                    else
                    {
                        Variant.EnumType lhsType = VariantPrimitiveBase.TypeToEnum(Value.Columns[i].DataType);
                        Variant.EnumType rhsType = VariantPrimitiveBase.TypeToEnum(rhsValue.Columns[i].DataType);

                        if (lhsType != rhsType)
                        {
                            return(lhsType.CompareTo(rhsType));
                        }
                        else
                        {
                            switch (lhsType)
                            {
                            case VariantBase.EnumType.Float:
                                comparers[i] = delegate(object lhs, object rhs) { return(((float)lhs).CompareTo((float)rhs)); };
                                break;

                            case VariantBase.EnumType.Double:
                                comparers[i] = delegate(object lhs, object rhs) { return(((double)lhs).CompareTo((double)rhs)); };
                                break;

                            case VariantBase.EnumType.Boolean:
                                comparers[i] = delegate(object lhs, object rhs) { return(((bool)lhs).CompareTo((bool)rhs)); };
                                break;

                            case VariantBase.EnumType.String:
                                comparers[i] = delegate(object lhs, object rhs) { return(((string)lhs).CompareTo((string)rhs)); };
                                break;

                            case VariantBase.EnumType.Int32:
                                comparers[i] = delegate(object lhs, object rhs) { return(((Int32)lhs).CompareTo((Int32)rhs)); };
                                break;

                            case VariantBase.EnumType.UInt32:
                                comparers[i] = delegate(object lhs, object rhs) { return(((UInt32)lhs).CompareTo((UInt32)rhs)); };
                                break;

                            case VariantBase.EnumType.Int64:
                                comparers[i] = delegate(object lhs, object rhs) { return(((Int64)lhs).CompareTo((Int64)rhs)); };
                                break;

                            case VariantBase.EnumType.UInt64:
                                comparers[i] = delegate(object lhs, object rhs) { return(((UInt64)lhs).CompareTo((UInt64)rhs)); };
                                break;

                            case VariantBase.EnumType.Time:
                                comparers[i] = delegate(object lhs, object rhs) { return(((TimeSpan)lhs).CompareTo((TimeSpan)rhs)); };
                                break;

                            case VariantBase.EnumType.DateTime:
                                comparers[i] = delegate(object lhs, object rhs) { return(((DateTime)lhs).CompareTo((DateTime)rhs)); };
                                break;

                            default:
                                throw new VariantException("Case exhaustion: " + lhsType);
                            }
                        }
                    }
                }

                for (int i = 0; i < Value.Rows.Count; ++i)
                {
                    DataRow lhsRow = Value.Rows[i];
                    DataRow rhsRow = rhsValue.Rows[i];
                    for (int j = 0; j < Value.Columns.Count; ++j)
                    {
                        int cmp = comparers[j](lhsRow[j], rhsRow[j]);
                        if (cmp != 0)
                        {
                            return(cmp);
                        }
                    }
                }

                return(0);
            }
#else
            throw new NotSupportedException("Datatables are not supported on this platform.");
#endif
        }
Beispiel #19
0
        protected VariantBase(EnumType type, int size)
        {
            switch (type)
            {
            case EnumType.None:
                Value = new VariantNone();
                break;

            case EnumType.Any:
                Value = new VariantAny();
                break;

            case EnumType.Boolean:
                Value = new VariantPrimitive <bool>(false);
                break;

            case EnumType.Int32:
                Value = new VariantPrimitive <Int32>(0);
                break;

            case EnumType.UInt32:
                Value = new VariantPrimitive <UInt32>(0);
                break;

            case EnumType.Int64:
                Value = new VariantPrimitive <Int64>(0);
                break;

            case EnumType.UInt64:
                Value = new VariantPrimitive <UInt64>(0);
                break;

            case EnumType.String:
                Value = new VariantPrimitive <String>("");
                break;

            case EnumType.DateTime:
                Value = new VariantPrimitive <DateTime>(new DateTime());
                break;

            case EnumType.Time:
                Value = new VariantPrimitive <TimeSpan>(new TimeSpan());
                break;

            case EnumType.List:
                Value = new VariantList(size);
                break;

            case EnumType.TimeSeries:
                Value = new VariantTimeSeries(size);
                break;

            case EnumType.Dictionary:
                Value = new VariantDictionary();
                break;

            case EnumType.Bag:
                Value = new VariantBag();
                break;

            case EnumType.Tuple:
                Value = new VariantTuple(size);
                break;

            case EnumType.Buffer:
                Value = new VariantBuffer(size);
                break;

            default:
                throw new VariantException("Cannot default construct variant of type: " + type.ToString());
            }
        }