Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Persisting custom dictionary property

Reply
Thread Tools

Persisting custom dictionary property

 
 
Nels P. Olsen
Guest
Posts: n/a
 
      08-01-2006
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(DesignerSerializat ionVisibility.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(DesignerSerializat ionVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string SomeShortTextProperty {get {...} set {...}}

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string SomeLongTextProperty {get {...} set {...}}

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.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(DesignerSerializat ionVisibility.Visible)]
[PersistenceMode(PersistenceMode.Attribute)]
public string Name {get {...} set {...}}

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Persisting Columns property in Designer for a GridView inside a CompositeDataBoundControl schmurgon ASP .Net Building Controls 0 12-16-2006 06:03 AM
Problem persisting asp.net 2.0 property in design-time JesperA ASP .Net Building Controls 1 10-18-2006 06:13 PM
Need help persisting arraylist property. Jeremy Chapman ASP .Net Building Controls 0 02-18-2006 01:03 AM
Persisting a collection property in a custom datagrid jcteague@gmail.com ASP .Net Building Controls 0 12-05-2005 09:09 PM
Persisting a property (e.g. TabIndex) in a control's Tag on creation Ahmet Gunes ASP .Net Building Controls 3 06-14-2004 10:37 AM



Advertisments