internal static void Initialize() { //ChoStreamProfile.Clean(ChoReservedDirectoryName.Others, ChoType.GetLogFileName(typeof(ChoTypesManager))); StringBuilder topMsg = new StringBuilder(); ChoStringMsgBuilder parseMethodsMsg = new ChoStringMsgBuilder("Below are the loaded parse methods"); ChoStringMsgBuilder formatMethodsMsg = new ChoStringMsgBuilder("Below are the loaded format methods"); ChoStringMsgBuilder msg = new ChoStringMsgBuilder("Below are the loaded type objects"); foreach (Type type in ChoType.GetTypes(typeof(ChoStringObjectFormattableAttribute))) { if (ChoTypesManagerSettings.IsExcludedType(type)) { continue; } ChoTypeObjectParseInfo typeObjectParseInfo = new ChoTypeObjectParseInfo(); ChoTypeObjectFormatInfo typeObjectFormatInfo = new ChoTypeObjectFormatInfo(); try { //typeObjectFormatInfo.TypeObject = typeObjectParseInfo.TypeObject = ChoObject.CreateInstance(type); msg.AppendFormatLine(type.FullName); } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { msg.AppendFormatLine("{0}: [{1}]", type.FullName, ex.Message); } LoadObjectParser(parseMethodsMsg, type, typeObjectParseInfo); LoadObjectFormatter(formatMethodsMsg, type, typeObjectFormatInfo); } _typeObjectsParseInfoArr = TypeObjectsParseInfo.Values.ToArray(); _typeObjectsFormatInfoArr = TypeObjectsFormatInfo.Values.ToArray(); //_typeObjectsParseInfo.Clear(); //_typeObjectsFormatInfo.Clear(); topMsg.Append(parseMethodsMsg.ToString() + Environment.NewLine + Environment.NewLine); topMsg.Append(formatMethodsMsg.ToString() + Environment.NewLine + Environment.NewLine); topMsg.Append(msg.ToString() + Environment.NewLine + Environment.NewLine); _helpText = topMsg.ToString(); }
private static void LoadObjectParser(ChoStringMsgBuilder parseMethodsMsg, Type type, ChoTypeObjectParseInfo typeObjectParseInfo) { ChoStringObjectFormattableAttribute attr = ChoType.GetAttribute <ChoStringObjectFormattableAttribute>(type); try { MethodInfo isParseMethodInfo = ChoType.GetMethod(type, typeof(ChoIsStringToObjectConvertable), true); if (isParseMethodInfo != null && isParseMethodInfo.IsStatic) { if (isParseMethodInfo.ReturnParameter == null || isParseMethodInfo.ReturnParameter.ParameterType != typeof(bool)) { throw new ChoApplicationException(String.Format("{0}: Incorrect Check Parse routine signature found. It should have bool return parameter.", type.Name)); } ParameterInfo[] parameters = isParseMethodInfo.GetParameters(); if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != typeof(string)) { throw new ChoApplicationException(String.Format("{0}: Incorrect Check Parse routine signature found. It should have one and only input string parameter.", type.Name)); } MethodInfo parseMethodInfo = ChoType.GetMethod(type, typeof(ChoStringToObjectConverterAttribute), true); if (parseMethodInfo != null) { parameters = parseMethodInfo.GetParameters(); if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != typeof(string)) { throw new ChoApplicationException(String.Format("{0}: Incorrect Parse routine signature found. It should have one and only input string parameter.", type.Name)); } typeObjectParseInfo.CheckParse = isParseMethodInfo.CreateDelegate <Func <string, bool> >(); typeObjectParseInfo.Parse = parseMethodInfo.CreateDelegate <Func <string, object> >(); parseMethodsMsg.AppendFormatLine("{0} [EX: {1}]", type.FullName, ((IChoStringObjectFormatter)Activator.CreateInstance(type)).GetHelpText()); } } } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { parseMethodsMsg.AppendFormatLine("{0}: [{1}]", type.FullName, ex.Message); } Type type1 = attr.SupportedType == null?type.GetType() : attr.SupportedType; if (typeObjectParseInfo.IsValid()) { if (TypeObjectsParseInfo.ContainsKey(type1)) { TypeObjectsParseInfo[type1] = typeObjectParseInfo; } else { TypeObjectsParseInfo.Add(type1, typeObjectParseInfo); } } }