开发者

C# Get properties from SettingsPropertyCollection

I have profile provider in my web.config

    <profile defaultProvider="MyProvider">
      <providers>
.......
      <properties>
        <add name="CustomField1" type="string" />
        <add name="CustomField2" type="string" />
        <add name="CustomField3" type="string" />
        <add name="CustomField4" type="string" />
      </properties>
    </profile>

How can I get string[] array containing all avaliable properties (CustomField1, CustomField2....)

Edit: Found working solution but not sure if it's the best and easie开发者_如何学Pythonst one.

var allCustomProperties =
                    profile.GetType().GetProperties().Where(l => l.PropertyType.Name == "String" && l.CanWrite == true).Select(
                        l => l.Name).ToArray();


I'd go with that:

string[] props = ProfileBase.Properties.Cast<SettingsProperty>()
            .Select( p => p.Name ).ToArray();

You have to import both System.Web.Profile and System.Configuration namespaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