本文整理汇总了C#中JToken.Count方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.Count方法的具体用法?C# JToken.Count怎么用?C# JToken.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecompressBullet
public Bullet DecompressBullet(JToken token)
{
Bullet bullet = null;
if(token.Count<object>() != 0)
{
bullet = new Bullet((int)token[0]);
bullet.Position.X = (float)token[1];
bullet.Position.Y = (float)token[2];
bullet.Velocity.X = (float)token[3];
bullet.Velocity.Y = (float)token[4];
}
return bullet;
}
示例2: DeserializeBot
Bot DeserializeBot(JToken token)
{
Bot bot = null;
if (token.Count<object>() != 0)
{
bot = new Bot();
bot.Id = (int)token[0];
bot.Movement.Position.X = (float)token[1];
bot.Movement.Position.Y = (float)token[2];
bot.Movement.Velocity.X = (float)token[3];
bot.Movement.Velocity.Y = (float)token[4];
bot.Movement.Acceleration.X = (float)token[5];
bot.Movement.Acceleration.Y = (float)token[6];
}
return bot;
}
示例3: DecompressShip
public Ship DecompressShip(JToken token)
{
Ship ship = null;
if (token.Count<object>() != 0)
{
ship = new Ship((int)token[0]);
ship.Position.X = (float)token[1];
ship.Position.Y = (float)token[2];
ship.Velocity.X = (float)token[3];
ship.Velocity.Y = (float)token[4];
ship.Acceleration.X = (float)token[5];
ship.Acceleration.Y = (float)token[6];
ship.Rotation = (float)token[7];
ship.Alive = (bool)token[8];
ship.Health = (float)token[9];
}
return ship;
}
示例4: Deserialize
Ship Deserialize(JToken token)
{
Ship ship = null;
if (token.Count<object>() != 0)
{
ship = new Ship(null);
ship.Id = (int)token[0];
ship.Movement.Position.X = (float)token[1];
ship.Movement.Position.Y = (float)token[2];
ship.Movement.Velocity.X = (float)token[3];
ship.Movement.Velocity.Y = (float)token[4];
ship.Movement.Acceleration.X = (float)token[5];
ship.Movement.Acceleration.Y = (float)token[6];
ship.Movement.Rotation = (float)token[7];
ship.Health.Alive = (bool)token[8];
ship.Health.Health = (int)token[9];
}
return ship;
}
示例5: ToInvokationBlock
public InvokationBlock ToInvokationBlock(JToken json)
{
string name = json[0].ToString();
string typeFingerPrint = json[1].ToString();
string retTypeName = json[2].ToString();
TypeCheck(name, typeFingerPrint);
DataType[] argTypes = DataTypeNames.DecodeFingerprint(typeFingerPrint);
DataType retType = DataTypeNames.TypeOf(retTypeName);
List<IBlock> args = new List<IBlock>();
for (int i = 3; i < json.Count(); ++i)
{
args.Add(ToBlock(json[i]));
}
BlockAttributes attr;
if (!blockSpace.RegisteredMethodAttribute(name, out attr))
{
attr = BlockAttributes.Stack;
}
InvokationBlock ib = new InvokationBlock(name, attr, argTypes, retType);
ib.Args.AddRange(args.ToArray(), argTypes.ToArray());
return ib;
}
示例6: ConvertHighScoresToTables
/// <summary>
/// Converts a list of high scores into rank tables
/// </summary>
/// <param name="highscores">Highscores.</param>
/// <returns>The returned object is a dictionary of the following format:
/// {
/// "world": {
/// "title": "World",
/// "highscores": [ ... array of high scores ...]
/// },
/// "country": {
/// "title": "Switzerland",
/// "highscores": [ ... array of high scores ...]
/// },
/// ...
/// }
/// </returns>
public static JToken ConvertHighScoresToTables(JToken highscores) {
JObject tables = new JObject ();
for (int i = 0; i < highscores.Count(); ++i) {
JObject highscore = (JObject)highscores[i];
foreach (JProperty rankType in highscore["ranks"]){
JObject rankTable;
if (tables[rankType.Name] == null){
rankTable = new JObject();
if (rankType.Name == "friends") {
rankTable.Add("title", "Friends");
} else if (rankType.Name == "world") {
rankTable.Add("title", "World");
} else if (rankType.Name == "country" || rankType.Name == "region" || rankType.Name == "city") {
rankTable.Add("title", highscore["location_" + rankType.Name + "_name"]);
}
tables[rankType.Name] = rankTable;
} else {
rankTable = (JObject)tables[rankType.Name];
}
if (rankTable["highscores"] == null){
rankTable.Add("highscores", new JArray());
}
((JArray)rankTable["highscores"]).Add(highscore);
}
}
return tables;
}
示例7: SelectBestGhosts
/// <summary>
/// <para>Given a list of high scores, returns the best high scores for ghost mode.
/// Preference in order:</para>
/// <para>- First, Ghosts with similar scores</para>
/// <para>- Then, sort by connected players, friends, city, region, country, world</para>
/// <para>If multiple Ghosts have the same preference score, random ones are chosen</para>
/// </summary>
/// <param name="highscores">Highscores.</param>
/// <param name="count">How many ghosts you would like to get.</param>
/// <param name="count">Optimal minimum score factor a ghost needs to have compared to the best score of a connected player. Default is 0.75f.</param>
/// <param name="count">Optimal maximum score factor a ghost needs to have compared to the best score of a connected player. Default is 1.5f.</param>
/// <returns>List of highscore entries that are best suited for ghost mode.</returns>
public static JToken SelectBestGhosts(JToken highscores, int count, float minScoreFactor = 0.75f, float maxScoreFactor = 1.5f){
float myScore = -1;
List<JToken> candidates = new List<JToken>();
for (int i = 0; i < highscores.Count(); ++i) {
JObject highscore = (JObject)highscores [i];
if (highscore["relationship"].ToString() == "requested"){
if (myScore == -1 || myScore < (float)highscore["score"]) {
myScore = (float)highscore["score"];
}
}
candidates.Add (highscore);
}
JObject preference = new JObject ();
preference.Add("world", 1);
preference.Add("country", 2);
preference.Add("region", 3);
preference.Add("city", 4);
preference.Add("friends", 5);
preference.Add("similar_score", 10);
preference.Add("requested", 20);
int randomUID = Mathf.FloorToInt(Random.value * 65536);
int randomUIDChar = Mathf.FloorToInt(Random.value * 32);
JArray result = new JArray ();
foreach (JToken candidate in candidates.OrderBy (element => SortScore (element, preference, myScore, minScoreFactor, maxScoreFactor, randomUID, randomUIDChar))) {
result.Add(candidate);
if (result.Count() == count){
break;
}
}
return result;
}
示例8: Position
/// <summary>
/// Initializes a new instance of the <see cref="Position"/> class.
/// </summary>
/// <param name="token">
/// The <see cref="JToken"/> holding 2 or three doubles.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="token"/> holds less than 2 values.
/// </exception>
public Position(JToken token)
{
if (token.Count() < 2)
{
throw new ArgumentException(
string.Format("Expected at least 2 elements, got {0}", token.Count()),
"token");
}
this.P1 = (double)token[0];
this.P2 = (double)token[1];
if (token.Count() > 2)
{
this.P3 = (double)token[2];
if (token.Count() > 3)
{
this.P4 = (double)token[3];
}
}
}
示例9: OptionsEqual
static bool OptionsEqual (IList<string> native, JToken json)
{
if (native.Count != json.Count ())
return false;
return native.All (opt => json.Any (j => opt == j.ToObject<string> ()));
}
示例10: EnvironmentVariablesEqual
static bool EnvironmentVariablesEqual (IDictionary<string, string> native, JToken json)
{
if (native.Count != json.Count ())
return false;
foreach (var kv in native) {
var jsonValue = json.Value<string> (kv.Key);
if (jsonValue == null)
return false;
if (jsonValue != kv.Value)
return false;
}
return true;
}
示例11: AssertPropertyValuesMatch
private bool AssertPropertyValuesMatch(JToken httpBody1, JToken httpBody2)
{
switch (httpBody1.Type)
{
case JTokenType.Array:
{
if (httpBody1.Count() != httpBody2.Count())
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
for (var i = 0; i < httpBody1.Count(); i++)
{
if (httpBody2.Count() > i)
{
var isMatch = AssertPropertyValuesMatch(httpBody1[i], httpBody2[i]);
if (!isMatch)
{
break;
}
}
}
break;
}
case JTokenType.Object:
{
foreach (JProperty item1 in httpBody1)
{
var item2 = httpBody2.Cast<JProperty>().SingleOrDefault(x => x.Name == item1.Name);
if (item2 != null)
{
var isMatch = AssertPropertyValuesMatch(item1, item2);
if (!isMatch)
{
break;
}
}
else
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
}
break;
}
case JTokenType.Property:
{
var httpBody2Item = httpBody2.SingleOrDefault();
var httpBody1Item = httpBody1.SingleOrDefault();
if (httpBody2Item == null && httpBody1Item == null)
{
return true;
}
if (httpBody2Item != null && httpBody1Item != null)
{
AssertPropertyValuesMatch(httpBody1Item, httpBody2Item);
}
else
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
case JTokenType.Integer:
case JTokenType.String:
{
if (!httpBody1.Equals(httpBody2))
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
default:
{
if (!JToken.DeepEquals(httpBody1, httpBody2))
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
}
return true;
}
示例12: Export
public override string Export(JToken[] jObject)
{
string fileName = "";
try
{
if (jObject == null || jObject.Length<=0)
{
throw new KMJXCException("没有符合要求的采购数据,不能导出");
}
Worksheet sheet = (Worksheet)this.WorkBook.ActiveSheet;
sheet.Name = "采购报表";
int startRow = 2;
object[,] os = new object[jObject.Length, 5];
for (int i = 0; i < jObject.Count(); i++)
{
JToken obj = (JToken)jObject[i];
string productName = obj["product_name"].ToString();
string propName = obj["prop_name"].ToString();
string month = obj["month"].ToString();
string quantity = obj["quantity"].ToString();
string amount = obj["amount"].ToString();
os[i, 0] = productName;
os[i, 1] = propName;
os[i, 2] = month;
os[i, 3] = quantity;
os[i, 4] = amount;
}
Range range1 = sheet.Cells[startRow, 1];
Range range2 = sheet.Cells[startRow + jObject.Length - 1, 5];
Range range = sheet.get_Range(range1, range2);
range.Value2 = os;
Worksheet pivotTableSheet = (Worksheet)this.WorkBook.Worksheets[2];
pivotTableSheet.Name = "采购透视表";
PivotCaches pch = WorkBook.PivotCaches();
sheet.Activate();
pch.Add(XlPivotTableSourceType.xlDatabase, "'" + sheet.Name + "'!A1:'" + sheet.Name + "'!E" + (jObject.Count() + 1)).CreatePivotTable(pivotTableSheet.Cells[4, 1], "PivTbl_1", Type.Missing, Type.Missing);
PivotTable pvt = pivotTableSheet.PivotTables("PivTbl_1") as PivotTable;
pvt.Format(XlPivotFormatType.xlTable1);
pvt.TableStyle2 = "PivotStyleLight16";
pvt.InGridDropZones = true;
foreach (PivotField pf in pvt.PivotFields() as PivotFields)
{
pf.ShowDetail = false;
}
PivotField productField = (PivotField)pvt.PivotFields("产品");
productField.Orientation = XlPivotFieldOrientation.xlRowField;
productField.set_Subtotals(1, false);
PivotField propField = (PivotField)pvt.PivotFields("属性");
propField.Orientation = XlPivotFieldOrientation.xlRowField;
propField.set_Subtotals(1, false);
PivotField monthField = (PivotField)pvt.PivotFields("年月");
monthField.Orientation = XlPivotFieldOrientation.xlRowField;
monthField.set_Subtotals(1, false);
pvt.AddDataField(pvt.PivotFields(4), "采购数量", XlConsolidationFunction.xlSum);
pvt.AddDataField(pvt.PivotFields(5), "采购金额", XlConsolidationFunction.xlSum);
((PivotField)pvt.DataFields["采购数量"]).NumberFormat = "#,##0";
((PivotField)pvt.DataFields["采购金额"]).NumberFormat = "#,##0";
pivotTableSheet.Activate();
this.WorkBook.Saved = true;
this.WorkBook.SaveCopyAs(this.ReportFilePath);
this.WorkBook.Close();
}
catch (Exception ex)
{
throw ex;
}
return fileName;
}
示例13: Tickers
public Tickers(JToken jsonObj)
{
tickers = new Dictionary<TickerType, Ticker>();
string[] tickerNames = { "avg", "high", "low", "vwap", "last_all", "last_local", "last_orig", "last", "buy", "sell", "vol" };
foreach (string tickName in tickerNames)
{
if (jsonObj.Count() == 2) //we have the REST API schema
{
Ticker tick = new Ticker(jsonObj["data"][tickName], tickName);
tickers[tick.tickerType] = tick;
}
else // we have the socketIO schema
{
JToken token = jsonObj[tickName];
Ticker tick = new Ticker(token, tickName);
tickers[tick.tickerType] = tick;
}
}
}
示例14: ToBlockStack
private IBlock ToBlockStack(JToken json)
{
BlockStack b = new BlockStack();
for (int i = 1; i < json.Count(); ++i)
{
IBlock subBlock = ToBlock(json[i]);
if (i == 1 && subBlock is ProcDefBlock)
currentProcDef = subBlock as ProcDefBlock;
b.Add(subBlock);
}
currentProcDef = null;
return b;
}
示例15: DeserializeBullet
Bullet DeserializeBullet(JToken token)
{
Bullet bullet = null;
if (token.Count<object>() != 0)
{
bullet = new Bullet(Vector2.Zero, Vector2.Zero, null);
bullet.Id = (int)token[0];
bullet.Movement.Position.X = (float)token[1];
bullet.Movement.Position.Y = (float)token[2];
bullet.Movement.Velocity.X = (float)token[3];
bullet.Movement.Velocity.Y = (float)token[4];
}
return bullet;
}