本文整理汇总了C#中ICollection.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Cast方法的具体用法?C# ICollection.Cast怎么用?C# ICollection.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEquivalent
public static void AreEquivalent(ICollection expected, ICollection actual)
{
if (expected == actual)
{
return;
}
if (expected.Count != actual.Count)
{
throw new AssertFailedException("collections differ in size");
}
var expectedCounts = expected.Cast<object>().GroupBy(e => e).ToDictionary(g => g.Key, g => g.Count());
var actualCounts = actual.Cast<object>().GroupBy(e => e).ToDictionary(g => g.Key, g => g.Count());
foreach (var kvp in expectedCounts)
{
int actualCount = 0;
if (actualCounts.TryGetValue(kvp.Key, out actualCount))
{
if (actualCount != kvp.Value)
{
throw new AssertFailedException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "collections have different count for element {0}", kvp.Key));
}
}
else
{
throw new AssertFailedException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "actual does not contain element {0}", kvp.Key));
}
}
}
示例2: InitializeGUI
public override void InitializeGUI()
{
title.text = GetName().SplitCamelCase();
value = GetValue<ICollection>();
if(value != null)
{
// much boxing
array = value.Cast<object>().ToArray();
if(array.Length < 1 || array.Length > 32)
return;
if(declaringType == null || declaringType.GetElementType() == null)
return;
System.Type elementType = declaringType.GetElementType();
string typeName = elementType.ToString().Substring(elementType.ToString().LastIndexOf('.') + 1);
for(int i = 0; i < array.Length; i++)
{
pb_TypeInspector inspector = pb_InspectorResolver.GetInspector(elementType);
inspector.SetIndexInCollection(i);
inspector.Initialize( typeName,
(int index) => { return array[index]; },
SetValueAtIndex );
inspector.transform.SetParent(collection);
}
}
}
示例3: CollectionsEqual
private static bool CollectionsEqual(ICollection x, ICollection y)
{
return x.Count == y.Count
&& x.Cast<object>().Select((e, i) => new { Expr = e, Index = i })
.Join(y.Cast<object>().Select((e, i) => new { Expr = e, Index = i }),
o => o.Index, o => o.Index, (xe, ye) => new { X = xe.Expr, Y = ye.Expr })
.All(o => Equals(o.X, o.Y));
}
示例4: InsertRange
/// <summary>
/// Overridden
/// </summary>
/// <param name="index"></param>
/// <param name="c"></param>
public override void InsertRange(int index, ICollection c) {
if (c == null) {
throw new ArgumentNullException("c");
}
if (c.Cast<object>().Any(o => !hashSet.Add(o))) {
throw new Exception("It is not expected that a bo is added multiple times");
}
base.InsertRange(index, c);
}
示例5: AppendEventsToStream
public void AppendEventsToStream(IIdentity id, long originalVersion, ICollection<IEvent> events)
{
if (events.Count == 0) return;
// functional events don't have an identity
var name = IdentityToKey(id);
try
{
_store.AppendToStore(name, MessageAttribute.Empty, originalVersion, events.Cast<object>().ToArray());
}
catch (AppendOnlyStoreConcurrencyException e)
{
// load server events
var server = LoadEventStream(id);
// throw a real problem
throw OptimisticConcurrencyException.Create(server.StreamVersion, e.ExpectedStreamVersion, id, server.Events);
}
}
示例6: EqualUnordered
public static void EqualUnordered(ICollection expected, ICollection actual)
{
Assert.Equal(expected == null, actual == null);
if (expected == null)
{
return;
}
// Lookups are an aggregated collections (enumerable contents), but ordered.
ILookup<object, object> e = expected.Cast<object>().ToLookup(key => key);
ILookup<object, object> a = actual.Cast<object>().ToLookup(key => key);
// Dictionaries can't handle null keys, which is a possibility
Assert.Equal(e.Where(kv => kv.Key != null).ToDictionary(g => g.Key, g => g.Count()), a.Where(kv => kv.Key != null).ToDictionary(g => g.Key, g => g.Count()));
// Get count of null keys. Returns an empty sequence (and thus a 0 count) if no null key
Assert.Equal(e[null].Count(), a[null].Count());
}
示例7: AppendEventsToStream
public void AppendEventsToStream(string name, long streamVersion, ICollection<Event> events)
{
if (events.Count == 0) return;
// functional events don't have an identity
try
{
_msgStore.AppendToStore(name, streamVersion, events.Cast<object>().ToArray());
}
catch (AppendOnlyStoreConcurrencyException e)
{
// load server events
var server = LoadEventStream(name);
// throw a real problem
throw OptimisticConcurrencyException.Create(server.StreamVersion, e.ExpectedStreamVersion, name, server.Events);
}
// sync handling. Normally we would push this to async
foreach (var @event in events)
{
_msgHandler.Handle(@event);
}
}
示例8: OnUpdateGUI
protected override void OnUpdateGUI()
{
value = GetValue<ICollection>();
if(value == null)
return;
int prev_length = array.Length;
array = value.Cast<object>().ToArray();
if(array.Length < 1 || array.Length > 32)
return;
if(prev_length != array.Length)
{
foreach(Transform t in transform)
pb_ObjectUtility.Destroy(t.gameObject);
InitializeGUI();
}
}
示例9: _GetMailboxes
protected override List<MailboxBase> _GetMailboxes(ICollection<string> mailboxNames)
{
var namesArg = mailboxNames.Cast<object>().ToArray();
const string mailbox_ns = "msm";
const string domain_ns = "msd";
const string address_ns = "msa";
var mailboxQuery = new SqlQuery(MailboxTable.name.Alias(mailbox_ns))
.InnerJoin(AliasTable.name.Alias(address_ns),
Exp.EqColumns(MailboxTable.Columns.domain.Prefix(mailbox_ns),
AliasTable.Columns.domain.Prefix(address_ns)))
.InnerJoin(DomainTable.name.Alias(domain_ns),
Exp.EqColumns(MailboxTable.Columns.domain.Prefix(mailbox_ns),
DomainTable.Columns.domain.Prefix(domain_ns)))
.Select(MailboxTable.Columns.username.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.password.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.name.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.maildir.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.quota.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.local_part.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.domain.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.created.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.modified.Prefix(mailbox_ns))
.Select(MailboxTable.Columns.active.Prefix(mailbox_ns))
.Select(AliasTable.Columns.address.Prefix(address_ns))
.Select(AliasTable.Columns.redirect.Prefix(address_ns))
.Select(AliasTable.Columns.domain.Prefix(address_ns))
.Select(AliasTable.Columns.created.Prefix(address_ns))
.Select(AliasTable.Columns.modified.Prefix(address_ns))
.Select(AliasTable.Columns.active.Prefix(address_ns))
.Select(DomainTable.Columns.domain.Prefix(domain_ns))
.Select(DomainTable.Columns.description.Prefix(domain_ns))
.Select(DomainTable.Columns.aliases.Prefix(domain_ns))
.Select(DomainTable.Columns.mailboxes.Prefix(domain_ns))
.Select(DomainTable.Columns.maxquota.Prefix(domain_ns))
.Select(DomainTable.Columns.quota.Prefix(domain_ns))
.Select(DomainTable.Columns.transport.Prefix(domain_ns))
.Select(DomainTable.Columns.backupmx.Prefix(domain_ns))
.Select(DomainTable.Columns.created.Prefix(domain_ns))
.Select(DomainTable.Columns.modified.Prefix(domain_ns))
.Select(DomainTable.Columns.active.Prefix(domain_ns))
.Where(MailboxTable.Columns.active.Prefix(mailbox_ns), 1)
.Where(AliasTable.Columns.active.Prefix(address_ns), true)
.Where(AliasTable.Columns.is_group.Prefix(address_ns), false)
.Where(Exp.In(MailboxTable.Columns.username.Prefix(mailbox_ns), namesArg))
.Where(Exp.EqColumns(AliasTable.Columns.redirect.Prefix(address_ns),
MailboxTable.Columns.username.Prefix(mailbox_ns)));
var mailboxList = new List<MailboxBase>();
List<object[]> dbResult;
using (var db = _dbManager.GetAdminDb())
{
dbResult = db.ExecuteList(mailboxQuery).ToList();
}
if (!dbResult.Any())
return mailboxList;
var groupedResult = dbResult.GroupBy(r => r[0]).ToDictionary(g => g.Key, g => g.ToList());
const int domain_start_index = ToDtoConverters.MAILBOX_COLUMNS_COUNT + ToDtoConverters.MAIL_ADDRESS_COLUMNS_COUNT;
foreach (var group in groupedResult)
{
var mailboxDto = group.Value[0].SubArray(0, ToDtoConverters.MAILBOX_COLUMNS_COUNT).ToMailboxDto();
var aliasList = new List<MailAddressBase>();
foreach (var groupVal in group.Value)
{
var addressDto = groupVal.SubArray(ToDtoConverters.MAILBOX_COLUMNS_COUNT, ToDtoConverters.MAIL_ADDRESS_COLUMNS_COUNT).ToAddressDto();
var domainDto = groupVal.SubArray(domain_start_index, groupVal.Length - domain_start_index).ToWebDomainDto();
addressDto.Domain = domainDto;
var addr = addressDto.ToPostfixAddress();
if (addr.ToString() != mailboxDto.username)
aliasList.Add(addr);
}
var mailbox = new MailboxBase(
new MailAccountBase(mailboxDto.username),
new MailAddressBase(mailboxDto.local_part,
new WebDomainBase(mailboxDto.domain)), aliasList);
mailboxList.Add(mailbox);
}
return mailboxList;
}
示例10: SaveServers
public static void SaveServers(ICollection objects)
{
using (var writer = new XmlTextWriter("servers.xml", Encoding.UTF8)) {
xml.Serialize(writer, objects.Cast<BukkitServer>().ToList());
}
}
示例11: InternalDump
static string InternalDump(ICollection xc) { return "Count=" + xc.Count + xc.Cast<object>().Select(Dump).Stringify("\n", true).Surround("{", "}"); }
示例12: GenerateFunctionSql
private string GenerateFunctionSql(ICollection<DbModificationCommandTree> commandTrees, string rowsAffectedParameter)
{
DebugCheck.NotNull(commandTrees);
Debug.Assert(commandTrees.Any());
var functionSqlGenerator = new DmlFunctionSqlGenerator(_sqlGenerator);
switch (commandTrees.First().CommandTreeKind)
{
case DbCommandTreeKind.Insert:
return functionSqlGenerator.GenerateInsert(commandTrees.Cast<DbInsertCommandTree>().ToList());
case DbCommandTreeKind.Update:
return functionSqlGenerator.GenerateUpdate(commandTrees.Cast<DbUpdateCommandTree>().ToList(), rowsAffectedParameter);
case DbCommandTreeKind.Delete:
return functionSqlGenerator.GenerateDelete(commandTrees.Cast<DbDeleteCommandTree>().ToList(), rowsAffectedParameter);
}
return null;
}
示例13: _GetWebDomains
protected override List<WebDomainBase> _GetWebDomains(ICollection<string> domainNames)
{
if (null == domainNames)
throw new ArgumentNullException("domainNames", "in _GetWebDomains method");
var namesArg = domainNames.Cast<object>().ToArray();
var postfixDomainsQuery = new SqlQuery(DomainTable.name)
.Select(DomainTable.Columns.domain, DomainTable.Columns.created)
.Where(DomainTable.Columns.active, 1)
.Where(Exp.In(DomainTable.Columns.domain, namesArg))
.OrderBy(DomainTable.Columns.created, true);
List<object[]> rows;
using (var db = _dbManager.GetAdminDb())
rows = db.ExecuteList(postfixDomainsQuery);
var domains = rows
.Select(d => new WebDomainBase(d[0].ToString())
{
DateCreated = Convert.ToDateTime(d[1])
})
.ToList();
return domains;
}
示例14: UpdateCollectionSubscriptions
/// <summary>
/// Updates all the collection subscriptions.
/// <para />
/// This method is internally used when a notifiable collection raises the <see cref="NotifyCollectionChangedAction.Reset"/> event.
/// </summary>
public void UpdateCollectionSubscriptions(ICollection collection)
{
if (collection == null)
{
return;
}
lock (_lockObject)
{
List<WeakReference> collectionItems;
if (_collectionItems.TryGetValue(collection, out collectionItems))
{
var oldItems = collectionItems.ToArray();
foreach (var item in oldItems)
{
if (item.IsAlive)
{
var actualItem = item.Target;
UnsubscribeNotifyChangedEvents(actualItem, collection);
}
}
collectionItems.Clear();
var newItems = collection.Cast<object>().ToArray();
foreach (var item in newItems)
{
SubscribeNotifyChangedEvents(item, collection);
}
}
}
}
示例15: ToStringArray
public static string[] ToStringArray(ICollection collection)
{
if (collection == null)
{
return null;
}
return collection.Cast<string>().ToArray();
}