MSDN is rather vague regarding this attribute.
The custom data string can be set to any string value and is set using the customProviderData attribute of the add configuration element for adding profile properties.
Which is the MSDN-esque way of saying figure it out yourself.
From the description it kind of feels like it's plain text you just pass from web.config to a custom provider. But it's not like that, this string seems to build the type of data a given attribute will hold, and I want to know what's the specific format.
In particular, I have the following attributes (and a few more, but I'll just exemplify with two)
[SettingsAllowAnonymous(false)]
[CustomProviderData("NotificationTypes;nvarchar;255")]
public string NotificationTypes
{
get { return base["NotificationTypes"] as string ?? "Email"; }
set { base["NotificationTypes"] = value; }
}
[SettingsAllowAnonymous(false)]
[CustomProviderData("IssuesPageSize;int")]
public int IssuesPageSize
{
get { return base["IssuesPageSize"] as int? ?? 10; }
set { base["IssuesPageSize"] = value; }
}
Here, the custom data seems to determine the name of the field, the db type, and the db length. I was wondering if this attribute could hold a default.
My questions then, are the following:
Can base[attrib]
ever be null in a ProfileBase
implementation?
0
and string.Empty
if I want to set default values?
The point being that if base[attrib]
can't ever be null, I don't need the int?
cast, and I should just be checking against 0
, in that case, and against string.Empty
in the previous one.
That is, unless there's a "happier" way to set a default value, pretty much like in web.config where you just type:
<add name="NotificationTypes" type="String" defaultValue="Email" customProviderData="NotificationTypes;nvarchar;255" />
I guess I'm asking how I can add an attribute that is functionally exactly like the one in the <add/>
tag above, but 开发者_开发技巧programatically.
Came up with adding this:
static SharedMembershipProfile()
{
Properties["IssuesPageSize"].DefaultValue = 10;
Properties["NotificationTypes"].DefaultValue = "Email";
Properties["PreferredLocale"].DefaultValue = "en-US";
}
Still wondering if there's a better approach, like an attribute, or something more "auto-wired"
精彩评论