Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 扩展方法的正确语法_C#_Asp.net - Fatal编程技术网

C# 扩展方法的正确语法

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还包含对属性进行分组的
组名。我的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或 个人资料。地址。城市)