Beispiel #1
0
        public void Awake()
        {
            HFTArgParser p = new HFTArgParser();

            bool found = false;

            found |= p.Contains("show-instructions");
            found |= p.TryGet <string>("instructions", ref instructions);
            found |= p.TryGetBool("bottom", ref bottom);
            if (found)
            {
                show = true;
            }
        }
Beispiel #2
0
 public void Init(string name, HFTArgParser p)
 {
     isSet_ = p.TryGetBool(name, ref value_);
 }
Beispiel #3
0
        public static bool Apply(string prefix, object obj)
        {
            HFTLog        log     = new HFTLog("HFTArgsDirect");
            HFTArgChecker checker = new HFTArgChecker(log, prefix);

            HFTArgParser p = HFTArgParser.GetInstance();

            System.Reflection.FieldInfo[] fields = obj.GetType().GetFields();
            foreach (System.Reflection.FieldInfo info in fields)
            {
                //object field = System.Activator.CreateInstance(info.FieldType);
                object      value     = null;
                System.Type fieldType = info.FieldType;
                string      dashName  = checker.GetHFTDashName(info.Name);
                checker.AddArg(dashName);
                // Should do this with reflection but ...
                if (fieldType == typeof(string))
                {
                    string strValue = "";
                    if (p.TryGet <string>(dashName, ref strValue))
                    {
                        value = strValue;
                    }
                }
                else if (fieldType == typeof(int))
                {
                    int intValue = 0;
                    if (p.TryGet <int>(dashName, ref intValue))
                    {
                        value = intValue;
                    }
                }
                else if (fieldType == typeof(bool))
                {
                    bool boolValue = false;
                    if (p.TryGetBool(dashName, ref boolValue))
                    {
                        value = boolValue;
                    }
                }
                else if (fieldType == typeof(float))
                {
                    float floatValue = 0;
                    if (p.TryGet <float>(dashName, ref floatValue))
                    {
                        value = floatValue;
                    }
                }
                else
                {
                    throw new System.InvalidOperationException("no support for type: " + fieldType.Name);
                }

                if (value != null)
                {
                    info.SetValue(obj, value);
                }
            }

            return(checker.CheckArgs());
        }