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


C# IDictionary.ElementAt方法代码示例

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


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

示例1: ToJson

 public static string ToJson(IDictionary<string, object> dictionary, string objectName = null)
 {
     if (!string.IsNullOrWhiteSpace(objectName))
         objectName = "{{\"{0}\":".Fmt(objectName);
     var stringBuilder = new StringBuilder(objectName);
     for (var i = 0; i < dictionary.Count; i++)
     {
         var kvp = dictionary.ElementAt(i);
         if (i == 0) stringBuilder.Append("{");
         if (kvp.Value is IDictionary<string, object>)
         {
             stringBuilder.Append("\"{0}\":".Fmt(kvp.Key));
             stringBuilder.Append(ToJson((IDictionary<string, object>)kvp.Value));
         }
         else if (kvp.Value is dynamic[])
         {
             stringBuilder.Append("\"{0}\":[".Fmt(kvp.Key));
             foreach (var dyn in (dynamic[])kvp.Value)
             {
                 stringBuilder.Append(ToJson(dyn));
             }
             stringBuilder.Append("],");
         }
         else
         {
             stringBuilder.Append("\"{0}\":{1}".Fmt(kvp.Key, JsonSerializer.SerializeToString(kvp.Value)));
             stringBuilder.Append(i < dictionary.Count - 1 ? "," : "");
         }
         if (i == dictionary.Count - 1) stringBuilder.Append("}");
     }
     if (!string.IsNullOrWhiteSpace(objectName))
         stringBuilder.Append("}");
     return stringBuilder.ToString().Replace("}{", "},{").Replace("}\"", "},\"");
 }
开发者ID:JonCanning,项目名称:CerealBox,代码行数:34,代码来源:ConvertDynamic.cs

示例2: Serialize

        public string Serialize(IDictionary<string, int> dictionary)
        {
            Precondition.EnsureNotNull("dictionary", dictionary);

            TreeMapNode root = new TreeMapNode();

            int size = dictionary.Count;

            var colors = ColorHelper.GetGradientHexColors(
                //ColorTranslator.FromHtml("#EBEB35"),
                    Color.Yellow,
                    Color.ForestGreen,
                    Color.Red, size)
                .ToList();

            for (int i = 0; i < size; i++)
            {
                var item = dictionary.ElementAt(i);

                TreeMapNode child = new TreeMapNode { Id = item.Key, Name = item.Key };
                TreeMapNodeItem data = new TreeMapNodeItem
                {
                    Area = item.Value,
                    Color = colors[i],
                    Count = item.Value.ToString(CultureInfo.InvariantCulture)
                };

                child.Data = data;
                root.Children.Add(child);
            }

            return JsonConvert.SerializeObject(root);
        }
开发者ID:injektoxa,项目名称:nTextNetwork,代码行数:33,代码来源:JsonSerializerForJit.cs

示例3: GraphWindow

        public GraphWindow(IDictionary<DateTime, Decimal> balance)
        {
            InitializeComponent();
            timeBalance = balance;

            startToShow = DateTime.Now.Date;
            endToShow = new DateTime(startToShow.Year, startToShow.Month, 1);
            minboundary = new DateTime(
                balance.ElementAt(0).Key.Year,
                balance.ElementAt(0).Key.Month,
                1);

            ChangeDataByBoundaries();
            chart.Series[0].ChartType = SeriesChartType.Line;
            chart.Series[0].BorderWidth = 4;
            SetupChartArea();
            UpdateLabels();
        }
开发者ID:jomarko,项目名称:FinanceManager,代码行数:18,代码来源:GraphWindow.cs

示例4: ShouldMatch

		public static void ShouldMatch(this IEnumerable<Model.Genre> genres, IDictionary<string,string> mappings)
		{
			for (int i = 0; i < genres.Count(); i++)
			{
				var genre = genres.ElementAt(i);
				var mapping = mappings.ElementAt(i);
				Assert.AreEqual(genre.Id, mapping.Key);
				Assert.AreEqual(genre.Name, mapping.Value);
			}
		}
开发者ID:NTCoding,项目名称:FubuRaven.NTCoding.com,代码行数:10,代码来源:GenreAssertions.cs

