当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.First方法代码示例

本文整理汇总了C#中IDictionary.First方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.First方法的具体用法?C# IDictionary.First怎么用?C# IDictionary.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNearestLevel

        public static int GetNearestLevel(IDictionary<int, Resolution> resolutions, double resolution)
        {
            if (resolutions.Count == 0)
            {
                throw new ArgumentException("No tile resolutions");
            }

            //smaller than smallest
            if (resolutions.Last().Value.UnitsPerPixel > resolution) return resolutions.Last().Key;

            //bigger than biggest
            if (resolutions.First().Value.UnitsPerPixel < resolution) return resolutions.First().Key;

            int result = 0;
            double resultDistance = double.MaxValue;
            foreach (var key in resolutions.Keys)
            {
                double distance = Math.Abs(resolutions[key].UnitsPerPixel - resolution);
                if (distance < resultDistance)
                {
                    result = key;
                    resultDistance = distance;
                }
            }
            return result;
        }
开发者ID:galchen,项目名称:brutile,代码行数:26,代码来源:Utilities.cs

示例2: SetToDataGridViewResult

		private void SetToDataGridViewResult(IDictionary<bool[], bool[]> results)
		{
			InitializeDataGridViewResult(results.First().Key.Length, results.First().Value.Length);
			dataGridViewResult.Rows.Clear();

			List<int[]> result = new List<int[]>();

			foreach (KeyValuePair<bool[], bool[]> item in results)
			{
				int[] currentRes = new int[item.Key.Length + item.Value.Length];

				for (int i = 0; i < item.Key.Length; i++)
				{
					if (item.Key[i])
					{
						currentRes[i] = 1;
					}
					else
					{
						currentRes[i] = 0;
					}
				}

				for (int i = 0; i < item.Value.Length; i++)
				{
					if (item.Value[i])
					{
						currentRes[item.Key.Length + i] = 1;
					}
					else
					{
						currentRes[item.Key.Length + i] = 0;
					}
				}

				result.Add(currentRes);
			}

			for (int i = 0; i < result.Count; i++)
			{
				dataGridViewResult.Rows.Add();

				for (int j = 0; j < result[i].Length; j++)
				{
					dataGridViewResult.Rows[i].Cells[j].Value = result[i][j];
				}
			}
		}
开发者ID:AlehSkamarokhau,项目名称:PrototypeApps,代码行数:48,代码来源:InputValuesGeneratorForm.cs

示例3: ResolveParameterUntyped

        /// <summary>Resolve untyped parameters used for the code or expression.</summary>
        /// <param name="scope">The expression scope for the code or expression to compile.</param>
        /// <param name="parameterTypes">The dictionary of parameter (name / type) used in the code or expression to compile.</param>
        /// <returns>A ParameterExpression list used in code or expression to compile.</returns>
        private static List<ParameterExpression> ResolveParameterUntyped(ExpressionScope scope, IDictionary<string, Type> parameterTypes, bool forceFirstParameterProperty = false)
        {
            var parameters = new List<ParameterExpression>();

            foreach (var parameter in parameterTypes)
            {
                var parameterExpression = scope.CreateParameter(typeof (object));
                parameters.Add(parameterExpression);

                scope.CreateLazyVariable(parameter.Key, new Lazy<Expression>(() =>
                {
                    var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key);

                    var innerExpression = parameterExpression.Type != parameter.Value ?
                        Expression.Assign(innerParameter, Expression.Convert(parameterExpression, parameter.Value)) :
                        Expression.Assign(innerParameter, parameterExpression);

                    scope.Expressions.Insert(0, innerExpression);

                    return innerParameter;
                }));
            }

            if (parameterTypes.Count == 1 || (parameterTypes.Count > 0 && forceFirstParameterProperty))
            {
                var keyValue = parameterTypes.First();
                if (Type.GetTypeCode(keyValue.Value) == TypeCode.Object)
                {
                    ResolzeLazyMember(scope, parameterTypes, keyValue.Key, keyValue.Value);
                }
            }

            return parameters;
        }
开发者ID:zzzprojects,项目名称:Eval-Expression.NET,代码行数:38,代码来源:ResolveParameterUntyped.cs

