public static bool CheckValueExist <T>(CompositionPropertySet properties, string propName) where T : struct { var status = CompositionGetValueStatus.NotFound; if (typeof(T) == typeof(float)) { status = properties.TryGetScalar(propName, out _); } if (typeof(T) == typeof(Vector2)) { status = properties.TryGetVector2(propName, out _); } if (typeof(T) == typeof(Vector3)) { status = properties.TryGetVector3(propName, out _); } if (typeof(T) == typeof(Vector4)) { status = properties.TryGetVector4(propName, out _); } if (typeof(T) == typeof(Quaternion)) { status = properties.TryGetQuaternion(propName, out _); } return(status == CompositionGetValueStatus.Succeeded); }
public static CompositionGetValueStatus TryGetValue <T>(CompositionPropertySet properties, string propName, out T value) { var status = CompositionGetValueStatus.NotFound; value = default; if (typeof(T) == typeof(float)) { status = properties.TryGetScalar(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector2)) { status = properties.TryGetVector2(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector3)) { status = properties.TryGetVector3(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector4)) { status = properties.TryGetVector4(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Quaternion)) { status = properties.TryGetQuaternion(propName, out var v); value = (T)(object)v; } return(status); }
public static T Get <T>(this CompositionPropertySet propSet, string key) { var type = typeof(T); if (type == typeof(float)) { float res; if (propSet.TryGetScalar(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector2)) { Vector2 res; if (propSet.TryGetVector2(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector3)) { Vector3 res; if (propSet.TryGetVector3(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector4)) { Vector4 res; if (propSet.TryGetVector4(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Matrix3x2)) { Matrix3x2 res; if (propSet.TryGetMatrix3x2(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Matrix4x4)) { Matrix4x4 res; if (propSet.TryGetMatrix4x4(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Quaternion)) { Quaternion res; if (propSet.TryGetQuaternion(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Color)) { Color res; if (propSet.TryGetColor(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } throw new ArgumentException("Unsupported type"); }