예제 #1
0
        private bool SetPropertyValue(object obj, PropertyInfo pi, BinaryReader reader)
        {
            object obj2;

            if (pi != null)
            {
                obj2 = null;
                if (pi.PropertyType == typeof(bool))
                {
                    obj2 = reader.ReadBoolean();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(double))
                {
                    obj2 = reader.ReadDouble();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(string))
                {
                    obj2 = reader.ReadString();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(int))
                {
                    obj2 = reader.ReadInt32();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(long))
                {
                    obj2 = reader.ReadInt64();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(float))
                {
                    obj2 = reader.ReadSingle();
                    goto IL_02de;
                }
                if (pi.PropertyType.IsEnum)
                {
                    obj2 = Enum.Parse(pi.PropertyType, reader.ReadString());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(byte))
                {
                    obj2 = reader.ReadByte();
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Font))
                {
                    obj2 = SerializerBase.FontFromString(reader.ReadString());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Color))
                {
                    obj2 = Color.FromArgb(reader.ReadInt32());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(DateTime))
                {
                    obj2 = new DateTime(reader.ReadInt64());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Size))
                {
                    obj2 = new Size(reader.ReadInt32(), reader.ReadInt32());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Margins))
                {
                    obj2 = new Margins(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(double[]))
                {
                    double[] array = new double[reader.ReadInt32()];
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = reader.ReadDouble();
                    }
                    obj2 = array;
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Color[]))
                {
                    Color[] array2 = new Color[reader.ReadInt32()];
                    for (int j = 0; j < array2.Length; j++)
                    {
                        array2[j] = Color.FromArgb(reader.ReadInt32());
                    }
                    obj2 = array2;
                    goto IL_02de;
                }
                if (pi.PropertyType == typeof(Image))
                {
                    int          num          = reader.ReadInt32();
                    MemoryStream memoryStream = new MemoryStream(num + 10);
                    memoryStream.Write(reader.ReadBytes(num), 0, num);
                    obj2 = new Bitmap(Image.FromStream(memoryStream));
                    memoryStream.Close();
                    goto IL_02de;
                }
                throw new InvalidOperationException(SR.ExceptionChartSerializerBinaryTypeUnsupported(obj.GetType().ToString()));
            }
            goto IL_02f8;
IL_02de:
            if (base.IsSerializableContent(pi.Name, obj))
            {
                pi.SetValue(obj, obj2, null);
                return(true);
            }
            goto IL_02f8;
IL_02f8:
            return(false);
        }
예제 #2
0
        private void SetXmlValue(object obj, string attrName, string attrValue)
        {
            PropertyInfo property = obj.GetType().GetProperty(attrName);

            if (property != null)
            {
                object value = attrValue;
                if (property.PropertyType == typeof(string))
                {
                    value = attrValue;
                }
                else if (property.PropertyType == typeof(Font))
                {
                    value = SerializerBase.FontFromString(attrValue);
                }
                else if (property.PropertyType == typeof(Color))
                {
                    value = (Color)SerializerBase.colorConverter.ConvertFromString(null, CultureInfo.InvariantCulture, attrValue);
                }
                else if (property.PropertyType == typeof(Image))
                {
                    value = SerializerBase.ImageFromString(attrValue);
                }
                else
                {
                    PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(obj)[attrName];
                    bool flag = false;
                    if (propertyDescriptor != null)
                    {
                        try
                        {
                            TypeConverterAttribute typeConverterAttribute = (TypeConverterAttribute)propertyDescriptor.Attributes[typeof(TypeConverterAttribute)];
                            if (typeConverterAttribute != null && typeConverterAttribute.ConverterTypeName.Length > 0)
                            {
                                Assembly      assembly      = Assembly.GetAssembly(base.GetType());
                                string[]      array         = typeConverterAttribute.ConverterTypeName.Split(',');
                                TypeConverter typeConverter = (TypeConverter)assembly.CreateInstance(array[0]);
                                if (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                                {
                                    value = typeConverter.ConvertFromString(null, CultureInfo.InvariantCulture, attrValue);
                                    flag  = true;
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        if (!flag && propertyDescriptor.Converter != null && propertyDescriptor.Converter.CanConvertFrom(typeof(string)))
                        {
                            value = propertyDescriptor.Converter.ConvertFromString(null, CultureInfo.InvariantCulture, attrValue);
                        }
                    }
                }
                property.SetValue(obj, value, null);
                return;
            }
            if (base.IgnoreUnknownAttributes)
            {
                return;
            }
            throw new InvalidOperationException(SR.ExceptionChartSerializerPropertyNameUnknown(attrName, obj.GetType().ToString()));
        }