示例4: PullRequest

        public PullAPIResponse PullRequest(IDictionary<string, object> prms)
        {
            string response = null;
            PullAPIResponse result = new PullAPIResponse() { PullDetails = new PullInfo() };

            var id = (string)prms.First(p => p.Key == "id").Value;

            switch (id)
            {
                case "08b923395b6ce8bfa4d96f57jsonmeta":
                    response = MockAPIResponses.Default.PullJsonMetaFormat;
                    result.PullDetails.Format = "json_meta";
                    break;
                case "08b923395b6ce8bfa4d96f5jsonarray":
                    response = MockAPIResponses.Default.PullJsonArrayFormat;
                    result.PullDetails.Format = "json_array";
                    break;
                case "08b923395b6ce8bfa4d96jsonnewline":
                    response = MockAPIResponses.Default.PullJsonNewLineFormat;
                    result.PullDetails.Format = "json_new_line";
                    break;
            }

            result.StatusCode = HttpStatusCode.OK;

            if (response != null)
            {
                result.Data = APIHelpers.DeserializeResponse(response, result.PullDetails.Format);
            }

            return result;
        }
开发者ID:sonrnews,项目名称:datasift-dotnet,代码行数:32,代码来源:MockRestAPIRequest.cs

示例5:

 public ResultCachesViewsPanel
     (IDictionary<ContextBase, ResultCache> target, SourceView master)
 {
     Target = target;
     Master = master;
     var selector = true.CreateLineupView
         (Target.Keys.Select(i => i.CreateLink(this)).ToArray());
     Client = false.CreateLineupView(selector, Target.First().CreateView(Master));
 }
开发者ID:hahoyer,项目名称:reni.cs,代码行数:9,代码来源:ResultCachesViewsPanel.cs

示例6: UpdateExisting

        /// <summary>
        /// Update any existing rows for the given values, and remove them from the values collection.
        /// </summary>
        /// <param name="configName"></param>
        /// <param name="values"></param>
        /// <param name="conn"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public bool UpdateExisting(string configName, IDictionary<long, MonitorRecord<double>> values, IDbConnection conn, IDbTransaction transaction = null)
        {
            var result = false;

            if (values.Count == 0)
                return true;

            MonitorInfo monitorInfo;
            if (_cache.MonitorInfo.TryGetValue(configName, out monitorInfo))
            {
                var reduceLevel = monitorInfo.FirstReduceLevel;
                var reduceMethod = reduceLevel.AggregationClass;
                var startTime = values.First().Value.TimeStamp;

                var tableName = Support.MakeReducedName(configName, reduceLevel.Resolution);

                var updateList = new List<MonitorRecord<double>>();
                var combineList = new List<MonitorRecord<double>>();

                //Based on the timestamp we have we pull out from the database all recrods that have a date
                //grater than the timestamp we have. For each value we find loop through and find the value
                //that is the next greatest time past our current value from the database
                var existingList = _storageCommands.SelectListForUpdateExisting(tableName, startTime, conn, transaction);
                foreach (var existingValue in existingList)
                {
                    var hasNext = false;
                    var matchingValue = _cache.Empty;

                    var valuesEnumerator = values.GetEnumerator();
                    while ((hasNext = valuesEnumerator.MoveNext()) && ((matchingValue = valuesEnumerator.Current.Value).TimeStamp < existingValue.TimeStamp)) ;

                    combineList.Clear();

                    if (hasNext && !_cache.Empty.Equals(matchingValue))
                    {
                        combineList.Add(existingValue);
                        combineList.Add(matchingValue);
                        values.Remove(matchingValue.TimeStamp.Ticks);
                    }
                    else
                        continue;

                    //Reduce the value we have from the database with the value we have here (thats what is in the combined list)
                    var update = reduceMethod.Reduce(existingValue.TimeStamp, combineList);
                    updateList.Add(update);
                }

                //Update everything in the database
                _storageCommands.Update(tableName, updateList, conn, transaction);

                result = true;
            }
            else
                throw new DataException("No monitor config found for " + configName);

            return result;
        }
开发者ID:modulexcite,项目名称:ZocMon,代码行数:65,代码来源:RecordFlushUpdate.cs

