Abstractions.Settings.DynamicSetting.TryConvert C# (CSharp) Метод

TryConvert() публичный Метод

public TryConvert ( ConvertBinder binder, object &result ) : bool
binder System.Dynamic.ConvertBinder
result object
Результат bool
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            result = null;

            if (m_value == null)
                return true;

            // 1:1 conversion
            Type ourType = m_value.GetType();
            if (binder.Type == ourType)
            {
                result = m_value;
                return true;
            }

            // If caller wants a bool we have to do a little
            //  conversion, as there is no native Reg bool type,
            //  instead it saves them as strings.
            if (binder.Type == typeof(bool))
            {
                if(ourType == typeof(string))
                {
                    result = bool.Parse((string)m_value);
                    return true;
                }

                if (ourType == typeof(Int32))
                {
                    result = (((int)m_value) != 0);
                    return true;
                }
            }

            // We could potentially offer some standard conversions here? For now,
            // we just fail.
            return false;
        }