read appSettings in configuration file by XElement with xmlns
in with File by Read configuration
2023-09-11 14:14:21 时间
public static int GetProgramId(string filePath) { int programId = 0; var element = XElement.Load(filePath); XNamespace xNamespace = element.GetDefaultNamespace(); XName tempXName1 = xNamespace + "appSettings"; var temp = element.Element(tempXName1); XName tempXName2 = xNamespace + "add"; var targetElement = temp?.Elements(tempXName2) .FirstOrDefault(x => x.Attribute("key")?.Value == "ProgramID"); if (targetElement == null) { LogUtil.CreateLog(LogLevel.Error, $"Can not find ProgramID in appSettings section in {filePath}"); } else { var valueAttribute = targetElement.Attribute("value"); if (valueAttribute == null) { LogUtil.CreateLog(LogLevel.Error, $"Can not find value attribute in appSettings section with key = ProgramID in {filePath}"); } else { programId = Convert.ToInt32(valueAttribute.Value); } } return programId; }
相关文章
- [Android Pro] 完美解决 No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
- 【异常】idea执行Main方法出现 Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 解决办法
- [TS] Implement a doubly linked list in TypeScript
- [React] Linting React JSX with ESLint (in ES6)
- not defined in file libmysqlclient.so.18 with link time reference
- java.lang.UnsatisfiedLinkError:no dll in java.library.path终极解决之道
- [AWS Amplify] Store Data in Amazon S3 with React + Amplify
- [PWA] Cache JSON Data in a React PWA with Workbox, and Display it while Offline
- [Node.js] Write or Append to a File in Node.js with fs.writeFile and fs.writeFileSync
- [TypeScript] Query Properties with keyof and Lookup Types in TypeScript
- [React] Work with HTML Canvas in React
- [RxJS] Flatten a higher order observable with concatAll in RxJS
- [Angular 2] Filter items with a custom search Pipe in Angular 2
- [React] Linting React JSX with ESLint (in ES6)
- [AngularJS] Using Services in Angular Directives
- SAP CRM WebClient UI Date time format in BSP UI
- how to use object based exception combined with message class in SE91
- 成功解决ValueError: Dimension 1 in both shapes must be equal, for ‘Assign_8‘ (op: ‘Assign‘) with input s
- 已解决FutureWarning: The default value of regex will change from True to False in a future version. In
- Web IDL in Blink
- FastAdmin 升级后出现 is already in use
- 《论文阅读》EmoBERTa: Speaker-Aware Emotion Recognition in Conversation with RoBERTa
- git 警告: LF will be replaced by CRLF in 解决办法