本文整理汇总了C#中IFile.exists方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.exists方法的具体用法?C# IFile.exists怎么用?C# IFile.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFile
的用法示例。
在下文中一共展示了IFile.exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: load
public bool load(IFile file) {
if (file.exists()) {
try {
var libraries = new ArrayList<ProjectLibrary>();
var preprocessorSymbols = new HashSet<String>();
var outputPath = "bin";
var document = XmlHelper.load(new InputStreamReader(file.getContents()));
var nodeList = document.getElementsByTagName("library");
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
var e = (Element)nodeList.item(i);
var lib = new ProjectLibrary(e.getAttribute("name"));
var enabled = e.getAttribute("enabled");
lib.setEnabled(enabled.length() == 0 || !enabled.equals("false"));
libraries.add(lib);
}
nodeList = document.getElementsByTagName("preprocessorSymbols");
if (nodeList.getLength() == 1) {
foreach (var s in nodeList.item(0).getTextContent().split(";")) {
preprocessorSymbols.add(s.trim());
}
}
nodeList = document.getElementsByTagName("outputPath");
if (nodeList.getLength() == 1) {
outputPath = nodeList.item(0).getTextContent();
}
this.Libraries = libraries;
this.PreprocessorSymbols = preprocessorSymbols;
this.OutputPath = outputPath;
return true;
} catch (Exception e) {
Environment.logException(e);
}
}
this.Libraries = Query.empty<ProjectLibrary>();
this.PreprocessorSymbols = Query.empty<String>();
return false;
}
示例2: save
public void save(IFile file) {
try {
var document = XmlHelper.load(new StringReader(EMPTY_DOC));
var libs = (Element)document.getElementsByTagName("libraries").item(0);
foreach (var lib in this.Libraries) {
var e = document.createElement("library");
libs.appendChild(e);
e.setAttribute("name", lib.Path);
if (!lib.Enabled) {
e.setAttribute("enabled", "false");
}
}
if (this.PreprocessorSymbols.any()) {
var sb = new StringBuilder();
var first = true;
foreach (String s in this.PreprocessorSymbols) {
if (first) {
first = false;
} else {
sb.append(';');
}
sb.append(s);
}
var e = document.createElement("preprocessorSymbols");
document.getDocumentElement().appendChild(e);
e.setTextContent(sb.toString());
}
var outputElt = document.createElement("outputPath");
document.getDocumentElement().appendChild(outputElt);
outputElt.setTextContent(this.OutputPath);
var writer = new StringWriter();
XmlHelper.save(document, writer);
var bytes = writer.toString().getBytes("UTF-8");
var stream = new ByteArrayInputStream(bytes);
if (file.exists()) {
file.setContents(stream, IResource.FORCE, null);
} else {
file.create(stream, true, null);
}
} catch (Exception e) {
Environment.logException(e);
}
}