本文整理汇总了C#中FavoriteConfigurationElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# FavoriteConfigurationElement.GetType方法的具体用法?C# FavoriteConfigurationElement.GetType怎么用?C# FavoriteConfigurationElement.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FavoriteConfigurationElement
的用法示例。
在下文中一共展示了FavoriteConfigurationElement.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFavorite
private static void WriteFavorite(XmlTextWriter w, bool includePassword, FavoriteConfigurationElement favorite)
{
if (favorite == null)
return;
if (w.WriteState == WriteState.Closed || w.WriteState == WriteState.Error)
return;
w.WriteStartElement("favorite");
PropertyInfo[] infos = favorite.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.GetProperty);
foreach (PropertyInfo info in infos)
{
if (info.Name == "UserName" || info.Name == "Password" || info.Name == "DomainName" || info.Name == "EncryptedPassword" ||
info.Name == "TsgwUsername" || info.Name == "TsgwPassword" || info.Name == "TsgwDomain" || info.Name == "TsgwEncryptedPassword")
if (!includePassword)
continue;
if (info.Name == "HtmlFormFields")
{
w.WriteElementString("HtmlFormFieldsString", favorite.GetType().GetProperty("HtmlFormFieldsString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(favorite, null).ToString());
continue;
}
// Has already been exported as favorite.Tag
// favorite.TagList is only for a human readable
// list of strings.
// The same applies to "RedirectedDrives" which is handled by
// "redirectDrives"
if (info.Name == "TagList" || info.Name == "RedirectedDrives")
{
continue;
}
object value = info.GetValue(favorite, null);
// if a value is null than the tostring wouldn't be callable. ->
// therefore set it to string.Empty.
if (value == null || string.IsNullOrEmpty(value.ToString()))
value = string.Empty;
w.WriteElementString(info.Name, value.ToString());
}
w.WriteEndElement();
}
示例2: ReadProperty
private static FavoriteConfigurationElement ReadProperty(XmlTextReader reader,
List<FavoriteConfigurationElement> favorites,
FavoriteConfigurationElement favorite)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.Name)
{
case "favorite":
favorite = new FavoriteConfigurationElement();
favorites.Add(favorite);
break;
default:
if (favorite == null)
break;
PropertyInfo property = favorite.GetType().GetProperty(reader.Name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if (property == null)
break;
// Check if the property has a setter -> if not break;
MethodInfo propertySetter = property.GetSetMethod(true);
if (propertySetter == null)
break;
try
{
if (property.GetValue(favorite, null) is Boolean)
{
property.SetValue(favorite, Convert.ToBoolean(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Decimal)
{
property.SetValue(favorite, Convert.ToDecimal(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Double)
{
property.SetValue(favorite, Convert.ToDouble(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Byte)
{
property.SetValue(favorite, Convert.ToByte(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Char)
{
property.SetValue(favorite, Convert.ToChar(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is DateTime)
{
property.SetValue(favorite, Convert.ToDateTime(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Int16)
{
property.SetValue(favorite, Convert.ToInt16(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Int32)
{
property.SetValue(favorite, Convert.ToInt32(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Int64)
{
property.SetValue(favorite, Convert.ToInt64(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is SByte)
{
property.SetValue(favorite, Convert.ToSByte(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Single)
{
property.SetValue(favorite, Convert.ToSingle(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is UInt16)
{
property.SetValue(favorite, Convert.ToUInt16(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is UInt32)
{
property.SetValue(favorite, Convert.ToUInt32(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is UInt64)
{
property.SetValue(favorite, Convert.ToUInt64(reader.ReadString()), null);
}
else if (property.GetValue(favorite, null) is Enum)
{
property.SetValue(favorite, Enum.Parse(property.GetValue(favorite, null).GetType(), reader.ReadString()), null);
}
else
property.SetValue(favorite, reader.ReadString(), null);
break;
}
catch
{
Log.Warn(string.Format("Unable to set property '{0}'.", reader.Name));
break;
}
}
//.........这里部分代码省略.........
示例3: ImportConfiguration
private System.Configuration.Configuration ImportConfiguration()
{
// get a temp filename to hold the current settings which are failing
string tempFile = Path.GetTempFileName();
fileWatcher.StopObservation();
MoveAndDeleteFile(fileLocations.Configuration, tempFile);
SaveDefaultConfigFile();
fileWatcher.StartObservation();
System.Configuration.Configuration c = OpenConfiguration();
// get a list of the properties on the Settings object (static props)
PropertyInfo[] propList = typeof(Settings).GetProperties();
// read all the xml from the erroring file
XmlDocument doc = new XmlDocument();
doc.LoadXml(File.ReadAllText(tempFile));
// get the settings root
XmlNode root = doc.SelectSingleNode("/configuration/settings");
try
{
// for each setting's attribute
foreach (XmlAttribute att in root.Attributes)
{
// scan for the related property if any
try
{
foreach (PropertyInfo info in propList)
{
try
{
if (info.Name.ToLower() == att.Name.ToLower())
{
// found a matching property, try to set it
string val = att.Value;
info.SetValue(null, Convert.ChangeType(val, info.PropertyType), null);
break;
}
}
catch (Exception exc)
{ // ignore the error
Logging.Error("Remapping Settings Inner", exc);
}
}
}
catch (Exception exc) // ignore the error
{
Logging.Error("Remapping Settings Outer", exc);
}
}
}
catch (Exception exc) // ignore the error
{
Logging.Error("Remapping Settings Outer Try", exc);
}
XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add");
try
{
foreach (XmlNode fav in favs)
{
try
{
FavoriteConfigurationElement newFav = new FavoriteConfigurationElement();
foreach (XmlAttribute att in fav.Attributes)
{
try
{
foreach (PropertyInfo info in newFav.GetType().GetProperties())
{
try
{
if (info.Name.ToLower() == att.Name.ToLower())
{
// found a matching property, try to set it
string val = att.Value;
if (info.PropertyType.IsEnum)
{
info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null);
}
else
{
info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null);
}
break;
}
}
catch (Exception exc) // ignore the error
{
Logging.Error("Remapping Favorites 1", exc);
}
}
}
catch (Exception exc) // ignore the error
{
Logging.Error("Remapping Favorites 2", exc);
}
}
//.........这里部分代码省略.........
示例4: ImportConfiguration
//.........这里部分代码省略.........
// domainsMRUList
// tags -> werden implizit durch die Favorites gesetzt - Überprüfen ob korrekt
// Nicht alle Felder bei den Favorites werden gesetzt
// Work through every favorite configuration element
XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add");
try
{
foreach (XmlNode fav in favs)
{
FavoriteConfigurationElement newFav = new FavoriteConfigurationElement();
// Add the plugin configuration for each favorite element
if (fav.ChildNodes != null && fav.ChildNodes.Count == 1)
{
XmlNode pluginRootElement = fav.ChildNodes[0];
if (pluginRootElement.Name.Equals("PLUGINS", StringComparison.InvariantCultureIgnoreCase))
{
foreach (XmlNode plugin in pluginRootElement.ChildNodes)
{
if (plugin.Name.Equals("PLUGIN", StringComparison.InvariantCultureIgnoreCase) && plugin.Attributes != null && plugin.Attributes.Count > 0)
{
PluginConfiguration pluginConfig = new PluginConfiguration();
if (plugin.Attributes["name"] != null && !string.IsNullOrEmpty(plugin.Attributes["name"].Value))
pluginConfig.Name = plugin.Attributes["name"].Value;
if (plugin.Attributes["value"] != null && !string.IsNullOrEmpty(plugin.Attributes["value"].Value))
{
pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("value", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["value"].Value, null);
}
if (plugin.Attributes["defaultValue"] != null && !string.IsNullOrEmpty(plugin.Attributes["defaultValue"].Value))
{
pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("defaultValue", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["defaultValue"].Value, null);
}
newFav.PluginConfigurations.Add(pluginConfig);
}
}
}
}
// Add the attributes of each favorite
foreach (XmlAttribute att in fav.Attributes)
{
foreach (PropertyInfo info in newFav.GetType().GetProperties())
{
try
{
if (info.Name.ToLower() == att.Name.ToLower())
{
// found a matching property, try to set it
string val = att.Value;
if (info.PropertyType.IsEnum)
{
info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null);
}
else
{
info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null);
}