本文整理汇总了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("}\"", "},\"");
}
示例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);
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
示例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() );
}
}