![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#21
| |||
| |||
|
#22
| |||
| |||
|
#23
| |||
| |||
|
#24
| |||
| |||
|
|
Hi Linda, I don't know if I agree with this comment: In addition, we should always write a ShouldSerialize<PropertyName> method for each property we'd like to serialize. I'll explain why I'm not so sure in a moment. As for this comment: We should always use TypeDescriptor.GetProperties(component) in our serializer and call the ShouldSerializeValue method on each property to tell if it should be serialized. I completely agree with the above statement, and this is what I'm doing. But this is where my concern with the previous statement (that we should always write a ShouldSerialize<PropertyName> method for each property we wish to serialize) comes in. The documentation for PropertyDescriptor.ShouldSerializeValue (http://msdn2.microsoft.com/en-us/lib...izevalue.aspx), says that it first looks for a default value by looking for a DefaultValueAttribute. If this is not found, then it looks for a "ShouldSerializeMyProperty" method. The documentation *does* say that you need to implement the "ShouldSerializeMyProeprty" method, but I read this to mean that it not actually required by the design pattern, but rather is a way of refining the behaviour of PropertyDescriptor.ShouldSerializeValue beyond what is possible with the DefaultValueAttribute. I make this conclusion because of later statements in the documentation that say: "If this method cannot find a DefaultValueAttribute or a "ShouldSerializeMyProperty" method, it cannot create optimizations and it returns true." This is NOT the case with the implementation of InheritedPropertyDescriptor.ShouldSerializeValue; if I have not used a DefaultValueAttribute (or even if do, it seems to make no difference) and if do not include a "ShouldSerializeMyProperty", then InheritedPropertyDescriptor.ShouldSerializeValue returns False rather than True. The fact that the component designer is substituting different property descriptors should be invisible to you. I agree that this would be ideal, and it is what the documentation suggests should be the case. However, my experience does not agree with this statement, nor the documentation. Thanks, Notre |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |