private static void SetValue <T>(ITuple dummyTuple, ITuple tuple, int fieldIndex, Random random)
        {
            IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>();
            T instance = generator.GetInstance(random);

            dummyTuple.SetValue(fieldIndex, instance);
            tuple.SetValue(fieldIndex, instance);
        }
Пример #2
0
        public static void CopyFrom(this ITuple tuple, IEnumerable list)
        {
            int i = 0;

            foreach (var item in list)
            {
                tuple.SetValue(i, item);
                ++i;
            }
        }
Пример #3
0
        void SetTupleValueAndResetColumnSortingIfNeeded(ITuple tuple, int columnIndex, object newValue)
        {
            var oldValue = tuple.GetValue(columnIndex);

            tuple.SetValue(columnIndex, newValue);

            // Reset column sorting only if needed
            // Using object.Equals to bypass unboxing
            if (!object.Equals(oldValue, newValue))
            {
                SetColumnSorting(columnIndex, TableValueSortType.NONE);
            }
        }
Пример #4
0
        void GetRandomValuesIntoTuple(ITableColumns columnsModel, ITuple tuple, System.Random random)
        {
            for (int i = 0; i < columnsModel.ColumnsCount; i++)
            {
                var randInt    = random.Next();
                var randIntPos = randInt < 0 ? -randInt : randInt;

                object obj = null;
                if (randInt % 10 != 0)                 // objects can also be null
                {
                    var columnState = columnsModel.GetColumnState(i);
                    var type        = columnState.Info.ValueType;
                    var buf8        = new byte[sizeof(double)];
                    switch (type)
                    {
                    case TableValueType.RAW:
                        if (randInt % 2 == 0)
                        {
                            obj = new object();
                        }
                        else
                        {
                            obj = new Vector3((randInt % 4), (randInt % (1 + i)), (randInt % (2 + i)));
                        }
                        break;

                    case TableValueType.STRING:
                        obj = _RandomStrings[randIntPos % _RandomStrings.Length];
                        break;

                    case TableValueType.INT:
                        obj = randInt;
                        break;

                    case TableValueType.LONG_INT:
                        obj = (((long)(randInt) << 32) + (~randInt));
                        break;

                    case TableValueType.FLOAT:
                        obj = randInt / 134325.4134E+23f;
                        break;

                    case TableValueType.DOUBLE:
                        // _Random.NextDouble() is useless because it doesn't produce the entire range of doubles
                        // This also can yield NaN and Infinity, but we want that, for demo purposes
                        random.NextBytes(buf8);
                        obj = BitConverter.ToDouble(buf8, 0);
                        break;

                    case TableValueType.ENUMERATION:
                        var enumType   = columnState.Info.EnumValueType;
                        var enumValues = Enum.GetValues(enumType);
                        obj = enumValues.GetValue(randIntPos % enumValues.Length);
                        break;

                    case TableValueType.BOOL:
                        obj = randInt % 2 == 0;
                        break;

                    case TableValueType.TEXTURE:
                        obj = _SampleTextures[randIntPos % _SampleTextures.Length];
                        break;
                    }
                }
                tuple.SetValue(i, obj);
            }
        }