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


C# KeyValuePair类代码示例

本文整理汇总了C#中KeyValuePair的典型用法代码示例。如果您正苦于以下问题:C# KeyValuePair类的具体用法?C# KeyValuePair怎么用?C# KeyValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: FixedUpdate

	void FixedUpdate()
	{
		NetworkClient newClient = ConnectionManager.GameServer.AcceptClient();
		if( newClient != null ) remoteClients.Add( newClient );

		int messageLength = 1;

		foreach( KeyValuePair<byte,byte> localPositionKey in localPositions.Keys ) 
		{
			outputBuffer[ messageLength ] = localPositionKey.Key;
			outputBuffer[ messageLength + 1 ] = localPositionKey.Value;
			Buffer.BlockCopy( BitConverter.GetBytes( localPositions[ localPositionKey ] ), 0, outputBuffer, messageLength + 2, sizeof(float) );

			messageLength += DATA_SIZE;
		}

		foreach( NetworkClient client in remoteClients )
		{
			if( client.ReceiveData( inputBuffer ) )
			{
				Buffer.BlockCopy( inputBuffer, 0, outputBuffer, messageLength, DATA_SIZE );

				KeyValuePair<byte,byte> remotePositionKey = new KeyValuePair<byte,byte>( inputBuffer[ 0 ], inputBuffer[ 1 ] );
				remotePositions[ remotePositionKey ] = BitConverter.ToSingle( inputBuffer, 2 );
			}

			messageLength += DATA_SIZE;
		}

		outputBuffer[ 0 ] = (byte) messageLength;

		foreach( NetworkClient client in remoteClients )
			client.SendData( outputBuffer );
	}
开发者ID:Bitiquinho,项目名称:RobRehabProtocolTest,代码行数:34,代码来源:GameServer.cs

