internal static IDictionary GetPersonalizablePropertyValues(Control control, PersonalizationScope scope, bool excludeSensitive)
        {
            IDictionary dictionary = null;
            IDictionary personalizablePropertyEntries = GetPersonalizablePropertyEntries(control.GetType());

            if (personalizablePropertyEntries.Count != 0)
            {
                foreach (DictionaryEntry entry in personalizablePropertyEntries)
                {
                    string key = (string)entry.Key;
                    PersonalizablePropertyEntry entry2 = (PersonalizablePropertyEntry)entry.Value;
                    if ((!excludeSensitive || !entry2.IsSensitive) && ((scope != PersonalizationScope.User) || (entry2.Scope != PersonalizationScope.Shared)))
                    {
                        if (dictionary == null)
                        {
                            dictionary = new HybridDictionary(personalizablePropertyEntries.Count, false);
                        }
                        object y = FastPropertyAccessor.GetProperty(control, key, control.DesignMode);
                        dictionary[key] = new Pair(entry2.PropertyInfo, y);
                    }
                }
            }
            if (dictionary == null)
            {
                dictionary = new HybridDictionary(false);
            }
            return(dictionary);
        }
        private void InitializePersonalizableProperties()
        {
            _propertyEntries = new HybridDictionary(/* caseInsensitive */ false);

            // Get all public and non-public instance properties, including those declared on
            // base types.
            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            PropertyInfo[] props = _type.GetProperties(flags);

            // Sorts PropertyInfos according to their DeclaringType.  Base types appear before derived types.
            Array.Sort(props, new DeclaringTypeComparer());

            // For each PropertyInfo, add it to the dictionary if it is personalizable, else remove
            // it from the dictionary.  We need to remove it from the dictionary, in case the base
            // type declared a valid personalizable property of the same name (VSWhidbey 237437).
            if ((props != null) && (props.Length != 0))
            {
                for (int i = 0; i < props.Length; i++)
                {
                    PropertyInfo pi   = props[i];
                    string       name = pi.Name;

                    // Get the PersonalizableAttribute (and include any inherited metadata)
                    PersonalizableAttribute pa = Attribute.GetCustomAttribute(pi,
                                                                              PersonalizableAttribute.PersonalizableAttributeType, true) as PersonalizableAttribute;

                    // If the property is not personalizable, remove it from the dictionary
                    if (pa == null || !pa.IsPersonalizable)
                    {
                        _propertyEntries.Remove(name);
                        continue;
                    }

                    // If the property has parameters, or does not have a public get or set
                    // accessor, throw an exception.
                    ParameterInfo[] paramList = pi.GetIndexParameters();
                    if ((paramList != null && paramList.Length > 0) || pi.GetGetMethod() == null || pi.GetSetMethod() == null)
                    {
                        throw new HttpException(SR.GetString(SR.PersonalizableTypeEntry_InvalidProperty, name, _type.FullName));
                    }

                    // Add the property to the dictionary
                    _propertyEntries[name] = new PersonalizablePropertyEntry(pi, pa);
                }
            }
        }
        private static IDictionary SetPersonalizedProperties(Control control, IDictionary personalizableProperties, IDictionary propertyState, System.Web.UI.WebControls.WebParts.PersonalizationScope scope)
        {
            if (personalizableProperties.Count == 0)
            {
                return(propertyState);
            }
            if ((propertyState == null) || (propertyState.Count == 0))
            {
                return(null);
            }
            IDictionary dictionary = null;

            foreach (DictionaryEntry entry in propertyState)
            {
                string key = (string)entry.Key;
                object val = entry.Value;
                PersonalizablePropertyEntry entry2 = (PersonalizablePropertyEntry)personalizableProperties[key];
                bool flag = false;
                if ((entry2 != null) && ((scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) || (entry2.Scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User)))
                {
                    PropertyInfo propertyInfo = entry2.PropertyInfo;
                    try
                    {
                        FastPropertyAccessor.SetProperty(control, key, val, control.DesignMode);
                        flag = true;
                    }
                    catch
                    {
                    }
                }
                if (!flag)
                {
                    if (dictionary == null)
                    {
                        dictionary = new HybridDictionary(propertyState.Count, false);
                    }
                    dictionary[key] = val;
                }
            }
            return(dictionary);
        }
