Exemplo n.º 1
0
        public void PreloadCache()
        {
            // Enumerate/reflect all of the available types and pre-cache them.
            // REVIEW: This pattern will re-enumerate the same assembly each time for
            // each CLR namespace... it could be more efficient.
            foreach (var kv in this.namespaceAssemblyCache)
            {
                var clrNamespace = kv.Key;
                var assembly     = kv.Value;

                foreach (var type in assembly.GetTypes().Where(t => !t.IsInterface && !t.IsNested && String.Equals(t.Namespace, clrNamespace, StringComparison.Ordinal)))
                {
                    if (!type.IsAbstract)
                    {
                        // REVIEW: any other attributes to check?
                        ObjectInstanceType ignored;
                        this.TryGetObjectInstanceType(type.Namespace, type.Name, out ignored);
                    }

                    // Look for attached properties and pre-load those as well...
                    if (AttachedPropertyObjectType.GetSetterMethods(type).Any())
                    {
                        AttachedPropertyObjectType ignored;
                        this.TryGetAttachedPropertyType(type.Namespace, type.Name, out ignored);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static bool TryCreate(Type type, out AttachedPropertyObjectType attachedPropertyObjectType)
        {
            var methods = AttachedPropertyObjectType.GetSetterMethods(type);

            if (!methods.Any())
            {
                attachedPropertyObjectType = null;
                return(false);
            }

            var setters = methods.Select(m => new AttachedPropertySetterType(m));

            attachedPropertyObjectType = new AttachedPropertyObjectType(type, setters);

            return(true);
        }