예제 #1
0
 public static Vector3 GetVector(this KeyValuePairs kvp, string key, Vector3 _default)
 {
     if (kvp.ContainsKey(key))
     {
         string[] str = kvp.GetString(key).Split(',');
         if (str.Length >= 3)
         {
             float x, y, z;
             if (float.TryParse(str[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out x) &&
                 float.TryParse(str[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out y) &&
                 float.TryParse(str[2].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out z))
             {
                 return(new Vector3(x, y, z));
             }
         }
     }
     return(_default);
 }
예제 #2
0
 public static void SetIntegerArray(this KeyValuePairs kvp, string key, int[] value)
 {
     if (value != null)
     {
         var joined = new StringBuilder();
         for (int i = 0; i < value.Length; ++i)
         {
             joined.Append(value[i].ToString(CultureInfo.InvariantCulture));
             if (i < value.Length - 1)
             {
                 joined.Append(',');
             }
         }
         kvp.Set(key, joined.ToString());
     }
     else
     {
         kvp.Remove(key);
     }
 }
예제 #3
0
 public static string[] GetStringArray(this KeyValuePairs kvp, string key, string[] _default)
 {
     if (kvp.ContainsKey(key))
     {
         var value = kvp.GetString(key);
         if (value.Length > 0)
         {
             var array = kvp.GetString(key).Split(',');
             for (int i = 0; i < array.Length; ++i)
             {
                 array[i] = array[i].Trim();
             }
             return(array);
         }
         else
         {
             return(new string[0]);
         }
     }
     return(_default);
 }
예제 #4
0
 public static void SetGUID(this KeyValuePairs kvp, string key, Guid value)
 {
     kvp.Set(key, value.ToString());
 }