protected internal virtual void RaiseDeserializeCustomProperties(SerializeCustomPropertiesEventArgs args) { if (DeserializeCustomProperties != null) { DeserializeCustomProperties(this, args); } }
private void myGridView1_DeserializeCustomProperties(object sender, SerializeCustomPropertiesEventArgs e) { if (e.SerializationObject == colID) { e.PropertyNames = new string[] { "ABC", "123", "Tag" } } ; }
protected override IXtraPropertyCollection SerializeObjectCore(object obj, XtraSerializationFlags parentFlags, OptionsLayoutBase options) { if (rootObject == null || !(rootObject is MyGridView)) { return(base.SerializeObjectCore(obj, parentFlags, options)); } XtraPropertyInfoCollection properties = base.SerializeObjectCore(obj, parentFlags, options) as XtraPropertyInfoCollection; for (int i = properties.Count - 1; i >= 0; i--) { AllowSerializePropertyEventArgs allowArgs = new AllowSerializePropertyEventArgs(obj, properties[i].Name, properties[i].PropertyType, properties[i].Value); ((MyGridView)rootObject).RaiseAllowSerialzeProperty(allowArgs); if (!allowArgs.SerializeProperty) { properties.RemoveAt(i); } } SerializeCustomPropertiesEventArgs customArgs = new SerializeCustomPropertiesEventArgs(obj); ((MyGridView)rootObject).RaiseSerializeCustomProperties(customArgs); if (customArgs.PropertyNames == null || customArgs.PropertyNames.Length == 0) { return(properties); } for (int i = 0; i < customArgs.PropertyNames.Length; i++) { PropertyInfo[] propInfos = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); PropertyInfo property = Array.Find(propInfos, info => info.Name == customArgs.PropertyNames[i]); object propertyValue = null; if (property == null) { CustomPropertyValueEventArgs args = new CustomPropertyValueEventArgs(obj, customArgs.PropertyNames[i]); ((MyGridView)rootObject).RaiseSetCustomPropertyValue(args); if (args.PropertyValue == null) { continue; } propertyValue = args.PropertyValue; } else { propertyValue = property.GetValue(obj, null); if (propertyValue == null) { continue; } } properties.Add(new XtraPropertyInfo(customArgs.PropertyNames[i], propertyValue.GetType(), propertyValue)); } return(properties); }
protected override void CustomGetSerializableProperties(object obj, List <SerializablePropertyDescriptorPair> pairsList, PropertyDescriptorCollection props) { base.CustomGetSerializableProperties(obj, pairsList, props); if (DeserializeHelper == null || DeserializeHelper.RootObject == null || !(DeserializeHelper.RootObject is MyGridView)) { return; } SerializeCustomPropertiesEventArgs args = new SerializeCustomPropertiesEventArgs(obj); ((MyGridView)DeserializeHelper.RootObject).RaiseDeserializeCustomProperties(args); customProperties = args.PropertyNames; if (customProperties == null) { return; } foreach (string customProperty in customProperties) { for (int i = 0; i < pairsList.Count; i++) { if (pairsList[i].Property.Name == customProperty) { XtraSerializableProperty attribute = pairsList[i].Property.Attributes[typeof(XtraSerializableProperty)] as XtraSerializableProperty; if (attribute == null) { attribute = new XtraSerializableProperty(); } PropertyDescriptor prop = pairsList[i].Property; pairsList.RemoveAt(i); pairsList.Insert(i, new SerializablePropertyDescriptorPair(prop, attribute)); break; } } } }