示例5: GetQueryString

        public static string GetQueryString(IDictionary<string, string> dictionary)
        {
            if (dictionary == null || dictionary.Count == 0) {
                throw new ArgumentNullException("dictionary");
            }

            var query = new StringBuilder();
            var first = dictionary.ElementAt(0);

            query.Append(first.Key + "=" + first.Value);

            if (dictionary.Count > 1) {
                for (int i = 1; i < dictionary.Count; i++) {
                    var d = dictionary.ElementAt(i);
                    query.Append("&" + d.Key + "=" + d.Value);
                }
            }

            return query.ToString();
        }
开发者ID:ccrabb,项目名称:Beer-Boutique,代码行数:20,代码来源:Helpers.cs

示例6: JsonExpression

        public JsonExpression(IDictionary<String, TypeInferenceUnit> props)
            : base(ExpressionType.Json, props.Values)
        {
            // bug: jeez.. wtf alert
//            Props = props;

            Props = new Dictionary<String, TypeInferenceUnit>();
            for (var i = 0; i < props.Count; i++)
            {
                Props.Add("Field" + i, props.ElementAt(i).Value);
            }
        }
开发者ID:xeno-by,项目名称:relinq,代码行数:12,代码来源:JsonExpression.cs

示例7: NodeFactory

        public NodeFactory(NodeFuncGenerator funcGenerator, IDictionary<NodeType, double> probabilityMap)
        {
            if (probabilityMap.Count == 0)
                throw new ArgumentException();

            foreach (var item in probabilityMap)
            {
                if (item.Value < 0)
                    throw new ArgumentException();
            }

            funcGenerator_ = funcGenerator;

            typeDistributionMap_ = new Dictionary<NodeType, double>();
            double sum = 0.0d;
            for (int i = 0; i < probabilityMap.Count; i++)
            {
                sum += probabilityMap.ElementAt(i).Value;
                typeDistributionMap_.Add(probabilityMap.ElementAt(i).Key, sum);
            }
            typeDistributionMapMax_ = sum;
        }
开发者ID:Spawek,项目名称:trendpredictortester,代码行数:22,代码来源:NodeFactory.cs

示例8: GetDefaultsAsJson

        private string GetDefaultsAsJson(IDictionary<string, object> defaults)
        {
            StringBuilder defaultsAsJson = new StringBuilder();
            if (defaults.Count > 0)
            {
                defaultsAsJson.Append(", {");

                for (int i = 0; i < defaults.Count; i++)
                {
                    var keyPair = defaults.ElementAt(i);
                    defaultsAsJson.AppendFormat("{0}:'{1}'", keyPair.Key, keyPair.Value);

                    if (!keyPair.Equals(defaults.Last()))
                        defaultsAsJson.Append(",");
                }

                defaultsAsJson.Append("}");
            }
            return defaultsAsJson.ToString();
        }
开发者ID:adaptabi,项目名称:GeekStuff-Blog-Posts,代码行数:20,代码来源:JavascriptRouteGenerator.cs

示例9: GenerateSrcMLFromFiles

 /// <summary>
 /// Generates srcML from a file
 /// </summary>
 /// <param name="fileNames">An enumerable of filenames</param>
 /// <param name="xmlFileName">the output file name</param>
 /// <param name="language">The language to use</param>
 /// <param name="namespaceArguments">additional arguments</param>
 /// <param name="extensionMapping">an extension mapping</param>
 public void GenerateSrcMLFromFiles(ICollection<string> fileNames, string xmlFileName, Language language, ICollection<UInt32> namespaceArguments, IDictionary<string, Language> extensionMapping) {
     UInt32 arguments = GenerateArguments(namespaceArguments);
     try {
         using (Archive srcmlArchive = new Archive()) {
             if (Convert.ToBoolean(extensionMapping.Count())) {
                 srcmlArchive.RegisterFileExtension(extensionMapping.ElementAt(0).Key, extensionMapping.ElementAt(0).Value.ToString());
             }
             foreach (string file in fileNames) {
                 using (Unit srcmlUnit = new Unit()) {
                     srcmlUnit.SetUnitFilename(file);
                     srcmlUnit.SetUnitLanguage(LibSrcMLRunner.SrcMLLanguages.SRCML_LANGUAGE_CXX);
                     srcmlArchive.AddUnit(srcmlUnit);
                 }
             }
             srcmlArchive.SetOutputFile(xmlFileName);
             RunSrcML(srcmlArchive, LibSrcMLRunner.SrcmlCreateArchiveFtF);
         }
     }
     catch (Exception e) {
         throw new SrcMLException(e.Message, e);
     }
 }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:30,代码来源:LibSrcMLRunner.cs

示例10: HandleUpdateAddOptions

        private ExpressionInfo HandleUpdateAddOptions(FunctionCall call, ExpressionInfo exprInfo, IVulnerabilityStorage storage, 
                                                      IDictionary<uint, ExpressionInfo> argumentInfos, AnalysisStacks analysisStacks)
        {
            XmlNode firstArgument;
            XmlNode secondArgument;

            string optionKeyValue;

            if (call.Arguments.TryGetValue(1, out firstArgument) &&
                call.Arguments.TryGetValue(2, out secondArgument) &&
                TryGetOptionKeyValue(firstArgument, argumentInfos[1], out optionKeyValue))
            {
                foreach (var sqliTaintSet in argumentInfos.ElementAt(1).Value.ExpressionTaint.SqliTaint)
                {
                    if (sqliTaintSet.TaintTag == SQLITaint.None)
                    {
                        continue;
                    }
                    string varName = (sqliTaintSet.InitialTaintedVariable ?? "???");
                    string message = "Stored SQLI found - Ingoing: " + varName +
                                    " on line: " + call.StartLine + " in file: " + analysisStacks.IncludeStack.Peek();

                    storage.AddPossibleStoredVulnerability(new StoredVulnerabilityInfo()
                    {
                        IncludeStack = analysisStacks.IncludeStack.ToImmutableStack(),
                        CallStack = analysisStacks.CallStack.ToImmutableStack(),
                        Message = message,
                        VulnerabilityType = VulnType.SQL,
                        PossibleStoredVuln = new StoredVulnInfo()
                                             {
                                                 ICantFeelIt = IsItInYet.YesItsGoingIn,
                                                 StorageName = optionKeyValue,
                                                 StorageOrigin = "Options",
                                                 Taint = new TaintSets(sqliTaintSet, new XSSTaintSet())
                                             }
                    });
                }
                foreach (var xssTaintSet in argumentInfos.ElementAt(1).Value.ExpressionTaint.XssTaint)
                {
                    if (xssTaintSet.TaintTag == XSSTaint.None)
                    {
                        continue;
                    }
                    string varName = (xssTaintSet.InitialTaintedVariable ?? "???");
                    string message = "Stored XSS found - Ingoing: " + varName +
                                    " on line: " + call.StartLine + " in file: " + analysisStacks.IncludeStack.Peek();

                    storage.AddPossibleStoredVulnerability(new StoredVulnerabilityInfo()
                    {
                        IncludeStack = analysisStacks.IncludeStack.ToImmutableStack(),
                        CallStack = analysisStacks.CallStack.ToImmutableStack(),
                        Message = message,
                        VulnerabilityType = VulnType.XSS,
                        PossibleStoredVuln = new StoredVulnInfo()
                                            {
                                                ICantFeelIt = IsItInYet.YesItsGoingIn,
                                                StorageName = optionKeyValue,
                                                StorageOrigin = "Options",
                                                Taint = new TaintSets(new SQLITaintSet(), xssTaintSet)
                                            }
                    });
                }
            }

            return exprInfo;
        }
开发者ID:jtvn,项目名称:Eir-CTLLTL,代码行数:66,代码来源:WPBlockAnalyzer.cs

示例11: MapToJSON

        /// <summary>
        /// Convert a given map to a JSON object.
        /// </summary>
        /// <param name="values">the map of values to be converted</param>
        /// <returns></returns>
        private IJSON MapToJSON( IDictionary<string, string> values )
        {
            using ( var stream = new MemoryStream() ) {

                var writer = new CBORWriter( stream );

                writer.WriteObject();
                for ( int i = 0; i < values.Count; i++ ) {
                    writer.Write( values.ElementAt( i ).Key );
                    writer.Write( values.ElementAt( i ).Value );
                }
                writer.WriteBreak();

                return jsonDataType.ReadValue( stream.ToArray() );
            }
        }
开发者ID:pushtechnology,项目名称:diffusion-examples,代码行数:21,代码来源:ControlClientUpdatingJSONTopics.cs


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