Additional properties on AppIdentity class in Silverlight3

Additional properties on AppIdentity class in Silverlight3

Old forum URL: forums.lhotka.net/forums/t/8080.aspx


Russ posted on Wednesday, December 02, 2009

Has anyone been able to add custom properties to the AppIdentity class in Silverlight3?

I tried the following:

namespace Business
{
[Serializable]
public partial class AppIdentity : Csla.Security.CslaIdentity
{
public AppIdentity()
{ }

public int UserPK { get { return (String.IsNullOrEmpty(Name) ? 0 : int.Parse(Name)); } }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string FullNameFL { get { return FirstName + " " + LastName; } }

}
}

But the custom fields were always null in the client. I reasoned that I required managed backing fields however I was unable to add them because the base class was CslaIdentity.

Another thought I have is that Rocky designed this on purpose to keep the AppIdentity class as small as possible because it is the most frequently tranferred object throught the data portal. Should I instead be creating a CurrentUser readonly class that get populated at login and is cached?

Any "Best Practices" info would be greatly appreciated.

Thanks
Russ.

RockfordLhotka replied on Thursday, December 03, 2009

You do need to use managed backing fields, or override OnGetState/OnSetState to serialize your private backing fields by hand.

The trick with CslaIdentity (like CommandBase) is that the type isn't generic, so you need to use the long form of RegisterProperty() where the first parameter is the type of the containing object (in your case AppIdentity).

Russ replied on Thursday, December 03, 2009

Thanks Rocky,

That was exactly what I was missing. I had tried the newer RegisterProperty syntax using the lambda expression and it had failed.

For the benefit of others who find this thread, here is the working AppIdentity class.

namespace Business
{
[Serializable]
public partial class AppIdentity : Csla.Security.CslaIdentity
{
public AppIdentity()
{ }

private static PropertyInfo FirstNameProperty =
RegisterProperty(typeof(AppIdentity), new PropertyInfo("FirstName", "First Name"));
public string FirstName
{
get { return GetProperty(FirstNameProperty); }
}

private static PropertyInfo LastNameProperty =
RegisterProperty(typeof(AppIdentity), new PropertyInfo("LastName", "Last Name"));
public string LastName
{
get { return GetProperty(LastNameProperty); }
}

public int UserPK { get { return (String.IsNullOrEmpty(Name) ? 0 : int.Parse(Name)); } }

public string FullNameFL { get { return FirstName + " " + LastName; } }
}
}

Regards
Russ

Copyright (c) Marimer LLC