..been browsing the net but no luck.. I need to use the ProfileCommon but I can\'t reference any assemblies to use it.. can someone help?
This is a dynamic type generated by the framework. On runtime the type 'ProfileCommon' exists.
If you can use the C# 4.0 language features you can wrap the behavior of ProfileCommon in a dynamic object.
I have the following extended properties
The code example to use the dynamic object is
dynamic profile = new ProfileData();
var name = profile.FirstName + ' ' + profile.LastName;
The implementation of ProfileData:
public class ProfileData: DynamicObject
{
private readonly ProfileBase profileBase;
///
/// Profile Data for the current user.
///
public ProfileData()
{
profileBase = HttpContext.Current.Profile;
}
///
/// Profile data for user with name
///
///
public ProfileData(string userName)
{
profileBase = ProfileBase.Create(userName);
}
// If you try to get a value of a property
// not defined in the class, this method is called.
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
try
{
result = profileBase.GetPropertyValue(binder.Name);
}
catch(SettingsPropertyNotFoundException)
{
result = null;
return false;
}
return true;
}
// If you try to set a value of a property that is
// not defined in the class, this method is called.
public override bool TrySetMember(SetMemberBinder binder, object value)
{
try
{
profileBase.SetPropertyValue(binder.Name, value);
return true;
}
catch (SettingsPropertyNotFoundException)
{
return false;
}
}
///
/// Persist the profile data.
///
public void Save()
{
profileBase.Save();
}
}