示例#1
0
        public bool TryGetAttachedPropertyType(string typeNamespace, string typeName, out AttachedPropertyObjectType attachedPropertyObjectType)
        {
            string assemblyTypeName = ObjectInstanceTypeCache.CalculateTypeName(typeNamespace, typeName);

            if (!this.attachedPropertyTypeCache.TryGetValue(assemblyTypeName, out attachedPropertyObjectType))
            {
                Assembly assembly;
                if (!this.namespaceAssemblyCache.TryGetValue(typeNamespace, out assembly))
                {
                    return(false);
                }

                Type type = assembly.GetType(assemblyTypeName, false);
                if (type == null)
                {
                    return(false);
                }

                if (!AttachedPropertyObjectType.TryCreate(type, out attachedPropertyObjectType))
                {
                    return(false);
                }

                this.attachedPropertyTypeCache.Add(assemblyTypeName, attachedPropertyObjectType);
            }

            return(true);
        }
示例#2
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);
                    }
                }
            }
        }
示例#3
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);
        }