Example #1
0
        /// <summary>
        ///     Initializes a new instance of the QTable with specified column names and data matrix.
        /// </summary>
        public QTable(string[] columns, Array data)
        {
            if (columns == null || columns.Length == 0)
            {
                throw new ArgumentException("Columns array cannot be null or 0-length");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data matrix cannot be null or 0-length");
            }

            if (columns.Length != data.Length)
            {
                throw new ArgumentException("Columns array and data matrix cannot have different length");
            }

            if (data.Cast<object>().Any(col => !col.GetType().IsArray))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            columnsMap = new ListDictionary();
            for (int i = 0; i < columns.Length; i++)
            {
                columnsMap[columns[i]] = i;
            }

            this.columns = columns;
            this.data = data;
            RowsCount = ((Array)data.GetValue(0)).Length;
        }
        public string FormatParameter(string name, Array values, Func<object, string> valueFormatter)
        {
            var items = string.Join(",", values.Cast<object>()
                .Select(valueFormatter));

            return string.Concat(name, "=", items);
        }
Example #3
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="values">Values to include in the collection</param>
 public StandardValuesConverter(Array values)
 {
     if (values == null)
         throw new ArgumentNullException("values");
     m_values = new StandardValuesCollection(values);
     
     // Check if all items are exclusive using a hash set
     var set = new HashSet<object>();
     m_exclusive = values.Cast<object>().All(set.Add); 
 }
        public override void AddRange(Array values)
        {
            var paramaters = values.Cast<CrmParameter>().ToList();
            bool canAdd = paramaters.Aggregate(true, (current, crmParameter) => current && crmParameter.CanAddToCommand());

            if (canAdd)
            {
                _Params.AddRange(paramaters);
            }
            else
            {
                throw new ArgumentException("one or more of the parameters in the array are not valid to add to a command. Are they all named?");
            }
        }
Example #5
0
 public static byte[] GetBytes(Array array, Encoding encoding)
 {
     if (array == null)
         return null;
     var bytes = array as byte[];
     if (bytes != null)
         return bytes;
     var objects = array.Cast<object>();
     var first = objects.FirstOrDefault();
     if (first.GetBaseObject().GetType().IsPrimitive) {
         return objects.Select(item => Convert.ToByte(item.GetBaseObject())).ToArray();
     } else {
         var text = new StringBuilder();
         foreach (var entry in array) {
             if (text.Length > 0)
                 text.AppendLine();
             var item = entry.GetBaseObject();
             if (item != null)
                 text.Append(item);
         }
         return encoding.GetBytes(text.ToString());
     }
 }
 public override void AddRange(Array values) => Add(values.Cast<SqliteParameter>());
 public static TagException InvalidValueException(object value, Array possibleValues)
 {
     return new TagException($"Value '{value}' is not allowed. Possible values are: {string.Join(", ", possibleValues.Cast<object>().Select(v => v.ToString()))}");
 }
		public override void AddRange(Array values)
		{
			AddRange(values.Cast<object>().Select(x => { EnsureFbParameterType(x); return (FbParameter)x; }));
		}
 public override void AddRange(Array values)
 {
     this.inner.AddRange(values.Cast<MockDbParameter>());
 }
 /// <summary>
 /// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing. </param><param name="index">The zero-based index in <paramref name="array"/> at which copying begins. </param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null. </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than zero. </exception><exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>. </exception><exception cref="T:System.ArgumentException">The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>. </exception>
 public void CopyTo(Array array,
                    int index)
 {
     this.resultPropertyValueCollection.CopyTo(array.Cast<object>().ToArray(), index);
 }
Example #11
0
 private static SObject TranslateArray(ScriptProcessor processor, Array array) =>
     processor.CreateArray(array.Cast<object>().Select((t, i) =>
             Translate(processor, array.GetValue(i))).ToArray());
        public void UpdateResults(Array results) {
            results = results.Cast<object>().Take(50).ToArray();

            ResultView.ItemsSource = results;
            if (results.Length == 0) {
                ResultView.Visibility = Visibility.Collapsed;
                NoResults.Visibility = Visibility.Visible;
            } else {
                ResultView.Visibility = Visibility.Visible;
                NoResults.Visibility = Visibility.Collapsed;
            }
        }
