Exemplo n.º 1
0
        ///<summary>
        /// Note: sanity check done outside (in DefaultValuesFactory class)
        ///</summary>
        ///<returns></returns>
        public object GetDefault()
        {
            /* XOR! */
            //if (null == ProxyType ^ !string.IsNullOrEmpty(ProxyMemberName))
            //    throw new Exception("When using proxy, both ProxyType and ProxyMemberName have to be defined: " + GetType());

            try
            {
                /**
                 * 1. Proxy takes precedence
                 * */
                if (null != ProxyType)
                {
                    return(string.IsNullOrEmpty(ProxyMemberName) ?
                           StyleProxyReader.GetProxySingleton(ProxyType) :
                           StyleProxyReader.GetProxyMemberValue(ProxyType, ProxyMemberName));
                }

                /**
                 * 2. Color
                 * */
                if (IsValidColor())
                {
                    return(ColorMixer.FromHexAndAlpha((int)Default, 1f).ToColor());
                }

                /**
                 * 3. Font
                 * */
                if (IsValidFont())
                {
                    var fontMapperId = Default as string;
                    /* Use the font mapper */
                    return(string.IsNullOrEmpty(fontMapperId) ?
                           FontMapper.GetDefault().Font :                  // get default font
                           FontMapper.GetWithFallback(fontMapperId).Font); // get named font
                }

                /**
                 * 3. Default value
                 * */
                return(Default);
            }
            catch (Exception ex)
            {
                throw new Exception("Problem processing style attribute " + Name + ": ", ex);
            }
        }