Ejemplo n.º 1
0
        public static void SetValueByName(this ID2D1Properties properties, string name, object value)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (value is null)
            {
                SetValueByName(properties, name, null);
                return;
            }

            var type = value.GetType();

            if (type.IsEnum)
            {
                value = (int)value;
            }

            if (value is bool bv)
            {
                SetValueByName(properties, name, bv);
                return;
            }

            if (value is Guid gv)
            {
                SetValueByName(properties, name, gv);
                return;
            }

            if (value is float fv)
            {
                SetValueByName(properties, name, fv);
                return;
            }

            if (value is uint uiv)
            {
                SetValueByName(properties, name, uiv);
                return;
            }

            if (value is int iv)
            {
                SetValueByName(properties, name, iv);
                return;
            }

            if (value is byte[] byv)
            {
                SetValueByName(properties, name, byv);
                return;
            }

            if (value is string sv)
            {
                SetValueByName(properties, name, sv);
                return;
            }

            if (value is ValueType vt) // matrix & vector types
            {
                using (var mem = new ComMemory(vt))
                {
                    SetValueByName(properties, name, mem.ToArray());
                    return;
                }
            }
            throw new NotSupportedException("Value of type '" + value.GetType().FullName + "' is not supported.");
        }
Ejemplo n.º 2
0
        public static void SetValue(this ID2D1Properties properties, int index, object value)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (value is null)
            {
                SetValue(properties, index, null);
                return;
            }

            if (value is bool bv)
            {
                SetValue(properties, index, bv);
                return;
            }

            if (value is Guid gv)
            {
                SetValue(properties, index, gv);
                return;
            }

            if (value is float fv)
            {
                SetValue(properties, index, fv);
                return;
            }

            if (value is uint uiv)
            {
                SetValue(properties, index, uiv);
                return;
            }

            if (value is int iv)
            {
                SetValue(properties, index, iv);
                return;
            }

            if (value is byte[] byv)
            {
                SetValue(properties, index, byv);
                return;
            }

            if (value is string sv)
            {
                SetValue(properties, index, sv);
                return;
            }

            if (value is ValueType vt)
            {
                using (var mem = new ComMemory(vt))
                {
                    SetValue(properties, index, mem.ToArray());
                    return;
                }
            }
            throw new NotSupportedException("Value of type '" + value.GetType().FullName + "' is not supported.");
        }