C# 扩展方法的正确语法
我试着按照这个例子来创建轮廓特征 让我大吃一惊的是,我的web.config还包含对属性进行分组的C# 扩展方法的正确语法,c#,asp.net,C#,Asp.net,我试着按照这个例子来创建轮廓特征 让我大吃一惊的是,我的web.config还包含对属性进行分组的组名。我的web.config如下所示 // Personal Info txtFirstName.Text = lprofile.Personal.FirstName; txtLastName.Text = lprofile.Personal.LastName; ddlGenders.SelectedValue = lprofile.
组名。我的web.config如下所示
// Personal Info
txtFirstName.Text = lprofile.Personal.FirstName;
txtLastName.Text = lprofile.Personal.LastName;
ddlGenders.SelectedValue = lprofile.Personal.Gender;
if (lprofile.Personal.BirthDate != DateTime.MinValue)
txtBirthDate.Text = lprofile.Personal.BirthDate.ToShortDateString();
ddlOccupations.SelectedValue = lprofile.Personal.Occupation;
txtWebsite.Text = lprofile.Personal.Website;
// Address Info
ddlCountries.SelectedValue = lprofile.Address.Country;
txtAddress.Text = lprofile.Address.Address;
txtAptNumber.Text = lprofile.Address.AptNumber;
txtCity.Text = lprofile.Address.City;
ddlStates1.SelectedValue = lprofile.Address.State;
txtPostalCode.Text = lprofile.Address.PostalCode;
web.config:
<profile defaultProvider="MyCMSSqlProfileProvider" automaticSaveEnabled="false" inherits ="TestProj.Controls.wProfile">
<providers>
<clear/>
<add name="MyCMSSqlProfileProvider" connectionStringName="dbMyCMSConnectionString" applicationName="MyCMS" type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<group name="Personal">
<add name="FirstName" type="String" />
<add name="LastName" type="String" />
<add name="Gender" type="String" />
<add name="BirthDate" type="DateTime" />
<add name="Occupation" type="String" />
<add name="Website" type="String" />
</group>
<group name="Address">
<add name="Country" type="String" />
<add name="Address" type="String" />
<add name="AptNumber" type="String" />
<add name="City" type="String" />
<add name="State" type="String" />
<add name="PostalCode" type="String" />
</group>
//.....etc
using System.Web;
using System.Web.Profile;
namespace Project1.Account
{
public class wProfile : ProfileBase
{
public ProfileInfo ProfileInfo
{
get { return (ProfileInfo) GetPropertyValue("ProfileInfo"); }
}
public static wProfile GetProfile()
{
return (wProfile) HttpContext.Current.Profile;
}
public static wProfile GetProfile(string userName)
{
return (wProfile) Create(userName);
}
}
}
但要知道这是行不通的,因为我需要通过wProfile
wProfile.cs:
<profile defaultProvider="MyCMSSqlProfileProvider" automaticSaveEnabled="false" inherits ="TestProj.Controls.wProfile">
<providers>
<clear/>
<add name="MyCMSSqlProfileProvider" connectionStringName="dbMyCMSConnectionString" applicationName="MyCMS" type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<group name="Personal">
<add name="FirstName" type="String" />
<add name="LastName" type="String" />
<add name="Gender" type="String" />
<add name="BirthDate" type="DateTime" />
<add name="Occupation" type="String" />
<add name="Website" type="String" />
</group>
<group name="Address">
<add name="Country" type="String" />
<add name="Address" type="String" />
<add name="AptNumber" type="String" />
<add name="City" type="String" />
<add name="State" type="String" />
<add name="PostalCode" type="String" />
</group>
//.....etc
using System.Web;
using System.Web.Profile;
namespace Project1.Account
{
public class wProfile : ProfileBase
{
public ProfileInfo ProfileInfo
{
get { return (ProfileInfo) GetPropertyValue("ProfileInfo"); }
}
public static wProfile GetProfile()
{
return (wProfile) HttpContext.Current.Profile;
}
public static wProfile GetProfile(string userName)
{
return (wProfile) Create(userName);
}
}
}
如何正确设置ProfileInfo.cs
以公开包括组名在内的所有属性的配置文件
在代码隐藏中,我想做这样的事情
// Personal Info
txtFirstName.Text = lprofile.Personal.FirstName;
txtLastName.Text = lprofile.Personal.LastName;
ddlGenders.SelectedValue = lprofile.Personal.Gender;
if (lprofile.Personal.BirthDate != DateTime.MinValue)
txtBirthDate.Text = lprofile.Personal.BirthDate.ToShortDateString();
ddlOccupations.SelectedValue = lprofile.Personal.Occupation;
txtWebsite.Text = lprofile.Personal.Website;
// Address Info
ddlCountries.SelectedValue = lprofile.Address.Country;
txtAddress.Text = lprofile.Address.Address;
txtAptNumber.Text = lprofile.Address.AptNumber;
txtCity.Text = lprofile.Address.City;
ddlStates1.SelectedValue = lprofile.Address.State;
txtPostalCode.Text = lprofile.Address.PostalCode;
您只需将个人
/地址
作为属性添加到您的配置文件模型中即可
[Serializable]
public class Personal
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public string BirthDate { get; set; }
public string Occupation { get; set; }
public string Website { get; set; }
}
[Serializable]
public class Address
{
public string Country { get; set; }
public string Address { get; set; }
public string AptNumber { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
}
[Serializable]
public class ProfileInfo
{
public Personal Personal { get; set; }
public Address Address { get; set; }
}
从
属性可以在用户配置文件中组织为组
财产。配置文件属性组是使用组指定的
配置元素。例如,用户的
地址信息可以组合在一个地址组中。你
然后可以使用组标识符和
属性名称(例如Profile.Address.Street或
个人资料。地址。城市)
您只需将个人
/地址
作为属性添加到您的配置文件模型中即可
[Serializable]
public class Personal
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public string BirthDate { get; set; }
public string Occupation { get; set; }
public string Website { get; set; }
}
[Serializable]
public class Address
{
public string Country { get; set; }
public string Address { get; set; }
public string AptNumber { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
}
[Serializable]
public class ProfileInfo
{
public Personal Personal { get; set; }
public Address Address { get; set; }
}
从
属性可以在用户配置文件中组织为组
财产。配置文件属性组是使用组指定的
配置元素。例如,用户的
地址信息可以组合在一个地址组中。你
然后可以使用组标识符和
属性名称(例如Profile.Address.Street或
个人资料。地址。城市)