示例7: SubstituteRouteParameters

		private static string SubstituteRouteParameters(string endpointUri, IDictionary<string, string> parameters)
		{
			var regex = new Regex("{(.*?)}");
			var result = regex.Matches(endpointUri);
			foreach (var match in result)
			{
				var key = match.ToString().Remove(match.ToString().Length - 1).Remove(0, 1);
				var entry = parameters.First(x => x.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase));
				parameters.Remove(entry.Key);
				endpointUri = endpointUri.Replace(match.ToString(), entry.Value);
			}

			return endpointUri.ToLower();
		}
开发者ID:danhaller,项目名称:SevenDigital.Api.Wrapper,代码行数:14,代码来源:RouteParamsSubstitutor.cs

示例8: ShardStrategy

        public ShardStrategy(IDictionary<string, IAsyncFilesCommands> shards)
		{
			if (shards == null) throw new ArgumentNullException("shards");
			if (shards.Count == 0)
				throw new ArgumentException("Shards collection must have at least one item", "shards");

            this.shards = new Dictionary<string, IAsyncFilesCommands>(shards, StringComparer.OrdinalIgnoreCase);


			Conventions = shards.First().Value.Conventions.Clone();

			ShardAccessStrategy = new SequentialShardAccessStrategy();
			ShardResolutionStrategy = new DefaultShardResolutionStrategy(shards.Keys, this);
			ModifyFileName = (convention, shardId, documentId) => convention.IdentityPartsSeparator + shardId + convention.IdentityPartsSeparator + documentId;
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:15,代码来源:ShardStrategy.cs

示例9: AssertResponseHeadersAreExpected

        private static void AssertResponseHeadersAreExpected(IEnumerable<KeyValuePair<string, string>> expectedResponseHeaders, IDictionary<string, string> actualResponseHeaders)
        {
            foreach (var expectedHeader in expectedResponseHeaders)
            {
                if (!actualResponseHeaders.ContainsKey(expectedHeader.Key))
                {
                    throw new UnexpectedResponseHeaderException(expectedHeader.Key, expectedHeader.Value);
                }

                var actualValue = actualResponseHeaders.First(h => h.Key == expectedHeader.Key).Value;
                if (actualValue != expectedHeader.Value)
                {
                    throw new UnexpectedResponseHeaderException(expectedHeader.Key, expectedHeader.Value, actualValue);
                }
            }
        }
开发者ID:sreal,项目名称:Everest,代码行数:16,代码来源:EnsureAcceptableResponseHeaders.cs

示例10: ReplaceTokens

 /// <summary>
 /// Replaces tokens in the template text with the values from the supplied dictionary
 /// </summary>
 /// <param name="templateText">The template text</param>
 /// <param name="tokenValues">Dictionary mapping token names to values</param>
 /// <returns>Text with tokens replaced with their corresponding values from the dictionary</returns>
 public string ReplaceTokens(string templateText, IDictionary<string, string> tokenValues)
 {
     var output = RegExToken.Replace(templateText, (match) =>
                                                           {
                                                               var tokenName = match.Groups["TokenName"].Value.ToLower();
                                                               try
                                                               {
                                                                   KeyValuePair<string, string> property =
                                                                       tokenValues.First(x => x.Key.ToLower() == tokenName);
                                                                   return property.Value;
                                                               }
                                                               catch (Exception)
                                                               {
                                                                   throw new ArgumentException("No value supplied for token: " + tokenName);
                                                               }
                                                           });
     return output;
 }
开发者ID:endeavour,项目名称:town-crier,代码行数:24,代码来源:TemplateParser.cs

示例11: ResolveParameterTyped

        /// <summary>Resolve typed parameters used for the code or expression.</summary>
        /// <param name="scope">The expression scope for the code or expression to compile.</param>
        /// <param name="parameterTypes">The dictionary of parameter (name / type) used in the code or expression to compile.</param>
        /// <returns>A ParameterExpression list used in code or expression to compile.</returns>
        private static List<ParameterExpression> ResolveParameterTyped(ExpressionScope scope, IDictionary<string, Type> parameterTypes)
        {
            var parameters = new List<ParameterExpression>();

            foreach (var parameter in parameterTypes)
            {
                parameters.Add(scope.CreateParameter(parameter.Value, parameter.Key));
            }

            if (parameterTypes.Count == 1)
            {
                var keyValue = parameterTypes.First();
                if (Type.GetTypeCode(keyValue.Value) == TypeCode.Object)
                {
                    ResolzeLazyMember(scope, parameterTypes, keyValue.Key, keyValue.Value);
                }
            }

            return parameters;
        }
开发者ID:emmatb1,项目名称:Eval-Expression.NET,代码行数:24,代码来源:ResolveParameterTyped.cs

示例12: CommandServerGenerateCertificate

        /// <summary>
        /// Generates a server pfx file used by the command server with the specified password within the arguments.
        /// </summary>
        /// <param name="arguments">
        ///     <para>The arguments for this command</para>
        ///     <para>Expecting "password", but it is optional. If no password is supplied a random password will be generated</para>
        /// </param>
        public static ServiceMessage CommandServerGenerateCertificate(IDictionary<String, String> arguments) {
            var model = new CertificateModel();

            if (arguments != null && arguments.Count > 0) {
                model.Password = arguments.First().Value;
            }
            else {
                model.RandomizePassword();
            }

            model.Generate();

            return new ServiceMessage() {
                Name = "result",
                Arguments = new Dictionary<String, String>() {
                    { "Command", "CommandServerCreateCertificate" },
                    { "Success", model.Exists.ToString() },
                    { "Message", String.Format("Created certificate with password: {0}", model.Password) },
                    { "Password", model.Password }
                }
            };
        }
开发者ID:EBassie,项目名称:Potato,代码行数:29,代码来源:ConfigController.cs

示例13: CreateSentence

 public override ISentence CreateSentence(string subject, IDictionary<string, string[]> facts)
 {
     var separator = facts.Count > 1 || (facts.Count == 1 && facts.First().Value.Length > 1)
                         ? Environment.NewLine + Indent
                         : " ";
     var factsText = string.Join(";" + Environment.NewLine + Indent, facts.Select(this.GetFact));
     var text = string.Format("{0}{1}{2}.", subject, separator, factsText);
     var file = this.CreateNTriplesFile(text, true);
     var sentence = file.SentencesEnumerable.First();
     return sentence;
 }
开发者ID:xsburg,项目名称:ReSharper.NTriples,代码行数:11,代码来源:NTriplesElementFactoryImpl.cs

示例14: SelectGenericsFromArgumentsForOneLevel

        /// <summary>
        /// </summary>
        /// <param name="methodSymbol">
        /// </param>
        /// <param name="map">
        /// </param>
        /// <param name="resolvedTypes">
        /// </param>
        private static void SelectGenericsFromArgumentsForOneLevel(MethodSymbol methodSymbol, IDictionary<IType, IType> map, List<TypeSymbol> resolvedTypes)
        {
            ////if (namedTypeSymbol.IsNestedType())
            ////{
            ////    SelectGenericsFromArgumentsForOneLevel(namedTypeSymbol.ContainingType, map, resolvedTypes);
            ////}
            foreach (var typeSymbol in methodSymbol.TypeArguments)
            {
                if (typeSymbol.Kind == SymbolKind.TypeParameter)
                {
                    var foundType = map.First(pair => pair.Key.Name == typeSymbol.Name);
                    resolvedTypes.Add((foundType.Value as MetadataTypeAdapter).TypeDef);
                    continue;
                }

                var subTypeNamedTypeSymbol = typeSymbol as NamedTypeSymbol;
                if (subTypeNamedTypeSymbol != null && subTypeNamedTypeSymbol.Arity > 0)
                {
                    resolvedTypes.Add(ConstructGenericTypeSymbol(subTypeNamedTypeSymbol, map));
                    continue;
                }

                resolvedTypes.Add(subTypeNamedTypeSymbol);
            }
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:33,代码来源:Extentions.cs

示例15: GetByte

 private byte GetByte(char c, IDictionary<byte, string> charLookup)
 {
     return charLookup.First(kv => kv.Value[0] == c).Key; // lazy
 }
开发者ID:myoKun345,项目名称:Mother2GbaTranslation,代码行数:4,代码来源:Compiler.cs


注:本文中的IDictionary.First方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。