Serialize things in Sitefinity?
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!
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);
foreach
(PropertyDescriptor property
in
properties)
object
propertyValue = property.GetValue(ctrltype);
if
(propertyValue !=
null
)
root.Add(
new
XAttribute(property.Name, propertyValue));
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!