示例2: PosTest2

 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property get_Current in the IEnumerator 2");
     try
     {
         Dictionary<TestClass, TestClass> dictionary = new Dictionary<TestClass, TestClass>();
         TestClass Tkey1 = new TestClass();
         TestClass TVal1 = new TestClass();
         dictionary.Add(Tkey1, TVal1);
         Dictionary<TestClass, TestClass>.Enumerator enumer = dictionary.GetEnumerator();
         IEnumerator iEnumer = (IEnumerator)enumer;
         while(iEnumer.MoveNext())
         {
             object objCurrent = iEnumer.Current;
             KeyValuePair<TestClass, TestClass> keyVal = new KeyValuePair<TestClass, TestClass>(Tkey1, TVal1);
             if (!objCurrent.Equals(keyVal))
             {
                 TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:30,代码来源:dictionaryenumeratorienumeratorget_current.cs

示例3: AcceptOctetStream

        public HttpClientBuilder AcceptOctetStream()
        {
            var jsonAccept = new KeyValuePair<string, string>("accept", "application/octet-stream");
            _headers.Add(jsonAccept);

            return this;            
        }
开发者ID:Rnan,项目名称:Hadoop.Client,代码行数:7,代码来源:HttpClientBuilder.cs

示例4: FieldMap

        /// <summary>
        ///     关系映射
        /// </summary>
        /// <param name="type">实体类Type</param>
        public FieldMap(Type type)
        {
            Type = type;
            MapList = new Dictionary<PropertyInfo, FieldState>();

            #region 变量属性

            // 循环Set的字段
            foreach (var fieldProperty in Type.GetProperties())
            {
                // 获取字段的特性
                var attField = fieldProperty.GetCustomAttributes(false);
                var fieldState = new FieldState();
                foreach (var attr in attField)
                {
                    // 数据类型
                    if (attr is DataTypeAttribute) { fieldState.DataType = (DataTypeAttribute)attr; continue; }
                    // 字段映射
                    if (attr is FieldAttribute) { fieldState.FieldAtt = (FieldAttribute)attr; continue; }
                    // 属性扩展
                    if (attr is PropertyExtendAttribute) { fieldState.PropertyExtend = ((PropertyExtendAttribute)attr).PropertyExtend; continue; }
                }

                if (fieldState.FieldAtt == null) { fieldState.FieldAtt = new FieldAttribute { Name = fieldProperty.Name }; }
                if (string.IsNullOrEmpty(fieldState.FieldAtt.Name)) { fieldState.FieldAtt.Name = fieldProperty.Name; }
                if (fieldState.FieldAtt.IsMap && fieldState.FieldAtt.IsPrimaryKey) { PrimaryState = new KeyValuePair<PropertyInfo, FieldState>(fieldProperty, fieldState); } else { fieldState.FieldAtt.IsPrimaryKey = false; }


                //添加属变量标记名称
                MapList.Add(fieldProperty, fieldState);
            }

            #endregion
        }
开发者ID:lirongjun0926,项目名称:Farseer.Net,代码行数:38,代码来源:FieldMap.cs

示例5: BuildPredicate

        public static Func<ShapePlacementContext, bool> BuildPredicate(Func<ShapePlacementContext, bool> predicate, KeyValuePair<string, string> term)
        {
            var expression = term.Value;
            switch (term.Key) {
                case "ContentPart":
                        return ctx => ctx.Content != null
                            && ctx.Content.ContentItem.Parts.Any(part => part.PartDefinition.Name == expression)
                            && predicate(ctx);
                case "ContentType":
                    if (expression.EndsWith("*")) {
                        var prefix = expression.Substring(0, expression.Length - 1);
                        return ctx => ((ctx.ContentType ?? "").StartsWith(prefix) || (ctx.Stereotype ?? "").StartsWith(prefix)) && predicate(ctx);
                    }
                    return ctx => ((ctx.ContentType == expression) || (ctx.Stereotype == expression)) && predicate(ctx);
                case "DisplayType":
                    if (expression.EndsWith("*")) {
                        var prefix = expression.Substring(0, expression.Length - 1);
                        return ctx => (ctx.DisplayType ?? "").StartsWith(prefix) && predicate(ctx);
                    }
                    return ctx => (ctx.DisplayType == expression) && predicate(ctx);
                case "Path":
                    var normalizedPath = VirtualPathUtility.IsAbsolute(expression)
                                             ? VirtualPathUtility.ToAppRelative(expression)
                                             : VirtualPathUtility.Combine("~/", expression);

                    if (normalizedPath.EndsWith("*")) {
                        var prefix = normalizedPath.Substring(0, normalizedPath.Length - 1);
                        return ctx => VirtualPathUtility.ToAppRelative(String.IsNullOrEmpty(ctx.Path) ? "/" : ctx.Path).StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && predicate(ctx);
                    }

                    normalizedPath = VirtualPathUtility.AppendTrailingSlash(normalizedPath);
                    return ctx => (ctx.Path.Equals(normalizedPath, StringComparison.OrdinalIgnoreCase)) && predicate(ctx);
            }
            return predicate;
        }
开发者ID:dioptre,项目名称:nkd,代码行数:35,代码来源:ShapePlacementParsingStrategy.cs

示例6: CalculateColumns

 private void CalculateColumns(List<FormatObjectProperty> row)
 {
     _fullWidth = OutputWriter.Columns - 1; // -1 because of newline
     if (_fullWidth <= 0)
     {
         _fullWidth = OutputWriter.DefaultColumns - 1;
     }
     var cols = row.Count;
     // make sure it fits
     if (2 * cols - 1 > _fullWidth)
     {
         cols = (_fullWidth + 1) / 2;
         string format = "Warning: {0} columns have to be omitted in this format" +
                         "as they don't fit the available width.";
         OutputWriter.WriteLine(String.Format(format, row.Count - cols));
     }
     int perColumn = (_fullWidth - cols + 1) / cols;
     int rest = _fullWidth - cols + 1 - perColumn * cols; // because of rounding
     _currentColumns = new KeyValuePair<string, int>[cols];
     for (int i = 0; i < cols; i++)
     {
         _currentColumns[i] = new KeyValuePair<string,int>(row[i].PropertyName,
                                              i < rest ? perColumn + 1 : perColumn);
     }
 }
开发者ID:mauve,项目名称:Pash,代码行数:25,代码来源:TableFormatProcessor.cs

示例7: AnalyAndReplace

        /// <summary>
        /// 根据模板分析,并且返回已替换内容
        /// </summary>
        /// <param name="content"></param>
        /// <param name="regex"></param>
        /// <param name="modelInfo"></param>
        /// <param name="TransferFactory"></param>
        /// <returns></returns>
        public string AnalyAndReplace(string content, string regex, EntityInfo entity, Object obj, IExTransferFactory TransferFactory)
        {
            string Result = "";

            Dictionary<int, string> expresses = content.RegBaseDic(@regex); ;
            
            Dictionary<int, int> patternS_E = AnaUtil.Instance().GetKeyIndVal(expresses);

            Result += patternS_E.Count > 0 ? content.Substring(0, patternS_E.ElementAt(0).Key) : "";

            KeyValuePair<int, int> S_EPair = new KeyValuePair<int, int>();
            KeyValuePair<int, int> S_EPair2 = new KeyValuePair<int, int>();
            for (int i = 0; i < expresses.Count; i++)
            {
                Result += TransferFactory.CreateTransfer(expresses.ElementAt(i).Value).Transfer(expresses.ElementAt(i).Value, entity, obj);
                S_EPair = patternS_E.ElementAt(i);
                S_EPair2 = patternS_E.Count > (i + 1) ? patternS_E.ElementAt(i + 1) : patternS_E.ElementAt(i);

                Result += S_EPair2.Equals(S_EPair) ? "" : content.Substring(S_EPair.Value, S_EPair2.Key - S_EPair.Value);
            }
            Result += patternS_E.Count > 0 ? content.Substring(S_EPair.Value, content.Length - S_EPair.Value) : "";

            Result = patternS_E.Count == 0 ? content : Result;

            return Result;
        }
开发者ID:Dhenskr,项目名称:hoyi-er-tool,代码行数:34,代码来源:ContentAnalysis.cs

示例8: Create

        public void Create()
        {
            var p1 = new KeyValuePair<int, string>(42, "The answer");
            var p2 = KeyValuePair.Create(42, "The answer");

            Assert.AreEqual(p1, p2);
        }
开发者ID:koltsov-ps,项目名称:C5,代码行数:7,代码来源:KeyValuePairTests.cs

示例9: FindCurrentAlbum

        private void FindCurrentAlbum(string albumName)
        {
            albumName = albumName.ToUpper();

            if (!albumName.Equals(this.currentAlbum.Key))
            {
                if (this.Albums.ContainsKey(albumName))
                {
                    this.currentAlbum = new KeyValuePair<string, List<Music>>
                    (
                       albumName,
                       this.Albums[albumName]
                    );
                }
                else
                {
                    this.currentAlbum = new KeyValuePair<string, List<Music>>
                    (
                       albumName,
                       new List<Music>()
                    );

                    this.Albums.Add(this.currentAlbum);
                }
            }
        }
开发者ID:fholiveira,项目名称:MusicLibraryComparer,代码行数:26,代码来源:MusicsLibrary.cs

示例10: Draw

        public override void Draw(SpriteBatch sb)
        {
            int spacingR = 50;
            int spacingB = 50;
            lock (World.PlayerInfo)
            {
                try
                {
                    sb.DrawString(TextureManager.Fonts["console"], "Lobby", new Vector2(
                        GameConst.SCREEN_WIDTH / 20, GameConst.SCREEN_HEIGHT / 20), Color.White);

                    var p =  new KeyValuePair<int, PlayerInfo>(World.gameId, World.PlayerInfo[World.gameId]);
                    DrawPlayerIcon(sb, p, ref spacingR, ref spacingB);

                    foreach (var player in World.PlayerInfo)
                    {
                        if (player.Key != World.gameId)
                        {
                            DrawPlayerIcon(sb, player, ref spacingR, ref spacingB);
                        }
                    }

                    Texture2D checkTexture = ready ? TextureManager.Map["check-true"] : TextureManager.Map["check-false"];
                    sb.Draw(checkTexture, checkRect, Color.White);
                }
                catch (Exception e) { }
            }

            base.Draw(sb);
        }
开发者ID:DuncanKeller,项目名称:dunGeon,代码行数:30,代码来源:GameLobby.cs

示例11: foreach

        public string this[string key]
        {
            get
            {
                foreach (var entry in _records)
                {
                    if (entry.Key == key)
                    {
                        return entry.Value;
                    }
                }
                return null;
            }

            set
            {
                for (int i = 0; i < _records.Count; ++i )
                {
                    if (_records[i].Key == key)
                    {
                        _records[i] = new KeyValuePair<string, string>(key, value);
                        return;
                    }
                }
                _records.Add(new KeyValuePair<string, string>(key, value));
            }
        }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:27,代码来源:TextBuffer.cs

示例12: GetLatestVersions

        public override async Task<IEnumerable<KeyValuePair<string, NuGetVersion>>> GetLatestVersions(IEnumerable<string> packageIds, bool includePrerelease, bool includeUnlisted, CancellationToken token)
        {
            var results = new List<KeyValuePair<string, NuGetVersion>>();

            var tasks = new Stack<KeyValuePair<string, Task<IEnumerable<NuGetVersion>>>>();

            // fetch all ids in parallel
            foreach (var id in packageIds)
            {
                var task = new KeyValuePair<string, Task<IEnumerable<NuGetVersion>>>(id, GetVersions(id, includePrerelease, includeUnlisted, token));
                tasks.Push(task);
            }

            foreach (var pair in tasks)
            {
                // wait for the query to finish
                var versions = await pair.Value;

                if (versions == null
                    || !versions.Any())
                {
                    results.Add(new KeyValuePair<string, NuGetVersion>(pair.Key, null));
                }
                else
                {
                    // sort and take only the highest version
                    var latestVersion = versions.OrderByDescending(p => p, VersionComparer.VersionRelease).FirstOrDefault();

                    results.Add(new KeyValuePair<string, NuGetVersion>(pair.Key, latestVersion));
                }
            }

            return results;
        }
开发者ID:eerhardt,项目名称:NuGet3,代码行数:34,代码来源:MetadataResourceV2.cs

示例13: MakeGraphiteLines

 private GraphiteLine [] MakeGraphiteLines ( KeyValuePair<string, LatencyDatapointBox> latency )
 {
   if ( _calculateSumSquares )
   {
     return new GraphiteLine [] 
       {
         new GraphiteLine(RootNamespace + latency.Key + ".count", latency.Value.Count, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".min", latency.Value.Min, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".max", latency.Value.Max, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".mean", latency.Value.Mean, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".sum", latency.Value.Sum, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".sumSquares", latency.Value.SumSquares, Epoch)
       };
   }
   else 
   {
     return new GraphiteLine [] 
       {
         new GraphiteLine(RootNamespace + latency.Key + ".count", latency.Value.Count, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".min", latency.Value.Min, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".max", latency.Value.Max, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".mean", latency.Value.Mean, Epoch),
         new GraphiteLine(RootNamespace + latency.Key + ".sum", latency.Value.Sum, Epoch)
       };
   }
 }
开发者ID:BookSwapSteve,项目名称:statsd.net,代码行数:26,代码来源:LatencyBucket.cs

示例14: GetFromCache

		private static MethodInfo GetFromCache(MethodInfo methodInfo, Type type)
		{
			var key = new KeyValuePair<MethodInfo, Type>(methodInfo, type);
			MethodInfo method;
			cache.TryGetValue(key, out method);
			return method;
		}
开发者ID:elevine,项目名称:Core,代码行数:7,代码来源:InvocationHelper.cs

示例15: CreateMimeMessage

        public void CreateMimeMessage()
        {
            var message = Mail.GetInstance();
            var attachment = System.IO.Path.GetTempFileName();
            var text = "this is a test";
            var html = "<b>This<\b> is a better test";
            var headers = new KeyValuePair<String, String>("custom", "header");
            message.AddAttachment(attachment);
            message.Text = text;
            message.Html = html;
            message.AddTo("[email protected]");
            message.From = new MailAddress("[email protected]");
            message.AddHeaders(new Dictionary<string, string>{{headers.Key, headers.Value}});
            message.EnableGravatar();

            var mime = message.CreateMimeMessage();

            var sr = new StreamReader(mime.AlternateViews[0].ContentStream);
            var result = sr.ReadToEnd();
            Assert.AreEqual(text, result);

            sr = new StreamReader(mime.AlternateViews[1].ContentStream);
            result = sr.ReadToEnd();
            Assert.AreEqual(html, result);

            result = mime.Headers.Get(headers.Key);
            Assert.AreEqual(headers.Value, result);

            result = mime.Headers.Get("X-Smtpapi");
            var expected = "{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}";
            Assert.AreEqual(expected, result);

            result = mime.Attachments[0].Name;
            Assert.AreEqual(Path.GetFileName(attachment), result);
        }
开发者ID:advancedrei,项目名称:sendgridplus-csharp,代码行数:35,代码来源:MailTest.cs


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