I have been working on a Silverlight (RC0) module for DotNetNuke and I needed to have access to some of the objects that DotNetNuke supports such as the userInfo object inside my Silverlight Module.
So what I have done is use the XmlSerializer to serialise the UserInfo object then pass the string in the initParams of the Silverlight control and Deserailise inside the Silverlight app.
I have also created a UserInfo class in my Silverlight module to deserialise into.
This gives me a UserInfo object to use inside my Silverlight module, nice.
Serialise the object Server Side:
Dim slUserInfo As String
Dim sbUi As StringBuilder = New StringBuilder()
Dim writerUi As XmlWriter = XmlWriter.Create(sbUi)
Dim xsUi As XmlSerializer = New XmlSerializer(GetType(Users.UserInfo))
xsUi.Serialize(writerUi, Me.UserInfo)
slUserInfo = sbUi.ToString()
writerUi.Close()
Deserialise Client Side:
var rdr = XmlReader.Create(new StringReader(slUserInfo));
XmlSerializer xs = new XmlSerializer(typeof(DotNetNuke.UserInfo));
userInfo = (UserInfo)xs.Deserialize(rdr);
public class UserInfo
{
public int AffiliateID { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public bool IsSuperUser { get; set; }
public string LastName { get; set; }
public int PortalID { get; set; }
public int UserID { get; set; }
public string Username { get; set; }
public List<string> Roles { get; set; }
}
Works a treat. Now to work on a Silverlight Framework for DotNetNuke modules.