internal static bool TryGetDefaultValue(ChoCommandLineArgObject target, string propName, ChoDefaultCommandLineArgAttribute memberInfoAttribute, out string defaultValue) { defaultValue = null; ChoGuard.ArgumentNotNull(target, "CommandLineArgObject"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(target); if (propertyInfo != null) { ChoPropertyInfo propInfo = propertyInfo[propName]; if (propInfo == null) { if (memberInfoAttribute != null && memberInfoAttribute.IsDefaultValueSpecified) { defaultValue = memberInfoAttribute.DefaultValue; return(memberInfoAttribute.IsDefaultValueSpecified); } } defaultValue = propInfo != null && propInfo.DefaultValue != null ? propInfo.DefaultValue.Value : null; return(propInfo != null ? propInfo.IsDefaultValueSpecified : false); } else if (memberInfoAttribute != null && memberInfoAttribute.IsDefaultValueSpecified) { defaultValue = memberInfoAttribute.DefaultValue; return(memberInfoAttribute.IsDefaultValueSpecified); } return(false); }
private static ChoPropertyInfos GetPropertyInfos(ChoCommandLineArgObject cmdLineArgObject) { string elementPath = cmdLineArgObject.GetType().Name; if (elementPath.IsNullOrWhiteSpace()) { return(null); } Dictionary <string, ChoPropertyInfos> propDict = _propDict; if (!propDict.ContainsKey(elementPath)) { lock (_padLock) { if (!propDict.ContainsKey(elementPath)) { string xpath = @"//{0}/propertyInfos".FormatString(elementPath); XmlNode node = null; if (_rootNode != null) { node = _rootNode.SelectSingleNode(xpath); } if (node != null) { propDict.Add(elementPath, ChoPropertyInfos.Default); ChoPropertyInfos propertyInfos = node.ToObject(typeof(ChoPropertyInfos)) as ChoPropertyInfos; propertyInfos.Initialize(); propDict[elementPath] = propertyInfos; } else { propDict[elementPath] = ConstructPropertyInfos(cmdLineArgObject); } } } } return(propDict.ContainsKey(elementPath) ? propDict[elementPath] : null); }
private static void SetMetaDataSection(ChoCommandLineArgObject cmdLineArgObject, ChoPropertyInfos propertyInfos) { return; if (cmdLineArgObject == null) { return; } string elementPath = cmdLineArgObject.GetType().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, propertyInfos.ToXml()); xmlDocument.Save(); } } }
private static ChoPropertyInfos ConstructPropertyInfos(ChoCommandLineArgObject cmdLineArgObject) { if (cmdLineArgObject != null) { Dictionary <string, ChoPropertyInfos> propDict = _propDict; string elementPath = cmdLineArgObject.GetType().Name; if (elementPath.IsNullOrWhiteSpace()) { return(ChoPropertyInfos.Default); } if (!propDict.ContainsKey(elementPath)) { lock (_padLock) { if (!propDict.ContainsKey(elementPath)) { MemberInfo[] memberInfos = ChoTypeMembersCache.GetAllMemberInfos(cmdLineArgObject.GetType()); if (memberInfos != null && memberInfos.Length > 0) { //Set member values List <ChoPropertyInfo> propertyInfoList = new List <ChoPropertyInfo>(); ChoDefaultCommandLineArgAttribute memberInfoAttribute = null; foreach (MemberInfo memberInfo in memberInfos) { memberInfoAttribute = (ChoDefaultCommandLineArgAttribute)ChoType.GetMemberAttributeByBaseType(memberInfo, typeof(ChoDefaultCommandLineArgAttribute)); if (memberInfoAttribute == null) { continue; } ChoPropertyInfo propInfo = new ChoPropertyInfo(); propInfo.Name = ChoType.GetMemberName(memberInfo); if (ChoType.GetMemberType(memberInfo) != typeof(bool)) { propInfo.DefaultValue = new ChoCDATA(memberInfoAttribute.DefaultValue); propInfo.FallbackValue = new ChoCDATA(memberInfoAttribute.FallbackValue); propInfo.IsDefaultValueSpecified = memberInfoAttribute.IsDefaultValueSpecified; propInfo.IsFallbackValueSpecified = memberInfoAttribute.IsFallbackValueSpecified; propertyInfoList.Add(propInfo); } } if (propertyInfoList != null) { ChoPropertyInfos propertyInfos = new ChoPropertyInfos(); propertyInfos.PropertyInfoArr = propertyInfoList.ToArray(); SetMetaDataSection(cmdLineArgObject, propertyInfos); return(propertyInfos); } } } } } } return(ChoPropertyInfos.Default); }