本文整理汇总了C#中Profile.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Profile.GetType方法的具体用法?C# Profile.GetType怎么用?C# Profile.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Profile
的用法示例。
在下文中一共展示了Profile.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPropertyValues
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
var username = (string)context["UserName"];
if (string.IsNullOrEmpty(username) || collection.Count < 1)
return;
var db = new UserContext();
var firstOrDefault = db.Users.FirstOrDefault(u => u.Email.Equals(username));
if (firstOrDefault != null)
{
int userId = firstOrDefault.ID;
Profile profile = db.Profiles.FirstOrDefault(u => u.UserID == userId);
if (profile != null)
{
foreach (SettingsPropertyValue val in collection)
{
profile.GetType().GetProperty(val.Property.Name).SetValue(profile, val.PropertyValue);
}
profile.LastUpdateDate = DateTime.Now;
db.Entry(profile).State = EntityState.Modified;
}
else
{
profile = new Profile();
foreach (SettingsPropertyValue val in collection)
{
profile.GetType().GetProperty(val.Property.Name).SetValue(profile, val.PropertyValue);
}
profile.LastUpdateDate = DateTime.Now;
profile.UserID = userId;
db.Profiles.Add(profile);
}
}
db.SaveChanges();
}
示例2: SerializeProfileToXml
private static string SerializeProfileToXml(Profile profile)
{
if (profile == null) throw new ArgumentNullException("profile");
XmlRootAttribute profileRoot = new XmlRootAttribute("profile");
profileRoot.Namespace = MavenSettingsNamespace;
XmlAttributes attributes = new XmlAttributes();
attributes.XmlRoot = profileRoot;
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
overrides.Add(profile.GetType(), attributes);
XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
xmlnsEmpty.Add("", MavenSettingsNamespace);
XmlSerializer xs = new XmlSerializer(profile.GetType(), overrides);
StringWriter xout = new StringWriter();
xs.Serialize(xout, profile, xmlnsEmpty);
String SerializedProfile = xout.ToString();
xout.Close();
return SerializedProfile;
}