Exemplo n.º 4
0
        /// <devdoc>
        /// </devdoc>
        internal static IDictionary GetPersonalizablePropertyValues(Control control, PersonalizationScope scope, bool excludeSensitive)
        {
            IDictionary propertyBag = null;

            IDictionary propertyEntries = GetPersonalizablePropertyEntries(control.GetType());

            if (propertyEntries.Count != 0)
            {
                foreach (DictionaryEntry entry in propertyEntries)
                {
                    string name = (string)entry.Key;
                    PersonalizablePropertyEntry propEntry = (PersonalizablePropertyEntry)entry.Value;

                    if (excludeSensitive && propEntry.IsSensitive)
                    {
                        continue;
                    }
                    if ((scope == PersonalizationScope.User) &&
                        (propEntry.Scope == PersonalizationScope.Shared))
                    {
                        continue;
                    }

                    if (propertyBag == null)
                    {
                        propertyBag = new HybridDictionary(propertyEntries.Count, /* caseInsensitive */ false);
                    }

                    object value = FastPropertyAccessor.GetProperty(control, name, control.DesignMode);

                    propertyBag[name] = new Pair(propEntry.PropertyInfo, value);
                }
            }

            if (propertyBag == null)
            {
                propertyBag = new HybridDictionary(/* caseInsensitive */ false);
            }
            return(propertyBag);
        }
        private static IDictionary GetPersonalizedProperties(Control control, IDictionary personalizableProperties, IDictionary defaultPropertyState, IDictionary initialPropertyState, System.Web.UI.WebControls.WebParts.PersonalizationScope scope)
        {
            if (personalizableProperties.Count == 0)
            {
                return(null);
            }
            bool        flag       = scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User;
            IDictionary dictionary = null;

            foreach (DictionaryEntry entry in personalizableProperties)
            {
                PersonalizablePropertyEntry entry2 = (PersonalizablePropertyEntry)entry.Value;
                if (!flag || (entry2.Scope != System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
                {
                    PropertyInfo propertyInfo = entry2.PropertyInfo;
                    string       key          = (string)entry.Key;
                    object       objA         = FastPropertyAccessor.GetProperty(control, key, control.DesignMode);
                    bool         flag2        = true;
                    if (((initialPropertyState == null) || !initialPropertyState.Contains(key)) && (defaultPropertyState != null))
                    {
                        object objB = defaultPropertyState[key];
                        if (object.Equals(objA, objB))
                        {
                            flag2 = false;
                        }
                    }
                    if (flag2)
                    {
                        if (dictionary == null)
                        {
                            dictionary = new HybridDictionary(personalizableProperties.Count, false);
                        }
                        dictionary[key] = objA;
                    }
                }
            }
            return(dictionary);
        }
        private void InitializePersonalizableProperties() {
            _propertyEntries = new HybridDictionary(/* caseInsensitive */ false);

            // Get all public and non-public instance properties, including those declared on
            // base types.
            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
            PropertyInfo[] props = _type.GetProperties(flags);

            // Sorts PropertyInfos according to their DeclaringType.  Base types appear before derived types.
            Array.Sort(props, new DeclaringTypeComparer());

            // For each PropertyInfo, add it to the dictionary if it is personalizable, else remove
            // it from the dictionary.  We need to remove it from the dictionary, in case the base
            // type declared a valid personalizable property of the same name (VSWhidbey 237437).
            if ((props != null) && (props.Length != 0)) {
                for (int i = 0; i < props.Length; i++) {
                    PropertyInfo pi = props[i];
                    string name = pi.Name;

                    // Get the PersonalizableAttribute (and include any inherited metadata)
                    PersonalizableAttribute pa = Attribute.GetCustomAttribute(pi,
                      PersonalizableAttribute.PersonalizableAttributeType, true) as PersonalizableAttribute;

                    // If the property is not personalizable, remove it from the dictionary
                    if (pa == null || !pa.IsPersonalizable) {
                        _propertyEntries.Remove(name);
                        continue;
                    }

                    // If the property has parameters, or does not have a public get or set
                    // accessor, throw an exception.
                    ParameterInfo[] paramList = pi.GetIndexParameters();
                    if ((paramList != null && paramList.Length > 0) || pi.GetGetMethod() == null || pi.GetSetMethod() == null) {
                        throw new HttpException(SR.GetString(SR.PersonalizableTypeEntry_InvalidProperty, name, _type.FullName));
                    }

                    // Add the property to the dictionary
                    _propertyEntries[name] = new PersonalizablePropertyEntry(pi, pa);
                }
            }
        }