/// <summary> /// Get the ParseInstance pointed to by a field. /// </summary> /// <param name="key"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="ParseInstance"/> /// </returns> public ParseInstance GetPointer(string key) { var h = json[key] as Hashtable; if (h == null) { return(null); } if ("Pointer" == (string)h["__type"]) { var className = (string)h["className"]; ParseInstance pi; if (className == "_User") { pi = ParseClass.users.Get((string)h["objectId"]); } else { pi = new ParseClass("/classes/" + className).Get((string)h["objectId"]); } return(pi); } else { return(null); } }
public void parseClassShouldWork() { //Data testClass tester = new testClass(); testComp.Add("boolTest", TableRep.DType.boolean); testComp.Add("byteTest", TableRep.DType.Tint); testComp.Add("shortTest", TableRep.DType.Sint); testComp.Add("intTest", TableRep.DType.Rint); testComp.Add("longTest", TableRep.DType.Lint); testComp.Add("decimalTest", TableRep.DType.dec); testComp.Add("doubleTest", TableRep.DType.dec); testComp.Add("charTest", TableRep.DType.ch); testComp.Add("sbyteTest", TableRep.DType.Rint); testComp.Add("ushortTest", TableRep.DType.Rint); testComp.Add("uintTest", TableRep.DType.Rint); testComp.Add("ulongTest", TableRep.DType.Lint); testComp.Add("stringTest", TableRep.DType.vchar); TableRep testTable = new TableRep(); testTable.setColumns(testComp); testTable.setTableName("tester"); TableRep comp = ParseClass.parseClass(tester); comp.setTableName("tester"); Assert.Equal(testTable.getColumns(), comp.getColumns()); Assert.Equal(testTable.getTableName(), comp.getTableName()); }
public static bool TryParse(string input, ParseClassStyles style, IFormatProvider provider, out ParseClass result) { switch (style) { case ParseClassStyles.None: break; case ParseClassStyles.IgnoreSpace: input = input.Replace(" ", ""); break; default: throw new FormatException(); } if (!input.StartsWith("ParseClass_")) { result = null; return(false); } else { result = new ParseClass(); result.Content = input; return(true); } }
public void ParseCheckValisNumber2_False() { // arrange Char input = 'd'; bool expected = false; // act bool result = ParseClass.CheckValid(input); // assert Assert.AreEqual(expected, result); }
public void Parse_2Plus3Minus5() { // arrange string input = "2+3-5"; ListMyNumber expected = new ListMyNumber(); expected.Add(new MyNumber(2, '1', '+')); expected.Add(new MyNumber(3, '+', '-')); expected.Add(new MyNumber(5, '-', '1')); // act ListMyNumber result = ParseClass.ParseList(input); // assert for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i].Value, result[i].Value); Assert.AreEqual(expected[i].Left, result[i].Left); Assert.AreEqual(expected[i].Right, result[i].Right); } }
static void UseParseMethod() { //将一个写成十六进制的字符串转化为Int32类型 string hex = "C9"; Int32 deci = Int32.Parse(hex, System.Globalization.NumberStyles.AllowHexSpecifier); hex = " -3 "; deci = Int32.Parse(hex); //-3 可见默认NumberStyles.Integer = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign //能用上Parse完全体的场合 hex = "$499"; //deci = Int32.Parse(hex, System.Globalization.NumberStyles.Currency, new System.Globalization.CultureInfo("zh-CN")); //Wrong, 该文化无法识别$ deci = Int32.Parse(hex, System.Globalization.NumberStyles.Currency, new System.Globalization.CultureInfo("en-US")); Console.WriteLine(deci.ToString()); ParseClass pc; ParseClass.TryParse(" ParseClass_qiqiqi", ParseClassStyles.IgnoreSpace, null, out pc); Console.WriteLine(pc.Content); }
// Use this for initialization IEnumerator Start() { //Register a new user var user = ParseClass.users.New(); user.Set("username", "simon"); user.Set("password", "xyzzy"); user.Create(); while(!user.isDone) yield return null; //check for error if(user.error != null) { //A message is printed automatically. We can diagnose the issue by examing the HTTP code. Debug.Log(user.code); } //Authenticate an existing user var auth_user = ParseClass.Authenticate("simon","xyzzy"); while(!auth_user.isDone) yield return null; //check for error if(auth_user.error != null) { Debug.Log("An error occured, likely a bad password!"); } //HOWTO: Create a new class var commentClass = new ParseClass("/classes/Comment"); //HOWTO: Add an instance to the class var comment = commentClass.New(); //HOWTO: Add fields to the instance. comment.Set("author", "Simon Wittber"); comment.Set("text", "This is a wise comment."); comment.Set("DOB", 1979); //HOWTO: Save the new instance. comment.Create(); //Wait until it's finished the save. while(!comment.isDone) yield return null; ///HOWTO: Get data back out of the instance. Debug.Log(comment.createdAt); Debug.Log(comment.Get<string>("author")); Debug.Log(comment.Get<string>("text")); //HOWTO: Update a field. comment.Set("author", "John Doe"); //HOWTO: Save the updated instance. comment.Update(); //Wait until it's finished the update. while(!comment.isDone) yield return null; //This is how to add a pointer in the comment instance to a user. comment.Set("user", auth_user); comment.Update(); //Wait until it's finished the update. while(!comment.isDone) yield return null; //This is how to get the user class back from a pointer. var record = comment.GetPointer("user"); while(!record.isDone) yield return null; Debug.Log(record.Get<string>("username")); //This is how to get all instances in a class which reference this instance in a field. //Eg. Find all comments which point to auth_user via their 'user' field. var comments = auth_user.FindReferencesIn(commentClass, "user"); while(!comments.isDone) yield return null; Debug.Log(comments.items.Length); }
// Use this for initialization IEnumerator Start() { //Register a new user var user = ParseClass.users.New(); user.Set("username", "simon"); user.Set("password", "xyzzy"); user.Create(); while (!user.isDone) { yield return(null); } //check for error if (user.error != null) { //A message is printed automatically. We can diagnose the issue by examing the HTTP code. Debug.Log(user.code); } //Authenticate an existing user var auth_user = ParseClass.Authenticate("simon", "xyzzy"); while (!auth_user.isDone) { yield return(null); } //check for error if (auth_user.error != null) { Debug.Log("An error occured, likely a bad password!"); } //HOWTO: Create a new class var commentClass = new ParseClass("/classes/Comment"); //HOWTO: Add an instance to the class var comment = commentClass.New(); //HOWTO: Add fields to the instance. comment.Set("author", "Simon Wittber"); comment.Set("text", "This is a wise comment."); comment.Set("DOB", 1979); //HOWTO: Save the new instance. comment.Create(); //Wait until it's finished the save. while (!comment.isDone) { yield return(null); } ///HOWTO: Get data back out of the instance. Debug.Log(comment.createdAt); Debug.Log(comment.Get <string>("author")); Debug.Log(comment.Get <string>("text")); //HOWTO: Update a field. comment.Set("author", "John Doe"); //HOWTO: Save the updated instance. comment.Update(); //Wait until it's finished the update. while (!comment.isDone) { yield return(null); } //This is how to add a pointer in the comment instance to a user. comment.Set("user", auth_user); comment.Update(); //Wait until it's finished the update. while (!comment.isDone) { yield return(null); } //This is how to get the user class back from a pointer. var record = comment.GetPointer("user"); while (!record.isDone) { yield return(null); } Debug.Log(record.Get <string>("username")); //This is how to get all instances in a class which reference this instance in a field. //Eg. Find all comments which point to auth_user via their 'user' field. var comments = auth_user.FindReferencesIn(commentClass, "user"); while (!comments.isDone) { yield return(null); } Debug.Log(comments.items.Length); }
/// <summary> /// Find all instances in otherClass which reference this instance in the field identified by key. /// </summary> /// <param name="otherClass"> /// A <see cref="ParseClass"/> /// </param> /// <param name="key"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="ParseInstanceCollection"/> /// </returns> public ParseInstanceCollection FindReferencesIn(ParseClass otherClass, string key) { var q = "where={\"" + key + "\": {\"__type\":\"Pointer\", \"className\":\"" + parseClass.className + "\", \"objectId\":\"" + objectId + "\"}} "; return(otherClass.List(q)); }
public ParseInstance(ParseClass parseClass) { this.parseClass = parseClass; }
public ParseInstanceCollection(ParseClass parseClass) { this.parseClass = parseClass; }