HighTechTalks DotNet Forums  

Persisting custom dictionary property

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Persisting custom dictionary property in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nels P. Olsen
 
Posts: n/a

Default Persisting custom dictionary property - 08-01-2006 , 07:05 PM






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 Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.