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.
精彩评论