internal static bool MatchesCSSType(Type clientType, string cssType)
        {
            //StyleManager styleManager = StyleManager.Instance;
            //bool qualified = styleManager.QualifiedTypeSelectors;
            OrderedObject <bool> typeHierarchy = TypeHierarchyHelper.GetTypeHierarchy(clientType);

            return(typeHierarchy.KeyExists(cssType));
        }
        public static Type TYPE_TO_MONITOR;         // = typeof(ImageButtonSkin);

// ReSharper restore MemberCanBePrivate.Global
// ReSharper restore FieldCanBeMadeReadOnly.Global
// ReSharper restore UnassignedField.Global
// ReSharper restore InconsistentNaming
// ReSharper restore UnusedMember.Global
#endif

        /**
         *
         *  Implements the getClassStyleDeclarations() logic
         *  for Component and TextBase.
         *  The 'object' parameter will be one or the other.
         */
        internal static List <StyleDeclaration> GetClassStyleDeclarations(IStyleClient client)
        {
            /*if (client.GetType().FullName == "Assets.eDriven.Skins.ImageButtonSkin")
             *      Debug.Log("GetMatchingStyleDeclarations for: " + client);*/

            StyleManager styleManager = StyleManager.Instance;
            //bool qualified = true;
            string className = client.GetType().FullName;
            //IStyleClient advancedObject = client as IStyleClient;
            OrderedObject <bool> typeHierarchy = TypeHierarchyHelper.GetTypeHierarchy(client.GetType());            //, qualified);
            List <string>        types         = typeHierarchy.Keys;
            int typeCount = types.Count;

            //Debug.Log("typeCount for " + client + ": " + typeHierarchy);

            List <StyleDeclaration> classDecls = null;

            /*if (styleManager.TypeSelectorCache.ContainsKey(className))
             *      classDecls = styleManager.TypeSelectorCache[className];*/
            /*if (null != classDecls)
             *      return classDecls;*/

            classDecls = new List <StyleDeclaration>();

            // Loop over the type hierarhcy starting at the base type and work
            // down the chain of subclasses.
            for (int i = typeCount - 1; i >= 0; i--)
            {
                string type = types[i];                 //.toString(); && TODO??

                //Debug.Log("Getting decls for " + type);
                List <StyleDeclaration> decls = styleManager.GetStyleDeclarations(type);
                if (null != decls)
                {
                    //Debug.Log("  ->" + decls.Count);
                    var matchingDecls = MatchStyleDeclarations(decls, client);
                    if (null != matchingDecls)
                    {
                        classDecls.AddRange(matchingDecls);
                    }
                }
            }

            #region Monitor

//#if DEBUG
//            if (null != TYPE_TO_MONITOR)
//            {
//                if (client.GetType() == TYPE_TO_MONITOR)
//                    Debug.Log(string.Format(@"### {0} classDecls ###
//{1}", TYPE_TO_MONITOR, ListUtil<StyleDeclaration>.Format(classDecls)));
//            }
//#endif

            #endregion

            classDecls = SortOnSpecificity(classDecls);             //classDecls.Sort(SpecificitySort); // = SortOnSpecificity(classDecls);

            #region Monitor

//#if DEBUG
//            if (null != TYPE_TO_MONITOR)
//            {
//                if (client.GetType() == TYPE_TO_MONITOR)
//                    Debug.Log(string.Format(@"### {0} classDecls 2 ###
//{1}", TYPE_TO_MONITOR, ListUtil<StyleDeclaration>.Format(classDecls)));
//            }
//#endif

            #endregion

            #region Always advanced - NO caching!

/*if (styleManager.HasAdvancedSelectors()/* && advancedObject != null#1#)
 *                      {
 *                              // Advanced selectors may result in more than one match per type so
 *                              // we sort based on specificity, but we preserve the declaration
 *                              // order for equal selectors.
 *                              classDecls = SortOnSpecificity(classDecls);
 *                      }
 *                      else
 *                      {
 *                              // Cache the simple type declarations for this class
 *                              styleManager.TypeSelectorCache[className] = classDecls;
 *                      }*/

            #endregion


            return(classDecls);
        }
        public static Type TYPE_TO_MONITOR;         // = typeof(ImageButtonSkin);
        // ReSharper restore MemberCanBePrivate.Global
        // ReSharper restore FieldCanBeMadeReadOnly.Global
        // ReSharper restore UnassignedField.Global
        // ReSharper restore InconsistentNaming
        // ReSharper restore UnusedMember.Global
#endif

        /**
         *
         *  Param: object - the IStyleClient to be introspected
         *  Param: qualified - whether qualified type names should be used
         *  Returns: an ordered map of class names, starting with the object's class
         *  name and then each super class name until we hit a stop class, such as
         *  mx.core::Component.
         */

        internal static OrderedObject <bool> GetTypeHierarchy(Type type /*, bool qualified*/)
        {
            StyleManager styleManager = StyleManager.Instance;
            //Type type = client.GetType();
            string className = type.FullName;
            OrderedObject <bool> hierarchy = null;

            if (styleManager.TypeHierarchyCache.ContainsKey(className))
            {
                hierarchy = styleManager.TypeHierarchyCache[className];
            }

            if (hierarchy == null)
            {
                hierarchy = new OrderedObject <bool>();

                styleManager.TypeHierarchyCache[className] = hierarchy;
                while (!IsStopClass(type))
                {
                    try
                    {
                        if (null != type)
                        {
                            hierarchy.Add(className, true);
                            type = type.BaseType;
                            if (null != type)
                            {
                                className = type.FullName;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        className = null;
                    }

                    //try
                    //{
                    //    //var type:String;
                    //    //if (qualified)
                    //    //    type = className.replace("::", ".");
                    //    //else
                    //        type = NameUtil.getUnqualifiedClassName(className);

                    //    hierarchy.object_proxy::setObjectProperty(type, true);
                    //    className = getQualifiedSuperclassName(
                    //        myApplicationDomain.getDefinition(className));
                    //}
                    //catch(e:ReferenceError)
                    //{
                    //    className = null;
                    //}
                }

                #region Monitor

#if DEBUG
                if (null != TYPE_TO_MONITOR)
                {
                    if (type == TYPE_TO_MONITOR)
                    {
                        Debug.Log(string.Format(@"### {0} type hierarchy ###
{1}", TYPE_TO_MONITOR, hierarchy));
                    }
                }
#endif

                #endregion
            }

            return(hierarchy);
        }