本文整理汇总了C#中IEnumerable.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Cast方法的具体用法?C# IEnumerable.Cast怎么用?C# IEnumerable.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyExpression
protected PropertyExpression(object obj, IEnumerable<PropertyExpressionPart> parts)
{
if (obj == null)
throw new ArgumentNullException("obj");
if (parts == null)
throw new ArgumentNullException("parts");
/*foreach (object item in parts)
{
if (item == null)
{
throw new ArgumentException("An item inside the enumeration was null.", "parts");
}
}*/
if (parts.Cast<object>().Any(item => item == null))
{
throw new ArgumentException(Resources.AnItemWasNull, "parts");
}
_parts = new List<PropertyExpressionPart>(parts);
if (_parts.Count == 0)
throw new ArgumentException(Resources.OnePartRequired, "parts");
_finalPart = _parts.Last();
//whenever the final part's value changes, that means the value of the expression as a whole has changed
_finalPart.ValueChanged += delegate
{
OnValueChanged();
};
//assign the initial object in the potential chain of objects resolved by the expression parts
_parts[0].Object = obj;
}
示例2: CollectionView
public CollectionView(IEnumerable collection)
{
if (collection == null)
{
throw new ArgumentNullException("collection");
}
this.sourceCollection = collection;
if (collection.Cast<object>().Any())
{
this.currentItem = collection.Cast<object>().First();
this.currentPosition = 0;
}
else
{
this.currentPosition = -1;
this.IsCurrentAfterLast = this.IsCurrentBeforeFirst = true;
}
INotifyCollectionChanged incc = collection as INotifyCollectionChanged;
if (incc != null)
{
incc.CollectionChanged += this.OnCollectionChanged;
}
}
示例3: Convert
public IDbCommandResult Convert(IEnumerable values)
{
if (values.IsEmpty())
{
return new QueryResult();
}
var type = values.GetTypeOfValues();
if (type.IsValueType || type == typeof(string))
{
return QueryResultOfValues(values, type);
}
if (type == typeof(DynamicRecord))
{
return QueryResultOfDynamicRecord(values.Cast<DynamicRecord>());
}
if (type == typeof(DynamicDataRow))
{
return QueryResultOfDynamicDataRow(values.Cast<DynamicDataRow>());
}
if (type.IsAssignableFrom(typeof(IDictionary)))
{
return QueryResultOfDictionary((IEnumerable<IDictionary>)values);
}
return QueryResultOfType(values, type);
}
示例4: SelectIndividualGlyphsOrPassBoxComposition
private static IList SelectIndividualGlyphsOrPassBoxComposition(IEnumerable boxElements)
{
if (boxElements == null)
return null;
Contract.RequiresForAll(boxElements.Cast<object>(), element => element is IBoxElement);
return boxElements.Cast<object>().VirtualSelectMany<object, BoxCompositionViewModel, GlyphRunViewModel, object>(bc => bc.ToSingleton(), glyphRun => glyphRun).ToList();
}
示例5: CreateColumn
public static IColumn CreateColumn(Type dataType, IEnumerable<object> data)
{
if (new[]{typeof(Int64), typeof(Int32), typeof(Int16), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(int)}.Contains(dataType))
return new Column<Int64>( data.Cast<Int64>() );
if (dataType == typeof (DateTime))
return new Column<DateTime>(data.Cast<DateTime>());
if (dataType == typeof (Double))
return new Column<Double>(data.Cast<Double>());
return new Column<String>(data.Cast<String>());
}
示例6: Perform
public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems)
{
IEnumerable<Wnck.Window> windows = null;
if (items.First () is IWindowItem)
windows = items.Cast<IWindowItem> ().SelectMany (wi => wi.Windows);
else if (items.First () is IApplicationItem)
windows = items.Cast<IApplicationItem> ().SelectMany (a => WindowUtils.WindowListForCmd (a.Exec));
if (windows != null)
Action (windows);
return null;
}
示例7: AddIrtCalculatorDlg
public AddIrtCalculatorDlg(IEnumerable<RCalcIrt> calculators)
{
InitializeComponent();
comboLibrary.Items.AddRange(calculators.Cast<object>().ToArray());
ComboHelper.AutoSizeDropDown(comboLibrary);
}
示例8: BulkDeleteOperationArgs
// constructors
public BulkDeleteOperationArgs(
string collectionName,
string databaseName,
int maxBatchCount,
int maxBatchLength,
int maxDocumentSize,
int maxWireDocumentSize,
bool isOrdered,
BsonBinaryReaderSettings readerSettings,
IEnumerable<DeleteRequest> requests,
WriteConcern writeConcern,
BsonBinaryWriterSettings writerSettings)
: base(
collectionName,
databaseName,
maxBatchCount,
maxBatchLength,
maxDocumentSize,
maxWireDocumentSize,
isOrdered,
readerSettings,
requests.Cast<WriteRequest>(),
writeConcern,
writerSettings)
{
}
示例9: Perform
public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modifierItems)
{
string search_text;
search_text = (items.First () as ITextItem).Text;
return GCal.SearchEvents (modifierItems.Cast<GCalendarItem> (), search_text).Cast<Item> ();
}
示例10: HasSameItemsRegardlessOfSortOrder
public static bool HasSameItemsRegardlessOfSortOrder(this IEnumerable left, IEnumerable right)
{
var leftCollection = left.Cast<object>().ToList();
var rightCollection = right.Cast<object>().ToList();
return leftCollection.Except(rightCollection).Count() == 0;
}
示例11: Shuffle
public List<int> Shuffle(IEnumerable<int> cards)
{
int[] castedArray = cards.Cast<int>().ToArray();
int[] arr = ShuffleMethod(castedArray);
var list = new List<int>(arr);
return (list);
}
示例12: CreateMultiResolutionImage
public override object CreateMultiResolutionImage (IEnumerable<object> images)
{
var refImg = (GtkImage) images.First ();
var f = refImg.Frames [0];
var frames = images.Cast<GtkImage> ().Select (img => new GtkImage.ImageFrame (img.Frames[0].Pixbuf, f.Width, f.Height, true));
return new GtkImage (frames);
}
示例13: Assembly
public Assembly(string name, IEnumerable<Concern> concerns) : base(concerns.Cast<SpecificationContainer>())
{
_name = name;
_concerns = concerns.OrderBy(x => x.Name).ToList();
_totalConerns = concerns.Count();
_totalContexts = concerns.Sum(x => x.TotalContexts);
}
示例14: BulkInsertOperationArgs
// constructors
public BulkInsertOperationArgs(
Action<InsertRequest> assignId,
bool checkElementNames,
string collectionName,
string databaseName,
int maxBatchCount,
int maxBatchLength,
int maxDocumentSize,
int maxWireDocumentSize,
bool isOrdered,
BsonBinaryReaderSettings readerSettings,
IEnumerable<InsertRequest> requests,
WriteConcern writeConcern,
BsonBinaryWriterSettings writerSettings)
: base(
collectionName,
databaseName,
maxBatchCount,
maxBatchLength,
maxDocumentSize,
maxWireDocumentSize,
isOrdered,
readerSettings,
requests.Cast<WriteRequest>(),
writeConcern,
writerSettings)
{
_assignId = assignId;
_checkElementNames = checkElementNames;
}
示例15: createReferenceMembers
void createReferenceMembers(IEnumerable<IExtendedMemberInfo> xpCollection){
XPDictionary xpDictionary = XafTypesInfo.XpoTypeInfoSource.XPDictionary;
foreach (var info in xpCollection.Cast<IExtendedReferenceMemberInfo>()){
XPCustomMemberInfo member = xpDictionary.GetClassInfo(info.Owner).CreateMember(info.Name, info.ReferenceType);
createAttributes(info, member);
}
}