Serialize things in Sitefinity?

Posted by Community Admin on 03-Aug-2018 14:25

Serialize things in Sitefinity?

All Replies

Posted by Community Admin on 15-Nov-2012 00:00

Hey, guys!
I was wondering is there any "standard" way of serializing things ni SF?
I saw a lot of the objects are extended to have Serialize and Deserialize metods but not qutie sure how to use them.
If I serialize something it seems that first level properties are serialzied to Dictionary and then then the child objects are serialized binary.
Not much luck deserializing, though.
 
Is there an example anywhere? My goal is to have a ControlProperty serialized and then deserialized.

Sorry if the question is too stupid. Couldn't find an answer for about an hour an decided to ask the experts.

Edit: Now I see I am postign to General Discussions, please feel free to move this to Developing with Sitefinity / more appropriate forum if you need to.

Thanks in advance!

Posted by Community Admin on 15-Nov-2012 00:00

Hello,

We use TypeDescriptor to get the parent properties then PropertyDescriptor for each child property.  
This will allow you to read all properties from ControlProperty and if they are complex you can read the nested properties by iterating through them.

               //Top level properties
               var propertyDescriptors = TypeDescriptor.GetProperties(ctrlType);
 
          List<ControlProperty> childProps = new List<ControlProperty>();
          foreach (var propData in ctrlData.ChildProperties)
          
              var propDesc = propertyDescriptors.Find(propData.Name, true);
              if (propDesc == null)
                  continue;
var att = (PersistenceModeAttribute)propDesc.Attributes[typeof(PersistenceModeAttribute)];
              bool isInnerProperty = att != null && (att.Mode == PersistenceMode.InnerProperty || att.Mode == PersistenceMode.InnerDefaultProperty);
              if (isInnerProperty || propData.ListItems.Count() > 0)
              
                  childProps.Add(propData);
              
          


You can also see ControlHelper which might do some job for you. There are some useful methods in ConrolManager class as well.
You can use a proxy object to serialize/deserialize or XML (creating XElement and adding XAttribute with the name and value of the property

foreach (PropertyDescriptor property in properties)
  
         object propertyValue = property.GetValue(ctrltype);
         if (propertyValue != null)
             
                 root.Add(new XAttribute(property.Name, propertyValue));
             
  


For the WCF services we use Sys.Serialization.JavaScriptSerializer.deserialize where we pass a property bag. There we iterate through the whole property bag in order to build the object graph for a control.
The property object is sent on the client component (say a control and its designer) through  GetScriptDescriptors() method overridden from AjaxDialogBas again using JavaScripSerializer and its Serialize method. Inside the method we pass IList of ControlProperty  that is represent by WcfControlProperty ( responsible for transferring that data through WCF.)

Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 16-Nov-2012 00:00

Thanks, Ivan!
I found my way!

By the way is there any known issue with ordering the controls in Sitefinity when programatically adin a control?

I am following this one:
www.sitefinity.com/.../adding-and-removing-controls

But it seems to spread them all over the place.
Once again thanks for your help!

This thread is closed