Example #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;
 }
Example #2
0
        public void GenerateOptions(IDictionary<string,string> envVars, out string options)
        {
            StringBuilder ops = new StringBuilder ();
            if (MonoStripDriveLetters || MonoCaseInsensitivePaths) {
                if (MonoStripDriveLetters && MonoCaseInsensitivePaths)
                    envVars ["MONO_IOMAP"] = "all";
                else if (MonoStripDriveLetters)
                    envVars ["MONO_IOMAP"] = "drive";
                else if (MonoCaseInsensitivePaths)
                    envVars ["MONO_IOMAP"] = "case";
            }
            for (int n=0; n< MonoVerboseLevel; n++)
                ops.Append ("-v ");

            if (MonoDebugMode || MonoDebugMdbOptimizations || MonoDebugCasts || MonoGdbInfo) {
                ops.Append ("--debug=");
                if (MonoDebugMdbOptimizations)
                    ops.Append ("mdb-optimizations,");
                if (MonoDebugCasts)
                    ops.Append ("casts,");
                if (MonoGdbInfo)
                    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 ();
        }
        object GetValue(object val)
        {
            Type etype = val.GetType();

            if (etype.IsEnum)
            {
                long          ival    = Convert.ToInt64(val);
                bool          isFlags = etype.IsDefined(typeof(FlagsAttribute), false);
                StringBuilder flags   = null;
                if (isFlags)
                {
                    flags = new StringBuilder();
                }
                IList names = Enum.GetNames(etype);
                foreach (FieldInfo f in etype.GetFields())
                {
                    if (!names.Contains(f.Name))
                    {
                        continue;
                    }
                    long             v    = Convert.ToInt64(Enum.Parse(etype, 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.Append(',');
                        }
                        flags.Append(sval);
                    }
                }
                if (isFlags)
                {
                    return(flags.ToString());
                }
            }
            return(val);
        }