当前位置: 首页>>代码示例>>C#>>正文


C# IFile.exists方法代码示例

本文整理汇总了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;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:39,代码来源:ProjectProperties.stab.cs

示例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);
			}
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:44,代码来源:ProjectProperties.stab.cs


注:本文中的IFile.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。