示例#1
0
        /// <summary>
        /// 完成所有编译期属性的注册。此时会变更 container 的对应生成周期,并为其设置 ConsolidatedContainer 属性。
        /// </summary>
        private static void CompleteCompileProperties(TypePropertiesContainer container)
        {
            //设置 ConsolidatedContainer
            var consolidatedContainer = new ConsolidatedTypePropertiesContainer();

            consolidatedContainer.SimpleContainer = container;
            consolidatedContainer.InitCompiledProperties();

            //consolidatedContainer 初始化编译期属性成功(无异常),才设置 container 的连接。
            container.ConsolidatedContainer = consolidatedContainer;
            //变更生命期到“运行时”。
            container.CurLifeCycle = ManagedPropertyLifeCycle.Runtime;
        }
        private PropertyDescriptorCollection CreateDescriptors(ConsolidatedTypePropertiesContainer container)
        {
            //加入 ManagedProperty
            var mpList = container.GetAvailableProperties();
            var pdList = mpList.Select(mp => this.CreateDescriptor(mp)).ToList();

            //加入 CLRProperty
            //为了兼容一些直接使用 CLR 属性而没有使用托管属性编写的视图属性。
            var clrProperties = container.OwnerType.GetProperties();
            foreach (var clrProperty in clrProperties)
            {
                if (mpList.All(mp => mp.Name != clrProperty.Name))
                {
                    pdList.Add(new CLRPropertyDescriptor(clrProperty));
                }
            }

            return new PropertyDescriptorCollection(pdList.ToArray());
        }
示例#3
0
        private PropertyDescriptorCollection CreateDescriptors(ConsolidatedTypePropertiesContainer container)
        {
            //加入 ManagedProperty
            var mpList = container.GetAvailableProperties();
            var pdList = mpList.Select(mp => this.CreateDescriptor(mp)).ToList();

            //加入 CLRProperty
            //为了兼容一些直接使用 CLR 属性而没有使用托管属性编写的视图属性。
            var clrProperties = container.OwnerType.GetProperties();

            foreach (var clrProperty in clrProperties)
            {
                if (mpList.All(mp => mp.Name != clrProperty.Name))
                {
                    pdList.Add(new CLRPropertyDescriptor(clrProperty));
                }
            }

            return(new PropertyDescriptorCollection(pdList.ToArray()));
        }
示例#4
0
        internal PropertyDescriptorCollection GetProperties(ConsolidatedTypePropertiesContainer container)
        {
            var result = container.PropertyDescriptors;

            if (container.PropertyDescriptors == null)
            {
                lock (_lock)
                {
                    if (container.PropertyDescriptors == null)
                    {
                        result = CreateDescriptors(container);

                        //缓存到 container 上。
                        container.PropertyDescriptors = result;

                        //当动态属性变化时,PropertyDescriptorCollection 也不可用。
                        container.RuntimePropertiesChanged -= typePropertiesContainer_RuntimePropertiesChanged;
                        container.RuntimePropertiesChanged += typePropertiesContainer_RuntimePropertiesChanged;
                    }
                }
            }

            return(result);
        }
        internal PropertyDescriptorCollection GetProperties(ConsolidatedTypePropertiesContainer container)
        {
            var result = container.PropertyDescriptors;

            if (container.PropertyDescriptors == null)
            {
                lock (_lock)
                {
                    if (container.PropertyDescriptors == null)
                    {
                        result = CreateDescriptors(container);

                        //缓存到 container 上。
                        container.PropertyDescriptors = result;

                        //当动态属性变化时,PropertyDescriptorCollection 也不可用。
                        container.RuntimePropertiesChanged -= typePropertiesContainer_RuntimePropertiesChanged;
                        container.RuntimePropertiesChanged += typePropertiesContainer_RuntimePropertiesChanged;
                    }
                }
            }

            return result;
        }