private static void SetMetaDataSection(Type cmdLineObjType, ChoObjectInfo objectInfo) { if (cmdLineObjType == null) { return; } string elementPath = cmdLineObjType.Name; using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_metaDataFilepath)) { if (elementPath.IsNullOrEmpty()) { return; } XmlNode node = xmlDocument.XmlDocument.SelectSingleNode(elementPath); if (node == null) { node = xmlDocument.XmlDocument.MakeXPath(elementPath); } if (node != null) { xmlDocument.XmlDocument.InnerXml = ChoXmlDocument.AppendToInnerXml(node, objectInfo.ToXml()); xmlDocument.Save(); } } }
private static ChoObjectInfo GetObjectInfo(Type cmdLineObjType) { string elementPath = cmdLineObjType.Name; if (elementPath.IsNullOrWhiteSpace()) { return(null); } Dictionary <string, ChoObjectInfo> objDict = _objDict; if (!objDict.ContainsKey(elementPath)) { lock (_padLock) { if (!objDict.ContainsKey(elementPath)) { string xpath = @"//{0}/objectInfo".FormatString(elementPath); XmlNode node = null; if (_rootNode != null) { node = _rootNode.SelectSingleNode(xpath); } if (node != null) { objDict.Add(elementPath, ChoObjectInfo.Default); ChoObjectInfo objectInfo = node.ToObject(typeof(ChoObjectInfo)) as ChoObjectInfo; objectInfo.Initialize(); objDict[elementPath] = objectInfo; } else { objDict[elementPath] = ConstructObjectInfos(cmdLineObjType); } } } } return(objDict.ContainsKey(elementPath) ? objDict[elementPath] : null); }
private static ChoObjectInfo ConstructObjectInfos(Type cmdLineObjType) { if (cmdLineObjType != null) { Dictionary <string, ChoObjectInfo> objDict = _objDict; string elementPath = cmdLineObjType.Name; if (elementPath.IsNullOrWhiteSpace()) { return(ChoObjectInfo.Default); } if (!objDict.ContainsKey(elementPath)) { lock (_padLock) { if (!objDict.ContainsKey(elementPath)) { ChoCommandLineArgObjectAttribute commandLineArgObjectAttribute = ChoType.GetAttribute <ChoCommandLineArgObjectAttribute>(cmdLineObjType); if (commandLineArgObjectAttribute != null) { ChoObjectInfo objInfo = new ChoObjectInfo(); objInfo.ApplicationName = commandLineArgObjectAttribute.ApplicationName; objInfo.Copyright = commandLineArgObjectAttribute.Copyright; objInfo.Description = new ChoCDATA(commandLineArgObjectAttribute.Description); objInfo.Version = commandLineArgObjectAttribute.Version; objInfo.AdditionalInfo = new ChoCDATA(commandLineArgObjectAttribute.AdditionalInfo); objInfo.ShowUsageIfEmpty = commandLineArgObjectAttribute.ShowUsageIfEmptyInternal; objInfo.DisplayDefaultValue = commandLineArgObjectAttribute.DisplayDefaultValueInternal; objInfo.DoNotShowUsageDetail = commandLineArgObjectAttribute.DoNotShowUsageDetail; SetMetaDataSection(cmdLineObjType, objInfo); return(objInfo); } } } } } return(ChoObjectInfo.Default); }
internal static void LoadFromConfig(Type cmdLineObjType, ChoCommandLineArgObjectAttribute attr) { if (attr == null) { return; } ChoObjectInfo objInfo = GetObjectInfo(cmdLineObjType); if (objInfo != null) { if (!objInfo.ApplicationName.IsNullOrEmpty()) { attr.ApplicationName = objInfo.ApplicationName; } if (objInfo.AdditionalInfo != null && !objInfo.AdditionalInfo.Value.IsNullOrEmpty()) { attr.AdditionalInfo = objInfo.AdditionalInfo.Value; } if (!objInfo.Copyright.IsNullOrEmpty()) { attr.Copyright = objInfo.Copyright; } if (objInfo.Description != null && !objInfo.Description.Value.IsNullOrEmpty()) { attr.Description = objInfo.Description.Value; } attr.DoNotShowUsageDetail = objInfo.DoNotShowUsageDetail; if (objInfo.ShowUsageIfEmpty.HasValue) { attr.ShowUsageIfEmptyInternal = objInfo.ShowUsageIfEmpty.Value; } if (objInfo.DisplayDefaultValue.HasValue) { attr.DisplayDefaultValueInternal = objInfo.DisplayDefaultValue.Value; } if (!objInfo.Version.IsNullOrEmpty()) { attr.Version = objInfo.Version; } } }