本文整理汇总了C#中Properties.setProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Properties.setProperty方法的具体用法?C# Properties.setProperty怎么用?C# Properties.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Properties
的用法示例。
在下文中一共展示了Properties.setProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadFilePrefsImpl
static java.util.Properties loadFilePrefsImpl(java.io.File file)
{
Properties result = new Properties ();
if (!file.exists ()) {
file.getParentFile ().mkdirs ();
return result;
}
if (file.canRead ()) {
java.io.InputStream inJ = null;
java.nio.channels.FileLock lockJ = null;
try {
java.io.FileInputStream istream = new java.io.FileInputStream (file);
inJ = new java.io.BufferedInputStream (istream);
java.nio.channels.FileChannel channel = istream.getChannel ();
lockJ = channel.lockJ (0L, java.lang.Long.MAX_VALUE, true);
org.w3c.dom.Document doc = builder.parse (inJ);
org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList (doc
.getDocumentElement (), "entry"); //$NON-NLS-1$
int length = entries.getLength ();
for (int i = 0; i < length; i++) {
org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item (i);
String key = node.getAttribute ("key"); //$NON-NLS-1$
String value = node.getAttribute ("value"); //$NON-NLS-1$
result.setProperty (key, value);
}
return result;
} catch (java.io.IOException e) {
} catch (org.xml.sax.SAXException e) {
} catch (javax.xml.transform.TransformerException e) {
// transform shouldn't fail for xpath call
throw new java.lang.AssertionError (e);
} finally {
releaseQuietly (lockJ);
closeQuietly (inJ);
}
} else {
file.delete ();
}
return result;
}
示例2: Main
public static void Main(string[] args)
{
Properties arguments = new Properties();
string error = "";
bool ok = args.Length > 0;
if (ok)
{
arguments.setProperty("Trace", "Off");
arguments.setProperty("Rule", "xri");
for (int i = 0; i < args.Length; i++)
{
if (args[i].Equals("-trace"))
arguments.setProperty("Trace", "On");
else if (args[i].Equals("-visitor"))
arguments.setProperty("Visitor", args[++i]);
else if (args[i].Equals("-file"))
arguments.setProperty("File", args[++i]);
else if (args[i].Equals("-string"))
arguments.setProperty("String", args[++i]);
else if (args[i].Equals("-rule"))
arguments.setProperty("Rule", args[++i]);
else
{
error = "unknown argument: " + args[i];
ok = false;
}
}
}
if (arguments.getProperty("File") == null &&
arguments.getProperty("String") == null)
{
error = "insufficient arguments";
ok = false;
}
if (!ok)
{
Logger.Info("error: " + error);
Logger.Info("usage: Parser [-rule rulename] [-trace] <-file file | -string string> [-visitor visitor]");
}
else
{
try
{
Parser parser = new Parser();
Rule rule = null;
parser.traceOff();
if (arguments.getProperty("Trace").Equals("On"))
parser.traceOn();
if (arguments.getProperty("File") != null)
rule = parser.parse(arguments.getProperty("Rule"), File.OpenRead(arguments.getProperty("File")));
else if (arguments.getProperty("String") != null)
rule = parser.parse(arguments.getProperty("Rule"), arguments.getProperty("String"));
if (arguments.getProperty("Visitor") != null)
{
Visitor visitor =
(Visitor)Activator.CreateInstance(Type.GetType(arguments.getProperty("Visitor")));
visitor.visit(rule);
}
}
catch (ArgumentException e)
{
Logger.Info("argument error: " + e.Message);
}
catch (IOException e)
{
Logger.Info("io error: " + e.Message);
}
catch (ParserException e)
{
Logger.Info("parser error: " + e.Message);
}
catch (TypeLoadException e)
{
Logger.Info("visitor error: class not found - " + e.Message);
}
catch (MethodAccessException e)
{
Logger.Info("visitor error: illegal access - " + e.Message);
}
catch (TargetInvocationException e)
{
Logger.Info("visitor error: instantiation failure - " + e.Message);
}
}
}