Beispiel #1
0
        public void SetValue <T>(T obj, object value)
            where T : CadObject
        {
            if (_property.PropertyType.IsEquivalentTo(typeof(XY)))
            {
                XY vector = (XY)_property.GetValue(obj);

                int      index      = (this.Code / 10) % 10 - 1;
                double[] components = vector.GetComponents();
                components[index] = Convert.ToDouble(value);

                vector = vector.SetComponents(components);

                this._property.SetValue(obj, vector);
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(XYZ)))
            {
                XYZ vector = (XYZ)_property.GetValue(obj);

                int      index      = (this.Code / 10) % 10 - 1;
                double[] components = vector.GetComponents();
                components[index] = Convert.ToDouble(value);

                vector = vector.SetComponents(components);

                this._property.SetValue(obj, vector);
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(Color)))
            {
                //TODO: Implement color setter

                switch (this.Code)
                {
                case 62:
                    this._property.SetValue(obj, new Color((short)value));
                    break;

                case 420:
                    // true color
                    break;

                case 430:
                    // dictionary color
                    break;
                }
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(PaperMargin)))
            {
                PaperMargin margin = (PaperMargin)_property.GetValue(obj);

                switch (this.Code)
                {
                //40	Size, in millimeters, of unprintable margin on left side of paper
                case 40:
                    margin = new PaperMargin((double)value, margin.Bottom, margin.Right, margin.Top);
                    break;

                //41	Size, in millimeters, of unprintable margin on bottom of paper
                case 41:
                    margin = new PaperMargin(margin.Left, (double)value, margin.Right, margin.Top);
                    break;

                //42	Size, in millimeters, of unprintable margin on right side of paper
                case 42:
                    margin = new PaperMargin(margin.Left, margin.Bottom, (double)value, margin.Top);
                    break;

                //43	Size, in millimeters, of unprintable margin on top of paper
                case 43:
                    margin = new PaperMargin(margin.Left, margin.Bottom, margin.Right, (double)value);
                    break;
                }

                this._property.SetValue(obj, margin);
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(Transparency)))
            {
                //TODO: Implement transparency setter
                //this._property.SetValue(obj, new Transparency((short)value));
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(bool)))
            {
                this._property.SetValue(obj, Convert.ToBoolean(value));
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(char)))
            {
                this._property.SetValue(obj, Convert.ToChar(value));
            }
            else if (_property.PropertyType.IsEquivalentTo(typeof(byte)))
            {
                this._property.SetValue(obj, Convert.ToByte(value));
            }
            else if (_property.PropertyType.IsEnum)
            {
                this._property.SetValue(obj, Enum.ToObject(_property.PropertyType, value));
            }
            else
            {
                this._property.SetValue(obj, value);
            }
        }