holopy3/Assets/UniGLTF/UniJSON/Scripts/Extensions/ObjectExtensions.cs
Lena Biresch 490ef558ef CleanUp
2021-01-28 13:07:52 +01:00

36 lines
799 B
C#

using System;
using System.Collections;
namespace UniJSON
{
public static class ObjectExtensions
{
public static Object GetValueByKey(this Object self, String key)
{
var t = self.GetType();
var fi = t.GetField(key);
if (fi != null)
{
return fi.GetValue(self);
}
var pi = t.GetProperty(key);
if (pi != null)
{
return fi.GetValue(self);
}
throw new ArgumentException();
}
public static int GetCount(this object self)
{
var count = 0;
foreach (var x in self as IEnumerable)
{
++count;
}
return count;
}
}
}