Пример #1
0
        protected void InitializeObservableProperties()
        {
            PropertyInfoList lProps = PropertyInfoDictionary <PropertyInfoList> .GetObservablePropertiesInfoList(this.GetType());

            foreach (PropertyInfo pi in lProps)
            {
                Type[] arrTypes = pi.PropertyType.GetGenericArguments();
                Debug.Assert(arrTypes != null && arrTypes.Length > 0);

                Type   t        = typeof(ObservableProperty <>);
                Type[] typeArgs = new Type[] { arrTypes[0] };

                Type tObservableProperty = t.MakeGenericType(typeArgs);

                pi.SetValue(this, Activator.CreateInstance(tObservableProperty, this, m_lChangedProps, pi.Name));
            }
        }
Пример #2
0
        internal static PropertyInfoList GetObservablePropertyInfoList(Type type)
        {
            PropertyInfoList lProps = new PropertyInfoList();

            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo pi in props)
            {
                Type t = pi.PropertyType;

                if (t.IsConstructedGenericType)
                {
                    if (t.GetGenericTypeDefinition() == typeof(ObservableProperty <>))
                    {
                        lProps.Add(pi);
                    }
                }
            }

            return(lProps);
        }