Пример #1
0
 object GetValue(object val)
 {
     if (val.GetType().IsEnum)
     {
         long   ival    = Convert.ToInt64(val);
         Type   etype   = val.GetType();
         bool   isFlags = val.GetType().IsDefined(typeof(FlagsAttribute), false);
         string flags   = "";
         IList  names   = Enum.GetNames(etype);
         foreach (FieldInfo f in val.GetType().GetFields())
         {
             if (!names.Contains(f.Name))
             {
                 continue;
             }
             long             v    = Convert.ToInt64(Enum.Parse(val.GetType(), f.Name));
             MonoArgAttribute attr = (MonoArgAttribute)Attribute.GetCustomAttribute(f, typeof(MonoArgAttribute));
             string           sval = attr != null ? attr.Name : f.Name;
             if (ival == v)
             {
                 return(sval);
             }
             else if (isFlags && (v & ival) != 0)
             {
                 if (flags.Length > 0)
                 {
                     flags += ",";
                 }
                 flags += sval;
             }
         }
         if (isFlags)
         {
             return(flags);
         }
     }
     return(val);
 }
Пример #2
0
        public void GenerateOptions(IDictionary <string, string> envVars, out string options)
        {
            StringBuilder ops = new StringBuilder();

            if (StripDriveLetters || CaseInsensitivePaths)
            {
                if (StripDriveLetters && CaseInsensitivePaths)
                {
                    envVars ["MONO_IOMAP"] = "all";
                }
                else if (StripDriveLetters)
                {
                    envVars ["MONO_IOMAP"] = "drive";
                }
                else if (CaseInsensitivePaths)
                {
                    envVars ["MONO_IOMAP"] = "case";
                }
            }
            for (int n = 0; n < VerboseLevel; n++)
            {
                ops.Append("-v ");
            }

            if (DebugMode || DebugMdbOptimizations || DebugCasts || GdbInfo)
            {
                ops.Append("--debug=");
                if (DebugMdbOptimizations)
                {
                    ops.Append("mdb-optimizations,");
                }
                if (DebugCasts)
                {
                    ops.Append("casts,");
                }
                if (GdbInfo)
                {
                    ops.Append("gdb,");
                }
                ops.Remove(ops.Length - 1, 1);
                ops.Append(' ');
            }

            foreach (PropertyInfo prop in GetType().GetProperties())
            {
                MonoArgAttribute argAttr = (MonoArgAttribute)Attribute.GetCustomAttribute(prop, typeof(MonoArgAttribute));
                if (argAttr != null)
                {
                    object val = GetValue(prop.GetValue(this, null));
                    if ((val is bool) && (bool)val)
                    {
                        ops.Append(argAttr.Name).Append(' ');
                    }
                    else if ((val is string) && !string.IsNullOrEmpty((string)val))
                    {
                        ops.AppendFormat(argAttr.Name, val).Append(' ');
                    }
                }
                else
                {
                    EnvVarAttribute envVar = (EnvVarAttribute)Attribute.GetCustomAttribute(prop, typeof(EnvVarAttribute));
                    if (envVar != null)
                    {
                        object val = GetValue(prop.GetValue(this, null));
                        if ((val is bool) && (bool)val)
                        {
                            envVars [envVar.Name] = envVar.TrueValue;
                        }
                        else if ((val is string) && !string.IsNullOrEmpty((string)val))
                        {
                            envVars [envVar.Name] = val.ToString();
                        }
                    }
                }
            }
            options = ops.ToString().Trim();
        }