本文整理汇总了C#中System.Configuration.SettingsProperty类的典型用法代码示例。如果您正苦于以下问题:C# SettingsProperty类的具体用法?C# SettingsProperty怎么用?C# SettingsProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SettingsProperty类属于System.Configuration命名空间,在下文中一共展示了SettingsProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePropNode
private void CreatePropNode(SettingsProperty setting, SettingsPropertyValue value, SettingsContext context)
{
string xPathQuery = getXPathQuerySection(setting, context);
XmlNode groupNode = doc.SelectSingleNode(xPathQuery);
if (groupNode == null)
{
groupNode = doc.CreateElement(GetSectionName(context));
if (this.IsUserScoped(setting))
{
userSettings.AppendChild(groupNode);
}
else
{
appSettings.AppendChild(groupNode);
}
} //if (node == null)
XmlNode nodeProp = doc.CreateElement(setting.Name);
nodeProp.AppendChild(this.SerializeToXmlElement(setting, value));
groupNode.AppendChild(nodeProp);
}
示例2: GetDescription
public static string GetDescription(SettingsProperty property)
{
SettingsDescriptionAttribute a = CollectionUtils.SelectFirst(property.Attributes,
attribute => attribute is SettingsDescriptionAttribute) as SettingsDescriptionAttribute;
return a == null ? "" : a.Description;
}
示例3: SettingValuesCreatesAnAppAndUserId
public void SettingValuesCreatesAnAppAndUserId()
{
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", false);
ctx.Add("UserName", "user1");
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
SettingsProperty property1 = new SettingsProperty("color");
property1.PropertyType = typeof(string);
property1.Attributes["AllowAnonymous"] = true;
SettingsPropertyValue value = new SettingsPropertyValue(property1);
value.PropertyValue = "blue";
values.Add(value);
provider.SetPropertyValues(ctx, values);
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);
values["color"].PropertyValue = "green";
provider.SetPropertyValues(ctx, values);
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);
}
示例4: Settings
public Settings()
{
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
for (int i = 0; i < MaxExternalTools; i++)
{
SettingsProperty newProp = new SettingsProperty(
"ExternalTool" + i, typeof(ExternalTool),
this.Providers[Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location)],
false,
null,
SettingsSerializeAs.String,
null,
true, true
);
this.Properties.Add(newProp);
}
this.SettingsLoaded += new System.Configuration.SettingsLoadedEventHandler(Settings_SettingsLoaded);
}
示例5: CreateSetting
private SettingsProperty CreateSetting(PropertyInfo propInfo)
{
object[] customAttributes = propInfo.GetCustomAttributes(false);
SettingsProperty property = new SettingsProperty(this.Initializer);
bool flag = this._explicitSerializeOnClass;
property.Name = propInfo.Name;
property.PropertyType = propInfo.PropertyType;
for (int i = 0; i < customAttributes.Length; i++)
{
Attribute attribute = customAttributes[i] as Attribute;
if (attribute != null)
{
if (attribute is DefaultSettingValueAttribute)
{
property.DefaultValue = ((DefaultSettingValueAttribute) attribute).Value;
}
else if (attribute is ReadOnlyAttribute)
{
property.IsReadOnly = true;
}
else if (attribute is SettingsProviderAttribute)
{
string providerTypeName = ((SettingsProviderAttribute) attribute).ProviderTypeName;
Type type = Type.GetType(providerTypeName);
if (type == null)
{
throw new ConfigurationErrorsException(System.SR.GetString("ProviderTypeLoadFailed", new object[] { providerTypeName }));
}
SettingsProvider provider = SecurityUtils.SecureCreateInstance(type) as SettingsProvider;
if (provider == null)
{
throw new ConfigurationErrorsException(System.SR.GetString("ProviderInstantiationFailed", new object[] { providerTypeName }));
}
provider.Initialize(null, null);
provider.ApplicationName = ConfigurationManagerInternalFactory.Instance.ExeProductName;
SettingsProvider provider2 = this._providers[provider.Name];
if (provider2 != null)
{
provider = provider2;
}
property.Provider = provider;
}
else if (attribute is SettingsSerializeAsAttribute)
{
property.SerializeAs = ((SettingsSerializeAsAttribute) attribute).SerializeAs;
flag = true;
}
else
{
property.Attributes.Add(attribute.GetType(), attribute);
}
}
}
if (!flag)
{
property.SerializeAs = this.GetSerializeAs(propInfo.PropertyType);
}
return property;
}
示例6: ProfilePropertyViewModel
public ProfilePropertyViewModel(SettingsProperty property, ProfilePropertyInputModel value)
{
Type = PropTypeFromPropertyType(property);
Description = property.Name + " must be of type " + property.PropertyType.Name;
if (property.PropertyType.IsValueType) Description += " and is required";
Description += ".";
Data = value;
}
示例7: ProfilePropertyViewModel
public ProfilePropertyViewModel(SettingsProperty property, string value)
: this(property,
new ProfilePropertyInputModel
{
Name = property.Name,
Value = value
})
{
}
示例8: CreateProperty
private Property CreateProperty(PropertyInfo property, SettingsProperty settingsProperty, SettingsPropertyValueCollection settingsPropertyValues)
{
var descriptor = new SettingsPropertyDescriptor(property);
var settingsPropertyValue = settingsPropertyValues[settingsProperty.Name];
var defaultValue = settingsProperty.DefaultValue;
var serializedValue = settingsPropertyValue == null ? null : settingsPropertyValue.SerializedValue;
return new Property(descriptor, (serializedValue ?? defaultValue).ToString());
}
示例9: Add
public void Add ()
{
SettingsPropertyCollection col = new SettingsPropertyCollection ();
SettingsProperty test_prop = new SettingsProperty ("test_prop");
Assert.AreEqual (0, col.Count, "A1");
col.Add (test_prop);
Assert.AreEqual (1, col.Count, "A2");
}
示例10: SettingsProperty
public SettingsProperty (SettingsProperty propertyToCopy)
: this (propertyToCopy.Name,
propertyToCopy.PropertyType,
propertyToCopy.Provider,
propertyToCopy.IsReadOnly,
propertyToCopy.DefaultValue,
propertyToCopy.SerializeAs,
new SettingsAttributeDictionary (propertyToCopy.Attributes),
propertyToCopy.ThrowOnErrorDeserializing,
propertyToCopy.ThrowOnErrorSerializing)
{
}
示例11: IsRoaming
private bool IsRoaming(SettingsProperty prop)
{
foreach (DictionaryEntry entry in prop.Attributes)
{
Attribute attribute = (Attribute) entry.Value;
if (attribute is SettingsManageabilityAttribute)
{
return true;
}
}
return false;
}
示例12: SettingsProperty
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
public SettingsProperty(SettingsProperty propertyToCopy)
{
_Name = propertyToCopy.Name;
_IsReadOnly = propertyToCopy.IsReadOnly;
_DefaultValue = propertyToCopy.DefaultValue;
_SerializeAs = propertyToCopy.SerializeAs;
_Provider = propertyToCopy.Provider;
_PropertyType = propertyToCopy.PropertyType;
_ThrowOnErrorDeserializing = propertyToCopy.ThrowOnErrorDeserializing;
_ThrowOnErrorSerializing = propertyToCopy.ThrowOnErrorSerializing;
_Attributes = new SettingsAttributeDictionary(propertyToCopy.Attributes);
}
示例13: Add
public void Add (SettingsProperty property)
{
if (isReadOnly)
throw new NotSupportedException ();
OnAdd (property);
/* actually do the add */
items.Add (property.Name, property);
OnAddComplete (property);
}
示例14: GetSettingConverter
static SettingsPropertyValue GetSettingConverter(Type type, string name)
{
TypeConverter c = TypeDescriptor.GetConverter(type);
SettingsSerializeAs ssa;
if (c.CanConvertFrom(typeof(string)) && c.CanConvertTo(typeof(string))) {
ssa = SettingsSerializeAs.String;
} else {
ssa = SettingsSerializeAs.Xml;
}
SettingsProperty p = new SettingsProperty(name);
p.PropertyType = type;
p.SerializeAs = ssa;
return new SettingsPropertyValue(p);
}
示例15: Remove
public void Remove ()
{
SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
SettingsProperty test_prop = new SettingsProperty ("test_prop");
SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
col.Add (val);
Assert.AreEqual (1, col.Count, "A1");
col.Remove ("test_prop");
Assert.AreEqual (0, col.Count, "A2");
}