Example #1
0
 public static object ToObject(Type type, LLSD value)
 {
     if (type == typeof(ulong))
     {
         if (value.Type == LLSDType.Binary)
         {
             byte[] bytes = value.AsBinary();
             return(Utils.BytesToUInt64(bytes));
         }
         else
         {
             return((ulong)value.AsInteger());
         }
     }
     else if (type == typeof(uint))
     {
         if (value.Type == LLSDType.Binary)
         {
             byte[] bytes = value.AsBinary();
             return(Utils.BytesToUInt(bytes));
         }
         else
         {
             return((uint)value.AsInteger());
         }
     }
     else if (type == typeof(ushort))
     {
         return((ushort)value.AsInteger());
     }
     else if (type == typeof(byte))
     {
         return((byte)value.AsInteger());
     }
     else if (type == typeof(short))
     {
         return((short)value.AsInteger());
     }
     else if (type == typeof(string))
     {
         return(value.AsString());
     }
     else if (type == typeof(bool))
     {
         return(value.AsBoolean());
     }
     else if (type == typeof(float))
     {
         return((float)value.AsReal());
     }
     else if (type == typeof(double))
     {
         return(value.AsReal());
     }
     else if (type == typeof(int))
     {
         return(value.AsInteger());
     }
     else if (type == typeof(UUID))
     {
         return(value.AsUUID());
     }
     else if (type == typeof(Vector3))
     {
         if (value.Type == LLSDType.Array)
         {
             return(((LLSDArray)value).AsVector3());
         }
         else
         {
             return(Vector3.Zero);
         }
     }
     else if (type == typeof(Vector4))
     {
         if (value.Type == LLSDType.Array)
         {
             return(((LLSDArray)value).AsVector4());
         }
         else
         {
             return(Vector4.Zero);
         }
     }
     else if (type == typeof(Quaternion))
     {
         if (value.Type == LLSDType.Array)
         {
             return(((LLSDArray)value).AsQuaternion());
         }
         else
         {
             return(Quaternion.Identity);
         }
     }
     else
     {
         return(null);
     }
 }