Exemplo n.º 1
0
 /// <summary>
 /// Converts a string representation of an object to the actual object.
 /// </summary>
 /// <param name="serialised">The string representation of the object.</param>
 /// <returns>A native object converted from the string representation.</returns>
 public static fishBytesNativeObject FromString(string serialised)
 {
     fishBytesNativeObject obj = new fishBytesNativeObject();
     var serialisedArr = serialised.ToCharArray().ToList();
     serialisedArr.RemoveAt(0);
     serialisedArr.RemoveAt(serialisedArr.Count - 1);
     serialised = new string(serialisedArr.ToArray());
     uint objlvl = 0;
     string eobj = "";
     string name = "";
     string Obj = "";
     bool isName = true;
     foreach (char c in serialised)
     {
         if (objlvl == 1)
         {
             eobj += c;
         }
         else if (c == '{')
         {
             objlvl = 1;
             eobj = "";
         }
         else if (c == '}')
         {
             objlvl = 0;
             obj.Set(GetStructFromString(name), FromString(eobj));
         }
         else if (objlvl == 0)
         {
             if (isName)
             {
                 if (c == ':')
                 {
                     Obj = "";
                 }
                 else name += c;
             }
             else
             {
                 if (c == ',')
                 {
                     name = "";
                     obj.Set(GetStructFromString(name), GetStructFromString(Obj));
                 }
                 else Obj += c;
             }
         }
         else
         {
             throw new Exception("Something is wrong with our code. We will try and" +
                 $" solve this as soon as possible. Error code: OBJLVL_EQ_{objlvl}");
         }
     }
     return obj;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Construct an object from the specified template object.
 /// </summary>
 /// <returns>The object.</returns>
 /// <param name="template">A template opject to use.</param>
 public static fishBytesNativeObject Construct(fishBytesNativeObject template)
 {
     return new fishBytesNativeObject(template.properties);
 }