本文整理汇总了C#中IEnumerable.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.ToDictionary方法的具体用法?C# IEnumerable.ToDictionary怎么用?C# IEnumerable.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewExpression
public static Expression CreateNewExpression(Expression currentContext, IEnumerable<DataApiNode> fieldExpressions, ISchemaProvider schemaProvider, out Type dynamicType)
{
var fieldExpressionsByName = fieldExpressions.ToDictionary(f => f.Name, f => f.Expression);
dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(fieldExpressions.ToDictionary(f => f.Name, f => f.Expression.Type));
var bindings = dynamicType.GetFields().Select(p => Expression.Bind(p, fieldExpressionsByName[p.Name])).OfType<MemberBinding>();
var newExp = Expression.New(dynamicType.GetConstructor(Type.EmptyTypes));
var mi = Expression.MemberInit(newExp, bindings);
return mi;
}
示例2: EpicsOverviewViewModel
public EpicsOverviewViewModel(IEnumerable<JiraIssue> issues, IEnumerable<RawAgileEpic> epics, IMessenger messenger)
{
_issues = issues;
_messenger = messenger;
_epicKeyToIgnoreStatus = epics.ToDictionary(e => e.Key, e => e.Done);
_epicKeyToIgnoreStatus[""] = false;
_epicKeyToName = epics.ToDictionary(e => e.Key, e => e.Name);
_epicKeyToName[""] = "(No epic)";
EpicsStatistics = new ObservableCollection<EpicShare>();
GenerateData();
}
示例3: AudioScan
internal AudioScan(DirectoryInfo directory, SearchOption searchoption,
bool parseAdd, bool parseUpdate, bool removeDeadFiles,
string[] extensions, IEnumerable<RawTrack> existingFiles, IEnumerable<string> ignoredFiles,
ScanFileEventHandler parsed,
ScanCompletedEventHandler done)
{
var thread = new Thread(Run);
_directory = directory;
_searchoption = searchoption;
_parseAdd = parseAdd;
_parseUpdate = parseUpdate;
_removeDeadFiles = removeDeadFiles;
_parser = new MediaParser();
_extensions = extensions;
_existingFiles = existingFiles.ToDictionary(rt => rt.File);
_ignoredFiles = (from s in ignoredFiles select new FileInfo(s)).ToArray();
Parsed = parsed;
Done = done;
_state = ScannerState.NotRunning;
_added = _updated = _skipped = _error = _removed = _total = 0;
thread.Start();
}
示例4: SyndicationService
public SyndicationService(string title, IEnumerable<IResourceCollection> collections)
{
Title = title;
this.collections = collections.ToDictionary(
x => x.Info.Title.Text,
StringComparer.OrdinalIgnoreCase);
}
示例5: ExecuteMarginCall
/// <summary>
/// Executes synchronous orders to bring the account within margin requirements.
/// </summary>
/// <param name="generatedMarginCallOrders">These are the margin call orders that were generated
/// by individual security margin models.</param>
/// <returns>The list of orders that were actually executed</returns>
public virtual List<Order> ExecuteMarginCall(IEnumerable<Order> generatedMarginCallOrders)
{
// if our margin used is back under the portfolio value then we can stop liquidating
if (Portfolio.MarginRemaining >= 0)
{
return new List<Order>();
}
// order by losers first
var executedOrders = new List<Order>();
var ordersWithSecurities = generatedMarginCallOrders.ToDictionary(x => x, x => Portfolio[x.Symbol]);
var orderedByLosers = ordersWithSecurities.OrderBy(x => x.Value.UnrealizedProfit).Select(x => x.Key);
foreach (var order in orderedByLosers)
{
Portfolio.Transactions.AddOrder(order);
Portfolio.Transactions.WaitForOrder(order.Id);
executedOrders.Add(order);
// if our margin used is back under the portfolio value then we can stop liquidating
if (Portfolio.MarginRemaining >= 0)
{
break;
}
}
return executedOrders;
}
示例6: XmlTestResultParser
public XmlTestResultParser(IEnumerable<TestCase> testCasesRun, string xmlResultFile, TestEnvironment testEnvironment, string baseDir)
{
_testEnvironment = testEnvironment;
_baseDir = baseDir;
_xmlResultFile = xmlResultFile;
_testCasesMap = testCasesRun.ToDictionary(tc => tc.FullyQualifiedName, tc => tc);
}
示例7: Get
/// <summary>
/// Gets the <see cref="Type" /> matching the provided members.
/// </summary>
/// <param name="sourceType">The <see cref="Type" /> to generate the runtime type from.</param>
/// <param name="properties">The <see cref="MemberInfo" /> to use to generate properties.</param>
/// <returns>A <see cref="Type" /> mathing the provided properties.</returns>
public Type Get(Type sourceType, IEnumerable<MemberInfo> properties)
{
properties = properties.ToArray();
if (!properties.Any())
{
throw new ArgumentOutOfRangeException("properties",
"properties must have at least 1 property definition");
}
var dictionary = properties.ToDictionary(f => _nameResolver.ResolveName(f), memberInfo => memberInfo);
var className = GetTypeKey(sourceType, dictionary);
return BuiltTypes.GetOrAdd(
className,
s =>
{
var typeBuilder = ModuleBuilder.DefineType(
className,
TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable);
Contract.Assume(typeBuilder != null);
SetAttributes(typeBuilder, sourceType);
foreach (var field in dictionary)
{
CreateProperty(typeBuilder, field);
}
return typeBuilder.CreateType();
});
}
示例8: RedirectFromLogin
public static void RedirectFromLogin(string login, IEnumerable<RestResponseCookie> cookies)
{
if (cookies == null)
throw new ArgumentNullException("cookies");
cookies = cookies.ToArray();
var data = JsonConvert.SerializeObject(cookies.ToDictionary(c => c.Name, c => c.Value));
var cookie = FormsAuthentication.GetAuthCookie(login, false);
var sourceTicket = FormsAuthentication.Decrypt(cookie.Value);
if (sourceTicket == null)
throw new ApplicationException("Unable to decrypt authentication");
var expiration = cookies.Select(c => c.Expires)
.Where(exp => exp > DateTime.Today.AddYears(-1) && exp < DateTime.Today.AddYears(1))
.Concat(new[] {sourceTicket.Expiration})
.Min();
var ticket = new FormsAuthenticationTicket(
sourceTicket.Version, sourceTicket.Name, sourceTicket.IssueDate,
expiration, false, data);
cookie.Value = FormsAuthentication.Encrypt(ticket);
Response.SetCookie(cookie);
var redirectUrl = FormsAuthentication.GetRedirectUrl(login, sourceTicket.IsPersistent);
Response.Redirect(redirectUrl);
}
示例9: CryptographyManagerImpl
/// <summary>
/// Initializes a new instance of the class <see cref="CryptographyManagerImpl"/> given a collection of <see cref="IHashProvider"/> and a
/// collection of <see cref="ISymmetricCryptoProvider"/>.
/// </summary>
/// <param name="hashProviderNames">Sequence of names of the hash providers as defined in configuration.</param>
/// <param name="hashProviders">The hash providers corresponding to the names in <paramref name="hashProviderNames"/> at the same index.</param>
/// <param name="cryptoProviderNames">Sequence of names of the cryptography providers as defined in configuration.</param>
/// <param name="symmetricCryptoProviders">The symmetric cryptography providers corresponding to the names give in <paramref name="cryptoProviderNames"/>
/// <param name="instrumentationProvider">The instrumentation provider used to report errors.</param>
/// at the same index.</param>
public CryptographyManagerImpl(IEnumerable<string> hashProviderNames, IEnumerable<IHashProvider> hashProviders,
IEnumerable<string> cryptoProviderNames, IEnumerable<ISymmetricCryptoProvider> symmetricCryptoProviders,
IDefaultCryptographyInstrumentationProvider instrumentationProvider)
: this(hashProviderNames.ToDictionary(hashProviders), cryptoProviderNames.ToDictionary(symmetricCryptoProviders), instrumentationProvider)
{
}
示例10: StepDirectory
public StepDirectory(string path, ScriptEngine pythonEngine)
{
_path = path;
_pythonEngine = pythonEngine;
_logger = LogManager.GetLogger("steps");
var stepTypes = this.GetType().Assembly.GetTypes()
.Where(t => !t.IsAbstract)
.Where(t => t.IsSubclassOf(typeof (Step)))
.Select(t => new
{
Type = t,
Extensions = t.GetCustomAttributes(typeof (HandlesAttribute), true)
.Cast<HandlesAttribute>()
.SelectMany(h => h.Extensions)
});
_extensions = stepTypes.SelectMany(t => t.Extensions);
_typesByExtension = _extensions.ToDictionary(ext => ext.ToLowerInvariant(),
ext => stepTypes.Single(s => s.Extensions.Contains(ext)).Type);
LoadStepsAndMetadata();
InitializeFileWatcher();
}
示例11: ResolveDependencies
public static void ResolveDependencies(IEnumerable<ClassNode> allClasses)
{
var allClassesBySymbol = allClasses.ToDictionary(x => x.Symbol, x => x);
foreach (var dependor in allClassesBySymbol.Values)
{
foreach (var dependency in dependor.SymbolDependencies)
{
if (allClassesBySymbol.ContainsKey(dependency))
{
CreateDependency(allClassesBySymbol[dependency], dependor);
}
else
{
var matchingSymbols = allClassesBySymbol.Keys.Where(x => SymbolsMatch(x, dependency)).ToList();
if (matchingSymbols.Count == 1)
{
CreateDependency(allClassesBySymbol[matchingSymbols.First()], dependor);
}
if (matchingSymbols.Count > 1)
throw new NotImplementedException();
}
}
}
}
示例12: _Schedule
/// <summary>
/// Erzeugt eine neue Verwaltung.
/// </summary>
/// <param name="definition">Die Definition der Aufzeichnung.</param>
/// <param name="exceptions">Alle Ausnahmen zur Aufzeichnung.</param>
/// <exception cref="ArgumentNullException">Es wurde keine Aufzeichnung angegeben.</exception>
public _Schedule( IScheduleDefinition definition, IEnumerable<PlanException> exceptions = null )
{
// Validate
if (definition == null)
throw new ArgumentNullException( "plan" );
// Remember
Definition = definition;
// Default
if (exceptions == null)
exceptions = Enumerable.Empty<PlanException>();
// Validate exceptions
foreach (var exception in exceptions)
if (exception.ExceptionDate.TimeOfDay != TimeSpan.Zero)
throw new ArgumentException( string.Format( Properties.SchedulerResources.Exception_NotAPureDate, exception.ExceptionDate ), "exceptions" );
// Cross validate
foreach (var exception in exceptions.GroupBy( e => e.ExceptionDate ))
if (exception.Count() > 1)
throw new ArgumentException( string.Format( Properties.SchedulerResources.Exception_DuplicateDate, exception.Key ), "exceptions" );
// Order plan
m_Exceptions = exceptions.ToDictionary( e => e.ExceptionDate );
}
示例13: EntityType
internal EntityType(string schema, string name, IEnumerable<EntityField> fields)
{
_schema = schema;
_name = name;
_tableName = String.Format("{0}_{1}", _schema, _name);
_fields = fields.ToDictionary(val => val.Name);
}
示例14: TaskList
public TaskList(IEnumerable<TaskTable> tasks, IEnumerable<CategoryTable> categories, int currentPosition = 0)
{
_tasks = tasks.ToList();
_taskDictionary = _tasks.ToDictionary(task => task.Id);
_category = categories.ToDictionary(cat => cat.Id);
_enumerator = new TaskEnumerator(this) { CurrentPosition = currentPosition };
}
示例15: AddSerializers
public void AddSerializers(IEnumerable<Type> list)
{
var dictionary = list.ToDictionary(type => type.BaseType.GenericTypeArguments[0], type => (ISerializer)Activator.CreateInstance(type));
foreach (var serializer in dictionary)
serializers.Add(serializer.Key, serializer.Value);
}