本文整理汇总了C#中System.Array.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Array.Cast方法的具体用法?C# Array.Cast怎么用?C# Array.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QTable
/// <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;
}
示例2: FormatParameter
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);
}
示例3: StandardValuesConverter
/// <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);
}
示例4: AddRange
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?");
}
}
示例5: GetBytes
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());
}
}
示例6: AddRange
public override void AddRange(Array values) => Add(values.Cast<SqliteParameter>());
示例7: InvalidValueException
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()))}");
}
示例8: AddRange
public override void AddRange(Array values)
{
AddRange(values.Cast<object>().Select(x => { EnsureFbParameterType(x); return (FbParameter)x; }));
}
示例9: AddRange
public override void AddRange(Array values)
{
this.inner.AddRange(values.Cast<MockDbParameter>());
}
示例10: CopyTo
/// <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);
}
示例11: TranslateArray
private static SObject TranslateArray(ScriptProcessor processor, Array array) =>
processor.CreateArray(array.Cast<object>().Select((t, i) =>
Translate(processor, array.GetValue(i))).ToArray());
示例12: UpdateResults
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;
}
}
示例13: ArraysEqual
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();
}
示例14: AddRange
/// <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>());
}
开发者ID:yvesgoeleven,项目名称:NHibernate.Windows.Azure.Storage.Driver,代码行数:11,代码来源:TableStorageParameterCollection.cs
示例15: AddRange
public override void AddRange(Array values)
{
this.AddRange(values.Cast<FbParameter>());
}