static object Unbox()

in winrt/test.managed/EffectTests.cs [497:630]


        static object Unbox(object value, PropertyInfo property)
        {
            Type type = property.PropertyType;

            if (type == typeof(int) ||
                type == typeof(bool) ||
                type == typeof(float[]))
            {
                return value;
            }
            else if (type == typeof(float))
            {
                if (NeedsRadianToDegreeConversion(property))
                {
                    return (float)value * (float)Math.PI / 180f;
                }
                else
                {
                    return value;
                }
            }
            else if (type.GetTypeInfo().IsEnum)
            {
                return GetEnumValues(type).GetValue((int)(uint)value);
            }
            else if (type == typeof(Vector2))
            {
                var a = (float[])value;
                Assert.AreEqual(2, a.Length);

                return new Vector2
                { 
                    X = a[0], 
                    Y = a[1], 
                };
            }
            else if (type == typeof(Vector3))
            {
                var a = (float[])value;
                Assert.AreEqual(3, a.Length);

                return new Vector3
                {
                    X = a[0],
                    Y = a[1],
                    Z = a[2],
                };
            }
            else if (type == typeof(Vector4))
            {
                var a = (float[])value;
                Assert.AreEqual(4, a.Length);

                return new Vector4
                {
                    X = a[0],
                    Y = a[1],
                    Z = a[2],
                    W = a[3],
                };
            }
            else if (type == typeof(Matrix3x2))
            {
                var a = (float[])value;
                Assert.AreEqual(6, a.Length);

                return new Matrix3x2
                { 
                    M11 = a[0], M12 = a[1], 
                    M21 = a[2], M22 = a[3], 
                    M31 = a[4], M32 = a[5],
                };
            }
            else if (type == typeof(Matrix4x4))
            {
                var a = (float[])value;
                Assert.AreEqual(16, a.Length);

                return new Matrix4x4
                { 
                    M11 = a[0],  M12 = a[1],  M13 = a[2],  M14 = a[3],
                    M21 = a[4],  M22 = a[5],  M23 = a[6],  M24 = a[7],
                    M31 = a[8],  M32 = a[9],  M33 = a[10], M34 = a[11],
                    M41 = a[12], M42 = a[13], M43 = a[14], M44 = a[15],
                };
            }
            else if (type == typeof(Matrix5x4))
            {
                var a = (float[])value;
                Assert.AreEqual(20, a.Length);

                return new Matrix5x4
                { 
                    M11 = a[0],  M12 = a[1],  M13 = a[2],  M14 = a[3],
                    M21 = a[4],  M22 = a[5],  M23 = a[6],  M24 = a[7],
                    M31 = a[8],  M32 = a[9],  M33 = a[10], M34 = a[11],
                    M41 = a[12], M42 = a[13], M43 = a[14], M44 = a[15],
                    M51 = a[16], M52 = a[17], M53 = a[18], M54 = a[19],
                };
            }
            else if (type == typeof(Rect))
            {
                var a = (float[])value;
                Assert.AreEqual(4, a.Length);

                return new Rect(new Point(a[0], a[1]), 
                                new Point(a[2], a[3]));
            }
            else if (type == typeof(Windows.UI.Color))
            {
                var a = ConvertRgbToRgba((float[])value);
                Assert.AreEqual(4, a.Length);

                return Windows.UI.Color.FromArgb((byte)(a[3] * 255),
                                      (byte)(a[0] * 255),
                                      (byte)(a[1] * 255),
                                      (byte)(a[2] * 255));
            }
            else if (type == typeof(ColorManagementProfile)
#if WINDOWS_UWP
                  || type == typeof(EffectTransferTable3D)
#endif
                    )
            {
                var a = (object[])value;
                Assert.AreEqual(1, a.Length);

                return a[0];
            }
            else
            {
                throw new NotSupportedException("Unsupported Unbox type " + type);
            }
        }