N
Nels P. Olsen
I have a custom ASP control (an extension of DataSourceControl) that contains
a custom property, which contains a custom dictionary property. I can't get
the custom dictionary property to persist correctly from my custom designer.
The code looks like this:
[Designer(typeof(MyCustomControlDesignerType)]
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public class MyCustomControlType : System.Web.UI.DataSourceControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public MyCustomPropertyType CustomProperty {get { ... } set {...}}
}
public class MyCustomControlDesignerType :
System.Web.UI.Design.DataSourceDesigner
{
...
}
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public MyCustomPropertyType
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string SomeShortTextProperty {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string SomeLongTextProperty {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public MyCustomDictionaryType CustomDictionaryProperty {get {...} set
{...}}
}
[Serializable]
public MyCustomDictionaryType : IDictionary, ...
{
public MyCustomDictionaryValueType this[string key] {get {...} set {...}}
// Implementation of IDictionary members
// enforces dictionary values of type MyCustomDictionaryValueType
// MyCustomDictionaryValueType.Name is automatically used as the key
}
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public MyCustomDictionaryValueType
{
// The Name property serves as the dictionary key
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string Name {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public Type Type {get {...} {set {...}}
}
When I save changes to an instance of my control in my designer, the
dictionary entries are persisted in the ASP markup like this:
<myNamespace:MyCustomControlType>
<CustomProperty SomeShortTextProperty="...">
<SomeLongTextProperty>
...
</SomeLongTextProperty>
<CustomDictionaryProperty>
<dictionaryentry key="theKey" value="theValueToString">
...
</CustomDictionaryProperty>
</CustomProperty>
</myNamespace:MyCustomControlType>
I haven't been able to figure out a way to control the persisted ASP markup
of the dictionary entries. I've tried all kinds of things -- implementing
IXmlSerializable in my custom dictionary class, decorating my custom
dictionary value class with a custom type converter, etc. Nothing I do has
any effect.
How can I get the persisted ASP markup to look like this, which I can
deserialize:
<CustomDictionaryProperty>
<CustomDictionaryValue Name="theKey" Type="theAssemblyQualifiedName">
...
</CustomDictionaryProperty>
instead of this, which I can't deserialize:
<CustomDictionaryProperty>
<dictionaryentry key="theKey"
value="MyNamespace.MyCustomDictionaryValueType">
...
</CustomDictionaryProperty>
a custom property, which contains a custom dictionary property. I can't get
the custom dictionary property to persist correctly from my custom designer.
The code looks like this:
[Designer(typeof(MyCustomControlDesignerType)]
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public class MyCustomControlType : System.Web.UI.DataSourceControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public MyCustomPropertyType CustomProperty {get { ... } set {...}}
}
public class MyCustomControlDesignerType :
System.Web.UI.Design.DataSourceDesigner
{
...
}
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public MyCustomPropertyType
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string SomeShortTextProperty {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string SomeLongTextProperty {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public MyCustomDictionaryType CustomDictionaryProperty {get {...} set
{...}}
}
[Serializable]
public MyCustomDictionaryType : IDictionary, ...
{
public MyCustomDictionaryValueType this[string key] {get {...} set {...}}
// Implementation of IDictionary members
// enforces dictionary values of type MyCustomDictionaryValueType
// MyCustomDictionaryValueType.Name is automatically used as the key
}
[ParseChildren(true)]
[PersistChildren(false)]
[Serializable]
public MyCustomDictionaryValueType
{
// The Name property serves as the dictionary key
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string Name {get {...} set {...}}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public Type Type {get {...} {set {...}}
}
When I save changes to an instance of my control in my designer, the
dictionary entries are persisted in the ASP markup like this:
<myNamespace:MyCustomControlType>
<CustomProperty SomeShortTextProperty="...">
<SomeLongTextProperty>
...
</SomeLongTextProperty>
<CustomDictionaryProperty>
<dictionaryentry key="theKey" value="theValueToString">
...
</CustomDictionaryProperty>
</CustomProperty>
</myNamespace:MyCustomControlType>
I haven't been able to figure out a way to control the persisted ASP markup
of the dictionary entries. I've tried all kinds of things -- implementing
IXmlSerializable in my custom dictionary class, decorating my custom
dictionary value class with a custom type converter, etc. Nothing I do has
any effect.
How can I get the persisted ASP markup to look like this, which I can
deserialize:
<CustomDictionaryProperty>
<CustomDictionaryValue Name="theKey" Type="theAssemblyQualifiedName">
...
</CustomDictionaryProperty>
instead of this, which I can't deserialize:
<CustomDictionaryProperty>
<dictionaryentry key="theKey"
value="MyNamespace.MyCustomDictionaryValueType">
...
</CustomDictionaryProperty>