本文整理汇总了C#中Settings.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Settings.GetType方法的具体用法?C# Settings.GetType怎么用?C# Settings.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Settings
的用法示例。
在下文中一共展示了Settings.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OkClick
private void OkClick(object sender, RoutedEventArgs e)
{
//SerializeStatic.Save(settings.GetType(), "settings.xml");
settingRes = settings;
var writer = new StreamWriter("settings.xml", false);
var serializer = new XmlSerializer(settingRes.GetType());
serializer.Serialize(writer, settingRes);
writer.Close();
DialogResult = true;
}
示例2: PopulateSettings
public Settings.SettingsBase PopulateSettings(Settings.SettingsBase instance)
{
var type = instance.GetType();
var prefix = type.Name + ".";
var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.Where(x => x.CanWrite);
foreach (var pi in props)
{
try
{
var value = ConfigurationManager.AppSettings[prefix + pi.Name];
if (value == null)
{
instance.AddProblem(new ConvertProblem
{
PropertyName = pi.Name,
Exception = new Exception(
string.Format("Property [{0}{1}] not found in web.config", prefix, pi.Name))
});
}
// convert object to property type
var converted = GetConvertedValue(pi, value);
pi.SetValue(instance, converted, null);
}
catch (Exception e)
{
// silently add convert problem to instance
// so you can debug it in runtime
instance.AddProblem(new ConvertProblem
{
PropertyName = pi.Name,
Exception = e
});
}
}
return instance;
}
示例3: SaveItem
private void SaveItem(XmlDocument xmlDocument, Settings settings, String key, Object value, String serializerMethodName)
{
XmlElement rootEl = xmlDocument.DocumentElement;
if (rootEl == null)
throw new Exception("Xml document has no root element");
XmlNode itemNode = xmlDocument.SelectSingleNode("descendant::item[@key='" + key + "']");
//item is absent in the document
if (itemNode == null)
{
itemNode = xmlDocument.CreateElement("item");
rootEl.AppendChild(itemNode);
itemNode.AppendAttribute("key", key);
String strValue = null;
if (String.IsNullOrEmpty(serializerMethodName))
{
strValue = SerializeObject(value);
}
else
{
MethodInfo methodInfo = settings.GetType().GetMethod(serializerMethodName,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
if (methodInfo != null)
{
strValue = methodInfo.Invoke(this, new[] { value }).ToString();
}
}
if (strValue != null)
{
itemNode.InnerXml = strValue;
}
else
{
itemNode.AppendAttribute("IsNull", "true");
}
}
else
{
throw new Exception("Trying to add duplicated xml element");
}
}
示例4: DeserializeObject
private static Object DeserializeObject(Settings settings, Type type, String xml, String deserializerMethodName)
{
try
{
if (String.IsNullOrEmpty(deserializerMethodName))
{
return DeserializeObject(xml, type);
}
MethodInfo methodInfo = settings.GetType().GetMethod(deserializerMethodName,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
return methodInfo != null ? methodInfo.Invoke(null, new[] { xml }) : null;
}
catch (Exception ex)
{
throw new SerializationException(
string.Format("Cannot desirialize type {0} from xml:'{1}'. Deserializating method: {2}",
type.FullName, xml, deserializerMethodName), ex);
}
}
示例5: setConnectionReleaseModeByReflection
/// <summary>
/// Sets the <see cref="Settings.ConnectionReleaseMode"/> by reflection.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="mode">The mode.</param>
private void setConnectionReleaseModeByReflection(Settings settings, ConnectionReleaseMode mode)
{
PropertyInfo pInfoConnectionReleaseMode =
settings.GetType().GetProperty(
"ConnectionReleaseMode",
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.SetProperty |
BindingFlags.Instance);
pInfoConnectionReleaseMode.SetValue(settings, mode, null);
}
示例6: PopulateSetting
private Settings PopulateSetting(Settings newSettings)
{
foreach (KeyValuePair<string, object> entry in MyInvocation.BoundParameters)
{
string param = entry.Key;
if (entry.Key.StartsWith("Backup"))
{
param = Regex.Replace(param, @"^Backup", string.Empty);
var prop = newSettings.BackupConfiguration.GetType().GetProperty(param);
prop.SetValue(newSettings.BackupConfiguration, entry.Value);
}
else if (entry.Key.StartsWith("IpConfig"))
{
param = Regex.Replace(param, @"^IpConfig", string.Empty);
if (param.Equals("AuthorizedNetwork"))
{
param = "AuthorizedNetworks";
}
var prop = newSettings.IpConfiguration.GetType().GetProperty(param);
prop.SetValue(newSettings.IpConfiguration, entry.Value);
}
else if (entry.Key.StartsWith("LocationPreference"))
{
if (newSettings.LocationPreference == null)
{
newSettings.LocationPreference = new LocationPreference();
}
param = Regex.Replace(param, @"^LocationPreference", string.Empty);
if (param.Equals("FollowGae"))
{
param = "FollowGaeApplication";
}
var prop = newSettings.LocationPreference.GetType().GetProperty(param);
prop.SetValue(newSettings.LocationPreference, entry.Value);
}
else if (entry.Key.StartsWith("MaintenanceWindow"))
{
if (newSettings.MaintenanceWindow == null)
{
newSettings.MaintenanceWindow = new MaintenanceWindow();
}
param = Regex.Replace(param, @"^MaintenanceWindow", string.Empty);
var prop = newSettings.MaintenanceWindow.GetType().GetProperty(param);
prop.SetValue(newSettings.MaintenanceWindow, entry.Value);
}
else
{
//Some parameters aren't used or don't match up perfectly.
if (param.Equals("Update") | param.Equals("Project") | param.Equals("Instance")
| param.Equals("InstanceObject"))
{
continue;
}
else if (param.Equals("DiskType"))
{
newSettings.DataDiskType = entry.Value.ToString();
}
else if (param.Equals("Policy"))
{
newSettings.ActivationPolicy = entry.Value.ToString();
}
else if (param.Equals("DatabaseFlag"))
{
DatabaseFlags[] flags = (DatabaseFlags[])entry.Value;
}
else
{
var prop = newSettings.GetType().GetProperty(param);
prop.SetValue(newSettings, entry.Value);
}
}
};
return newSettings;
}