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); }
/// <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; }
private void RandomQueue() { System.Array values = System.Enum.GetValues(typeof(ClassicalSpawningPool.GroupSize)); foreach (ClassicalSpawningPool.GroupSize current in values.Cast <ClassicalSpawningPool.GroupSize>().Shuffle <ClassicalSpawningPool.GroupSize>()) { this.m_groupsToSpawn.Enqueue(current); } }
void control_DragDrop(object sender, DragEventArgs e) { System.Array ar = e.Data.GetData(DataFormats.FileDrop) as System.Array; if (ar != null && this.DropNotice != null) { DropFileEventArgs dfe = new DropFileEventArgs(ar.Cast <string>()); DropNotice(sender, dfe); } }
/// <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?"); } }
public ActivityPlan(int topicId, ref System.Array inputStrings, ref string validationString) { // Set to new request this.Updated = false; // string[] requestStrings = inputStrings.Cast <string>().ToArray(); // add empty string values to fill out array (let SAP do validation) if (requestStrings.Length < m_totalNumberOfParameters) { List <string> ls = new List <string>(requestStrings); while (ls.Count < 15) { ls.Add(String.Empty); } requestStrings = ls.ToArray(); } this.TopicID = topicId; this.Hash = inputStrings.Concatenate(); //this.FunctionType = FunctionType.; this.FunctionType = (PlanningFunctionType)Enum.Parse(typeof(PlanningFunctionType), requestStrings[0]); this.m_quantity = requestStrings[1].ToUpper(); // [TOT_VALUE][ACTVTY_QTY] this.m_price = requestStrings[2].ToUpper(); // [TOT_VALUE][PRICE_FIX] this.m_controllingArea = requestStrings[3].ToUpper(); // [HEADER_INFO][CO_AREA] this.m_fiscalYear = requestStrings[4].ToUpper(); // [HEADER_INFO][FISC_YEAR] this.m_perFrom = requestStrings[5].ToUpper(); // [HEADER_INFO][PERIOD_FROM] this.m_perTo = requestStrings[6].ToUpper(); // [HEADER_INFO][PERIOD_TO] this.m_distKey = requestStrings[7].ToUpper(); // [TOT_VALUE][DIST_KEY_PRICE_FIX] this.m_version = requestStrings[8].ToUpper(); // [HEADER_INFO][VERSION] this.m_documentTxt = requestStrings[9].ToUpper(); // [HEADER_INFO][DOC_HDR_TX] this.m_currencyType = requestStrings[10].ToUpper(); // [HEADER_INFO][PLAN_CURRTYPE] this.m_delta = requestStrings[11].ToUpper(); // [DELTA][DELTA] this.m_costCenter = requestStrings[12].ToUpper(); // [OBJECT][COSTCENTER] this.m_activityType = requestStrings[13].ToUpper(); // [OBJECT][ACTTYPE] this.m_transactionCurrency = requestStrings[14].ToUpper(); // [TOT_VALUE][CURRENCY] this.Signature = requestStrings[requestStrings.Length - 1].ToUpper(); IPlanningFunction thisFunc = (IPlanningFunction)this; MatManErrorDictionary.GetObject().ValidatePlanningFunction(ref thisFunc, ref validationString); }
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()); } }
/// <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 static Object[] ToObjectArray(this System.Array array) { return(array.Cast <Object>().ToArray()); }
/// <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(); }
public override void AddRange(Array values) { this.AddRange(values.Cast<FbParameter>()); }
/// <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.inner.AddRange(values.Cast<MockDbParameter>()); }
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))); }
public override void AddRange(Array values) { AddRange(values.Cast<object>().Select(x => { EnsureFbParameterType(x); return (FbParameter)x; })); }
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()))}"); }
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(); }
public override void AddRange(Array values) => Add(values.Cast<SqliteParameter>());
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; } }
public static string AsString(this System.Array arr) { // //Contract.Requires<ArgumentNullException>(arr != null, "arr cannot be null"); return(string.Format("{0}{1}{2}", "{", string.Join(",", arr.Cast <object>().ToArray()), "}")); }
private static SObject TranslateArray(ScriptProcessor processor, Array array) => processor.CreateArray(array.Cast<object>().Select((t, i) => Translate(processor, array.GetValue(i))).ToArray());
/// <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); }
public void Listing(ref Array entryIds, int length, int total, ref bool cancel) { // uuuugh EntryIds.AddRange(entryIds.Cast<string>()); }
public void CopyTo(Array array, int index) { this.CopyTo(array.Cast<ManagedWinapi.Hotkey>().ToArray(), index); }
public CostPlan(int topicId, ref System.Array inputStrings, ref string validationString) { // Set to new request this.Updated = false; // string[] requestStrings = inputStrings.Cast <string>().ToArray(); // add empty string values to fill out array (let SAP do validation) if (requestStrings.Length < m_totalNumberOfParameters) { List <string> ls = new List <string>(requestStrings); while (ls.Count < m_totalNumberOfParameters) { ls.Add(String.Empty); } requestStrings = ls.ToArray(); } this.TopicID = topicId; this.Hash = inputStrings.Concatenate(); this.FunctionType = PlanningFunctionType.CostPlan; this.m_fixedInputValue = requestStrings[1].ToUpper(); // [TOTVALUE][FIX_VALUE] this.m_controllingArea = requestStrings[2].ToUpper(); // [HEADERINFO][CO_AREA] this.m_fiscalYear = requestStrings[3].ToUpper(); // [HEADERINFO][FISC_YEAR] this.m_periodFrom = requestStrings[4].ToUpper(); // [HEADERINFO][PERIOD_FROM] this.m_periodTo = requestStrings[5].ToUpper(); // [HEADERINFO][PERIOD_TO] this.m_distributionKey = requestStrings[6].ToUpper(); // [TOTVALUE][DIST_KEY_FIX_VAL] this.m_version = requestStrings[7].ToUpper(); // [HEADERINFO][VERSION] this.m_documentHeaderText = requestStrings[8].ToUpper(); // [HEADERINFO][DOC_HDR_TXT] this.m_planningCurrency = requestStrings[9].ToUpper(); // [HEADERINFO][PLAN_CURRTYPE] this.m_delta = requestStrings[10].ToUpper(); // [DELTA][DELTA] this.m_costCenter = requestStrings[11].ToUpper(); // [COOBJECT][COSTCENTER] this.m_costElement = requestStrings[12].ToUpper(); // [TOTVALUE][COST_ELEM] this.m_activityType = requestStrings[13].ToUpper(); // [COOBJECT][ACTTYPE] this.m_orderID = requestStrings[14].ToUpper(); // [COOBJECT][ORDERID] this.m_wbsElement = requestStrings[15].ToUpper(); // [COOBJECT][WBS_ELEMENT] this.m_functionalArea = requestStrings[16].ToUpper(); // [TOTVALUE][FUNCTION] this.m_fund = requestStrings[17].ToUpper(); // [TOTVALUE][FUND] this.m_grant = requestStrings[18].ToUpper(); // [TOTVALUE][GRANT_NBR] this.m_transactionCurrency = requestStrings[19].ToUpper(); // [TOTVALUE][TRANS_CURR] this.Signature = requestStrings[requestStrings.Length - 1].ToUpper(); if (this.m_functionalArea != string.Empty) { this.m_functionalArea = this.m_functionalArea.TrimStart('0'); this.m_functionalArea = "000" + this.m_functionalArea; } if (this.m_wbsElement != string.Empty) { this.m_wbsElement = this.m_wbsElement.TrimStart(' '); if (this.m_wbsElement.ToUpper().StartsWith("WBS")) { this.m_wbsElement = this.m_wbsElement.Remove(0, 3); } this.m_wbsElement = this.m_wbsElement.TrimStart(' '); } IPlanningFunction thisFunc = (IPlanningFunction)this; MatManErrorDictionary.GetObject().ValidatePlanningFunction(ref thisFunc, ref validationString); }