本文整理汇总了C#中System.Configuration.SettingsPropertyCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SettingsPropertyCollection.Add方法的具体用法?C# SettingsPropertyCollection.Add怎么用?C# SettingsPropertyCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.SettingsPropertyCollection
的用法示例。
在下文中一共展示了SettingsPropertyCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitProperties
static void InitProperties ()
{
SettingsPropertyCollection properties = new SettingsPropertyCollection ();
ProfileSection config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
RootProfilePropertySettingsCollection ps = config.PropertySettings;
for (int i = 0; i < ps.GroupSettings.Count; i++) {
ProfileGroupSettings pgs = ps.GroupSettings [i];
ProfilePropertySettingsCollection ppsc = pgs.PropertySettings;
for (int s = 0; s < ppsc.Count; s++) {
SettingsProperty settingsProperty = CreateSettingsProperty (pgs, ppsc [s]);
ValidateProperty (settingsProperty, ppsc [s].ElementInformation);
properties.Add (settingsProperty);
}
}
for (int s = 0; s < ps.Count; s++) {
SettingsProperty settingsProperty = CreateSettingsProperty (null, ps [s]);
ValidateProperty (settingsProperty, ps [s].ElementInformation);
properties.Add (settingsProperty);
}
if (config.Inherits.Length > 0) {
Type profileType = ProfileParser.GetProfileCommonType (HttpContext.Current);
if (profileType != null) {
Type properiesType = profileType.BaseType;
for (; ; ) {
PropertyInfo [] pi = properiesType.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
if (pi.Length > 0)
for (int i = 0; i < pi.Length; i++)
properties.Add (CreateSettingsProperty (pi [i]));
if (properiesType.BaseType == null ||
properiesType.BaseType == typeof (ProfileBase))
break;
properiesType = properiesType.BaseType;
}
}
}
properties.SetReadOnly ();
lock (Profiles_SettingsPropertyCollection) {
if (_properties == null)
_properties = properties;
}
}
示例2: AddDuplicate
public void AddDuplicate ()
{
SettingsPropertyCollection col = new SettingsPropertyCollection ();
SettingsProperty test_prop = new SettingsProperty ("test_prop");
col.Add (test_prop);
Assert.AreEqual (1, col.Count, "A1");
test_prop = new SettingsProperty ("test_prop");
col.Add (test_prop);
Assert.AreEqual (1, col.Count, "A2");
}
示例3: ToSettingsPropertyCollection
public static SettingsPropertyCollection ToSettingsPropertyCollection(this IEnumerable<SettingsProperty> settingsProperties)
{
var c = new SettingsPropertyCollection();
foreach (var property in settingsProperties)
{
c.Add(property);
}
return c;
}
示例4: GetPropertiesForProvider
private static SettingsPropertyCollection GetPropertiesForProvider(ApplicationSettingsBase settings, SettingsProvider provider)
{
SettingsPropertyCollection properties = new SettingsPropertyCollection();
foreach (SettingsProperty property in settings.Properties)
{
if (property.Provider == provider)
properties.Add(property);
}
return properties;
}
示例5: GetPropertiesFromProvider
private void GetPropertiesFromProvider(SettingsProvider provider)
{
SettingsPropertyCollection collection = new SettingsPropertyCollection();
foreach (SettingsProperty property in this.Properties)
{
if (property.Provider == provider)
{
collection.Add(property);
}
}
if (collection.Count > 0)
{
foreach (SettingsPropertyValue value2 in provider.GetPropertyValues(this.Context, collection))
{
if (this._PropertyValues[value2.Name] == null)
{
this._PropertyValues.Add(value2);
}
}
}
}
示例6: AuthenticatedDateTime
public void AuthenticatedDateTime()
{
ProfileBase profile = ProfileBase.Create("foo", true);
ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
DateTime date = DateTime.Now;
profile["BirthDate"] = date;
profile.Save();
SettingsPropertyCollection getProps = new SettingsPropertyCollection();
SettingsProperty getProp1 = new SettingsProperty("BirthDate");
getProp1.PropertyType = typeof(DateTime);
getProp1.SerializeAs = SettingsSerializeAs.Xml;
getProps.Add(getProp1);
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", true);
ctx.Add("UserName", "foo");
SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);
Assert.AreEqual(1, getValues.Count);
SettingsPropertyValue getValue1 = getValues["BirthDate"];
Assert.AreEqual(date, getValue1.PropertyValue);
}
示例7: GetAllProfiles
public void GetAllProfiles()
{
ProfileBase profile = ProfileBase.Create("foo", true);
ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
profile["Name"] = "Fred Flintstone";
profile.Save();
SettingsPropertyCollection getProps = new SettingsPropertyCollection();
SettingsProperty getProp1 = new SettingsProperty("Name");
getProp1.PropertyType = typeof(String);
getProps.Add(getProp1);
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", true);
ctx.Add("UserName", "foo");
int total;
ProfileInfoCollection profiles = provider.GetAllProfiles(
ProfileAuthenticationOption.All, 0, 10, out total);
Assert.AreEqual(1, total);
}
示例8: AuthenticatedStringProperty
public void AuthenticatedStringProperty()
{
ProfileBase profile = ProfileBase.Create("foo", true);
ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
profile["Name"] = "Fred Flintstone";
profile.Save();
SettingsPropertyCollection getProps = new SettingsPropertyCollection();
SettingsProperty getProp1 = new SettingsProperty("Name");
getProp1.PropertyType = typeof(String);
getProps.Add(getProp1);
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", true);
ctx.Add("UserName", "foo");
SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);
Assert.AreEqual(1, getValues.Count);
SettingsPropertyValue getValue1 = getValues["Name"];
Assert.AreEqual("Fred Flintstone", getValue1.PropertyValue);
}
示例9: StringCollectionAsProperty
public void StringCollectionAsProperty()
{
ProfileBase profile = ProfileBase.Create("foo", true);
ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
StringCollection colors = new StringCollection();
colors.Add("red");
colors.Add("green");
colors.Add("blue");
profile["FavoriteColors"] = colors;
profile.Save();
DataTable dt = FillTable("SELECT * FROM my_aspnet_applications");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_users");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_profiles");
Assert.AreEqual(1, dt.Rows.Count);
// now retrieve them
SettingsPropertyCollection getProps = new SettingsPropertyCollection();
SettingsProperty getProp1 = new SettingsProperty("FavoriteColors");
getProp1.PropertyType = typeof(StringCollection);
getProp1.SerializeAs = SettingsSerializeAs.Xml;
getProps.Add(getProp1);
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", true);
ctx.Add("UserName", "foo");
SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);
Assert.AreEqual(1, getValues.Count);
SettingsPropertyValue getValue1 = getValues["FavoriteColors"];
StringCollection outValue = (StringCollection)getValue1.PropertyValue;
Assert.AreEqual(3, outValue.Count);
Assert.AreEqual("red", outValue[0]);
Assert.AreEqual("green", outValue[1]);
Assert.AreEqual("blue", outValue[2]);
}
示例10: Upgrade
public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
{
string previousUserConfigPath = PreviousUserConfigPath;
if (!string.IsNullOrEmpty(previousUserConfigPath))
{
SettingsPropertyCollection propertys = new SettingsPropertyCollection();
foreach (SettingsProperty property in properties)
{
if (!(property.Attributes[typeof(NoSettingsVersionUpgradeAttribute)] is NoSettingsVersionUpgradeAttribute))
{
propertys.Add(property);
}
}
SettingsPropertyValueCollection collection = this.GetPropertyValuesFromFile(previousUserConfigPath, context, propertys);
this.SetPropertyValues(context, collection);
}
}
示例11: AddPropertyTypeMismatch
public void AddPropertyTypeMismatch ()
{
SettingsPropertyCollection props = new SettingsPropertyCollection ();
SettingsProviderCollection provs = new SettingsProviderCollection ();
MyProvider p = new MyProvider ();
MySettings s = new MySettings ();
props.Add (new SettingsProperty ("Foo", typeof (string), p, false, 10, SettingsSerializeAs.String, null, true, true));
provs.Add (p);
s.Initialize (new SettingsContext (), props, provs);
int i = s.Foo; // it still works as int, regardless of the settings property type...
}
示例12: LoadPropertyValue
private void LoadPropertyValue (SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
{
SettingsProperty prop = collection [element.Name];
if (prop == null) { // see bug #343459
prop = new SettingsProperty (element.Name);
collection.Add (prop);
}
SettingsPropertyValue value = new SettingsPropertyValue (prop);
value.IsDirty = false;
if (element.Value.ValueXml != null) {
switch (value.Property.SerializeAs) {
case SettingsSerializeAs.Xml:
value.SerializedValue = element.Value.ValueXml.InnerXml;
break;
case SettingsSerializeAs.String:
value.SerializedValue = element.Value.ValueXml.InnerText;
break;
case SettingsSerializeAs.Binary:
value.SerializedValue = Convert.FromBase64String (element.Value.ValueXml.InnerText);
break;
}
}
else
value.SerializedValue = prop.DefaultValue;
try
{
if (allowOverwrite)
values.Remove (element.Name);
values.Add (value);
} catch (ArgumentException ex) {
throw new ConfigurationErrorsException (string.Format (
CultureInfo.InvariantCulture,
"Failed to load value for '{0}'.",
element.Name), ex);
}
}
示例13: PropertyValuesInstance
public void PropertyValuesInstance ()
{
SettingsPropertyCollection props = new SettingsPropertyCollection ();
SettingsProviderCollection provs = new SettingsProviderCollection ();
MyProvider p = new MyProvider ();
MySettings s = new MySettings ();
props.Add (new SettingsProperty ("Foo", typeof (string), p, false, 10, SettingsSerializeAs.String, null, true, true));
provs.Add (p);
s.Initialize (new SettingsContext (), props, provs);
Assert.AreEqual (s.PropertyValues, s.PropertyValues);
}
示例14: GetPreviousVersion
public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) {
bool isRoaming = IsRoamingSetting(property);
string prevConfig = GetPreviousConfigFileName(isRoaming);
if (!String.IsNullOrEmpty(prevConfig)) {
SettingsPropertyCollection properties = new SettingsPropertyCollection();
properties.Add(property);
SettingsPropertyValueCollection values = GetSettingValuesFromFile(prevConfig, GetSectionName(context), true, properties);
return values[property.Name];
}
else {
SettingsPropertyValue value = new SettingsPropertyValue(property);
value.PropertyValue = null;
return value;
}
}
示例15: Upgrade
private void Upgrade(SettingsContext context, SettingsPropertyCollection properties, bool isRoaming) {
string prevConfig = GetPreviousConfigFileName(isRoaming);
if (!String.IsNullOrEmpty(prevConfig)) {
//Filter the settings properties to exclude those that have a NoSettingsVersionUpgradeAttribute on them.
SettingsPropertyCollection upgradeProperties = new SettingsPropertyCollection();
foreach (SettingsProperty sp in properties) {
if (!(sp.Attributes[typeof(NoSettingsVersionUpgradeAttribute)] is NoSettingsVersionUpgradeAttribute)) {
upgradeProperties.Add(sp);
}
}
SettingsPropertyValueCollection values = GetSettingValuesFromFile(prevConfig, GetSectionName(context), true, upgradeProperties);
SetPropertyValues(context, values);
}
}