コード例 #1
0
        // This method actually converts from a string to a BoolOption.
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                string       val    = (string)value;
                StringOption option = new StringOption();

                option.Value = val;

                return(option);
            }

            return(base.ConvertFrom(context, culture, value));
        }
コード例 #2
0
        // This method fires when the user wishes to edit a value.
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            StringOption   option = (StringOption)value;
            OpenFileDialog form   = new OpenFileDialog();

            form.Title  = "Find opC++.oplicense";
            form.Filter = "opC++ License (opC++.oplicense) | opC++.oplicense";

            if (form.ShowDialog() == DialogResult.OK)
            {
                option.Value = form.FileName;
            }

            return(option);
        }
コード例 #3
0
        // This method actually converts from a StringOption to a string.
        public override object ConvertTo(ITypeDescriptorContext context,
                                         CultureInfo culture,
                                         object value,
                                         Type destinationType)
        {
            if (destinationType == typeof(string) &&
                value is StringOption)
            {
                StringOption option = (StringOption)value;

                return(option.Value);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #4
0
        // copy constructor
        public Options(Options copy)
        {
            FieldInfo[] oFields;
            Type        oType = typeof(Options);

            // Get the public data members in the 'Options' class.
            oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            // This loops through all the public data members in the 'Options' class.
            for (int i = 0; i < oFields.Length; i++)
            {
                // Handle string list options.
                if (oFields[i].FieldType == typeof(StringListOption))
                {
                    StringListOption theiroption = (StringListOption)oFields[i].GetValue(copy);
                    StringListOption myoption    = (StringListOption)oFields[i].GetValue(this);

                    myoption.StringList = new List <string>(theiroption.StringList);
                }
                // Handle string options.
                else if (oFields[i].FieldType == typeof(StringOption))
                {
                    StringOption theiroption = (StringOption)oFields[i].GetValue(copy);
                    StringOption myoption    = (StringOption)oFields[i].GetValue(this);

                    myoption.Value = theiroption.Value;
                }
                // Handle bool options.
                else if (oFields[i].FieldType == typeof(BoolOption))
                {
                    BoolOption theiroption = (BoolOption)oFields[i].GetValue(copy);
                    BoolOption myoption    = (BoolOption)oFields[i].GetValue(this);

                    myoption.Value      = theiroption.Value;
                    myoption.UseDefault = theiroption.UseDefault;
                }
                // Handle int options.
                else if (oFields[i].FieldType == typeof(IntOption))
                {
                    IntOption theiroption = (IntOption)oFields[i].GetValue(copy);
                    IntOption myoption    = (IntOption)oFields[i].GetValue(this);

                    myoption.Value      = theiroption.Value;
                    myoption.UseDefault = theiroption.UseDefault;
                }
            }
        }
コード例 #5
0
        // 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);
        }