Пример #1
0
        // Return a string version of a particular parameter value
        public string GetParameterValue(string pName)
        {
            var ret = String.Empty;

            foreach (FieldInfo fi in this.GetType().GetFields())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(fi))
                {
                    ConfigParam cp = attr as ConfigParam;
                    if (cp != null)
                    {
                        if (cp.name == pName)
                        {
                            var val = fi.GetValue(this);
                            if (val != null)
                            {
                                ret = val.ToString();
                            }
                            break;
                        }
                    }
                }
                if (ret != String.Empty)
                {
                    break;
                }
            }
            return(ret);
        }
Пример #2
0
        // Set a parameter value
        public bool SetParameterValue(string pName, string pVal)
        {
            var ret = false;

            foreach (FieldInfo fi in this.GetType().GetFields())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(fi))
                {
                    ConfigParam cp = attr as ConfigParam;
                    if (cp != null)
                    {
                        if (cp.name == pName)
                        {
                            fi.SetValue(this, ParamBlock.ConvertToObj(cp.valueType, pVal));
                            ret = true;
                            break;
                        }
                    }
                }
                if (ret)
                {
                    break;
                }
            }
            return(ret);
        }
Пример #3
0
        // Return a list of all the parameters and their descriptions
        public Dictionary <string, string> ListParameters()
        {
            var ret = new Dictionary <string, string>();

            foreach (FieldInfo fi in this.GetType().GetFields())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(fi))
                {
                    ConfigParam cp = attr as ConfigParam;
                    if (cp != null)
                    {
                        ret.Add(cp.name, cp.desc);
                    }
                }
            }
            return(ret);
        }
Пример #4
0
        // Find the parameter definition and return the config info and the field info
        // Returns 'true' of the parameter is found. False otherwise.
        public bool TryGetParameterInfo(string pName, out ConfigParam pConfigParam, out FieldInfo pFieldInfo)
        {
            var lName = pName.ToLower();

            foreach (FieldInfo fi in this.GetType().GetFields())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(fi))
                {
                    ConfigParam cp = attr as ConfigParam;
                    if (cp != null)
                    {
                        if (cp.name.ToLower() == lName || (cp.alt != null && cp.alt == lName))
                        {
                            pConfigParam = cp;
                            pFieldInfo   = fi;
                            return(true);
                        }
                    }
                }
            }
            pConfigParam = null;
            pFieldInfo   = null;
            return(false);
        }