// This method returns the command line argument string. public static CommandLineInfo GetCommandLineInfo(Project p) { /*=== Read the options. ===*/ Options gOptions = GetGlobalOptions().GetGlobalConfiguration().Options; Options pOptions = GetProjectOptions(p).GetActiveConfiguration().Options; /*=== Use reflection to build the command line string. ===*/ string cmd = ""; FieldInfo[] oFields; Type oType = typeof(Options); char[] trimchars = { '"' }; // Get the fields for type 'Options'. oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance); /*=== Loop through the data members in the 'Options' object. ===*/ for (int i = 0; i < oFields.Length; i++) { /*=== If the current field is not an option, ignore it. ===*/ if (!oFields[i].FieldType.IsSubclassOf(typeof(OptionBase))) { continue; } /*=== Parse this option's attributes. ===*/ List <Attribute> attrs = AttributeUtility.GetAllAttributes(oFields[i], false); OptionInfo info = new OptionInfo(attrs); // If a commandline syntax isn't specified, ignore this option. if (info.CommandLine == "") { continue; } string tag = info.CommandLine; // Handle string list options. if (oFields[i].FieldType == typeof(StringListOption)) { StringListOption gOption = (StringListOption)oFields[i].GetValue(gOptions); StringListOption pOption = (StringListOption)oFields[i].GetValue(pOptions); int gsize = gOption.StringList.Count; int psize = pOption.StringList.Count; if (gsize > 0) { cmd += " " + tag + " "; cmd += '"' + gOption.StringList[0].Trim(trimchars) + '"'; for (int j = 1; j < gsize; j++) { cmd += "," + '"' + gOption.StringList[j].Trim(trimchars) + '"'; } } if (psize > 0) { int j = 0; if (gsize < 1) { cmd += " " + tag + " "; cmd += '"' + pOption.StringList[0].Trim(trimchars) + '"'; j = 1; } for (; j < psize; j++) { cmd += "," + '"' + pOption.StringList[j].Trim(trimchars) + '"'; } } } // Handle string options. else if (oFields[i].FieldType == typeof(StringOption)) { StringOption gOption = (StringOption)oFields[i].GetValue(gOptions); StringOption pOption = (StringOption)oFields[i].GetValue(pOptions); if (pOption.Value != "") { cmd += " " + tag + " " + '"' + pOption.Value.Trim(trimchars) + '"'; } else if (gOption.Value != "") { cmd += " " + tag + " " + '"' + gOption.Value.Trim(trimchars) + '"'; } } // Handle boolean options. else if (oFields[i].FieldType == typeof(BoolOption)) { BoolOption gOption = (BoolOption)oFields[i].GetValue(gOptions); BoolOption pOption = (BoolOption)oFields[i].GetValue(pOptions); bool on = pOption.UseDefault ? gOption.Value : pOption.Value; if (on) { cmd += " " + tag; } } // Handle int options. else if (oFields[i].FieldType == typeof(IntOption)) { IntOption gOption = (IntOption)oFields[i].GetValue(gOptions); IntOption pOption = (IntOption)oFields[i].GetValue(pOptions); int val = pOption.UseDefault ? gOption.Value : pOption.Value; cmd += " " + tag + " " + val; } } /*=== Setup the command line info data structure. ===*/ CommandLineInfo cmdinfo = new CommandLineInfo(); /*=== set the license path ===*/ if (pOptions.LicensePath.Value != "") { cmd += " -license " + '"' + pOptions.LicensePath.Value.Trim(trimchars) + '"'; } else if (gOptions.LicensePath.Value != "") { cmd += " -license " + '"' + gOptions.LicensePath.Value.Trim(trimchars) + '"'; } else { cmd += " -license " + '"' + opLicenseUtility.FullLicenseFileName + '"'; } cmdinfo.Arguments = cmd; /*=== set the executable path ===*/ if (pOptions.ExecutablePath.Value != "") { cmdinfo.ExecutablePath = pOptions.ExecutablePath.Value.Trim(trimchars); } else if (gOptions.ExecutablePath.Value != "") { cmdinfo.ExecutablePath = gOptions.ExecutablePath.Value.Trim(trimchars); } else { cmdinfo.ExecutablePath = Path.GetFullPath(Paths.GetFullAppPath() + "..\\Release\\opCpp.exe"); } return(cmdinfo); }
/*=== construction ===*/ public OptionInfo(List <Attribute> attrs) { /*=== name ===*/ OptionNameAttribute name = (OptionNameAttribute)AttributeUtility.GetAttribute <OptionNameAttribute>(attrs); if (name != null) { Name = name.OptionName; } /*=== is global ===*/ IsGlobalOptionAttribute isGlobal = (IsGlobalOptionAttribute)AttributeUtility.GetAttribute <IsGlobalOptionAttribute>(attrs); if (isGlobal != null) { IsGlobal = true; } /*=== is project ===*/ IsProjectOptionAttribute isProject = (IsProjectOptionAttribute)AttributeUtility.GetAttribute <IsProjectOptionAttribute>(attrs); if (isProject != null) { IsProject = true; } /*=== category ===*/ OptionCategoryAttribute category = (OptionCategoryAttribute)AttributeUtility.GetAttribute <OptionCategoryAttribute>(attrs); if (category != null) { Category = category.OptionCategory; } /*=== description ===*/ OptionDescriptionAttribute description = (OptionDescriptionAttribute)AttributeUtility.GetAttribute <OptionDescriptionAttribute>(attrs); if (description != null) { Description = description.OptionDescription; } /*=== editor type ===*/ OptionEditorTypeAttribute editorType = (OptionEditorTypeAttribute)AttributeUtility.GetAttribute <OptionEditorTypeAttribute>(attrs); if (editorType != null) { EditorType = editorType.OptionEditorType.AssemblyQualifiedName; } /*=== global type converter ===*/ GlobalOptionTypeConverterAttribute globalTypeConverter = (GlobalOptionTypeConverterAttribute)AttributeUtility.GetAttribute <GlobalOptionTypeConverterAttribute>(attrs); if (globalTypeConverter != null) { GlobalTypeConverter = globalTypeConverter.OptionTypeConverter.AssemblyQualifiedName; } /*=== project type converter ===*/ ProjectOptionTypeConverterAttribute projectTypeConverter = (ProjectOptionTypeConverterAttribute)AttributeUtility.GetAttribute <ProjectOptionTypeConverterAttribute>(attrs); if (projectTypeConverter != null) { ProjectTypeConverter = projectTypeConverter.OptionTypeConverter.AssemblyQualifiedName; } /*=== command line converter ===*/ CommandLineAttribute commandLine = (CommandLineAttribute)AttributeUtility.GetAttribute <CommandLineAttribute>(attrs); if (commandLine != null) { CommandLine = commandLine.CommandLine; } }