Example #13
0
 private static bool ArraysEqual(Array array1, Array array2)
 {
     if (array1.Length != array2.Length)
     {
         return false;
     }
     return !array1.Cast<object>().Where((t, i) => !AreEqual(array1.GetValue(i), array2.GetValue(i))).Any();
 }
        /// <summary>
        /// Adds an array of items with the specified values to the <see cref="T:System.Data.Common.DbParameterCollection"/>.
        /// </summary>
        /// <param name="values">An array of values of type <see cref="T:System.Data.Common.DbParameter"/> to add to the collection.
        ///                 </param><filterpriority>2</filterpriority>
        public override void AddRange(Array values)
        {
            if (values == null) throw new ArgumentNullException("values");

            InnerList.AddRange(values.Cast<TableStorageParameter>());
        }
		public override void AddRange(Array values)
		{
			this.AddRange(values.Cast<FbParameter>());
		}
 public void Listing(ref Array entryIds, int length, int total, ref bool cancel)
 {
     // uuuugh
     EntryIds.AddRange(entryIds.Cast<string>());
 }
Example #17
0
        /// <summary>
        /// Shuffles the entries in an array into a new random order.
        /// <code>FlxG.shuffle()</code> is deterministic and safe for use with replays/recordings.
        /// HOWEVER, <code>FlxU.shuffle()</code> is NOT deterministic and unsafe for use with replays/recordings.
        /// </summary>
        /// <param name="objects">A Flash <code>Array</code> object containing...stuff.</param>
        /// <param name="howManyTimes">How many swaps to perform during the shuffle operation.  Good rule of thumb is 2-4 times as many objects are in the list.</param>
        /// <returns>The same Flash <code>Array</code> object that you passed in in the first place.</returns>
        public static Array shuffle(Array objects, uint howManyTimes)
        {
            var shuffleList = objects.Cast<object>().ToList();

            for (uint i = 0; i < howManyTimes; ++i)
            {
                // this is awesome sexy ^^
                // http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
                shuffleList = shuffleList.OrderBy(item => Guid.NewGuid()).ToList();
            }

            return shuffleList.ToArray();
        }
Example #18
0
        /// <summary>
        ///     Initializes a new instance of the QKeyedTable with specified column names and data matrix.
        /// </summary>
        public QKeyedTable(string[] columns, string[] keyColumns, Array data)
        {
            if (columns == null || columns.Length == 0)
            {
                throw new ArgumentException("Columns array cannot be null or 0-length");
            }

            if (keyColumns == null || keyColumns.Length == 0)
            {
                throw new ArgumentException("Key columns array cannot be null or 0-length");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data matrix cannot be null or 0-length");
            }

            if (columns.Length != data.Length)
            {
                throw new ArgumentException("Columns array and data matrix cannot have different length");
            }

            if (data.Cast<object>().Any(col => !col.GetType().IsArray))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            if (keyColumns.Any(keyCol => !columns.Contains(keyCol)))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            var keyIndices = new SortedSet<int>();
            for (int i = 0; i < columns.Length; i++)
            {
                if (keyColumns.Contains(columns[i]))
                {
                    keyIndices.Add(i);
                }
            }

            var keyArrays = new object[keyIndices.Count];
            var keyHeaders = new string[keyIndices.Count];
            var dataArrays = new object[data.Length - keyIndices.Count];
            var dataHeaders = new string[data.Length - keyIndices.Count];

            int ki = 0;
            int di = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (keyIndices.Contains(i))
                {
                    keyHeaders[ki] = columns[i];
                    keyArrays[ki++] = data.GetValue(i);
                }
                else
                {
                    dataHeaders[di] = columns[i];
                    dataArrays[di++] = data.GetValue(i);
                }
            }

            keys = new QTable(keyHeaders, keyArrays);
            values = new QTable(dataHeaders, dataArrays);
        }
 public void CopyTo(Array array, int index)
 {
     this.CopyTo(array.Cast<ManagedWinapi.Hotkey>().ToArray(), index);
 }
 private static void AssertArray(string errorMessage, Array expected, Func<object> readOne)
 {
     var actual = Enumerable.Range(0, expected.Length).Select(i => readOne()).ToArray();
     if (!Enumerable.SequenceEqual(expected.Cast<object>(), actual))
         throw new InvalidDataException(string.Format("{0} ({1} expected; was {2})", errorMessage, string.Join(", ", expected.Cast<object>()), string.Join(", ", actual)));
 }