public void ReadOnly_Add()
        {
            SettingsPropertyCollection col = new SettingsPropertyCollection();

            col.SetReadOnly();

            SettingsProperty test_prop = new SettingsProperty("test_prop");

            col.Add(test_prop);
        }
Ejemplo n.º 2
0
        static void InitProperties()
        {
            SettingsPropertyCollection properties = new SettingsPropertyCollection();

            ProfileSection config = (ProfileSection)WebConfigurationManager.GetSection("system.web/profile");
            RootProfilePropertySettingsCollection ps = config.PropertySettings;

            for (int i = 0; i < ps.GroupSettings.Count; i++)
            {
                ProfileGroupSettings pgs = ps.GroupSettings [i];
                ProfilePropertySettingsCollection ppsc = pgs.PropertySettings;

                for (int s = 0; s < ppsc.Count; s++)
                {
                    SettingsProperty settingsProperty = CreateSettingsProperty(pgs, ppsc [s]);
                    ValidateProperty(settingsProperty, ppsc [s].ElementInformation);
                    properties.Add(settingsProperty);
                }
            }

            for (int s = 0; s < ps.Count; s++)
            {
                SettingsProperty settingsProperty = CreateSettingsProperty(null, ps [s]);
                ValidateProperty(settingsProperty, ps [s].ElementInformation);
                properties.Add(settingsProperty);
            }

            if (config.Inherits.Length > 0)
            {
                Type profileType = ProfileParser.GetProfileCommonType(HttpContext.Current);
                if (profileType != null)
                {
                    Type properiesType = profileType.BaseType;
                    for (; ;)
                    {
                        PropertyInfo [] pi = properiesType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                        if (pi.Length > 0)
                        {
                            for (int i = 0; i < pi.Length; i++)
                            {
                                properties.Add(CreateSettingsProperty(pi [i]));
                            }
                        }

                        if (properiesType.BaseType == null ||
                            properiesType.BaseType == typeof(ProfileBase))
                        {
                            break;
                        }

                        properiesType = properiesType.BaseType;
                    }
                }
            }

            properties.SetReadOnly();
            lock (Profiles_SettingsPropertyCollection) {
                if (_properties == null)
                {
                    _properties = properties;
                }
            }
        }
Ejemplo n.º 3
0
 private static void InitializeStatic()
 {
     if (!ProfileManager.Enabled || s_Initialized)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
     }
     else
     {
         lock (s_InitializeLock)
         {
             if (s_Initialized)
             {
                 if (s_InitializeException != null)
                 {
                     throw s_InitializeException;
                 }
                 return;
             }
             try
             {
                 ProfileSection profileAppConfig = MTConfigUtil.GetProfileAppConfig();
                 bool           fAnonEnabled     = HostingEnvironment.IsHosted ? AnonymousIdentificationModule.Enabled : true;
                 Type           inheritsFromType = InheritsFromType;
                 bool           hasLowTrust      = HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low);
                 s_Properties = new SettingsPropertyCollection();
                 AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, ProfileManager.DynamicProfileProperties, null);
                 if (inheritsFromType != typeof(ProfileBase))
                 {
                     PropertyInfo[]      properties = typeof(ProfileBase).GetProperties();
                     NameValueCollection values     = new NameValueCollection(properties.Length);
                     foreach (PropertyInfo info in properties)
                     {
                         values.Add(info.Name, string.Empty);
                     }
                     foreach (PropertyInfo info2 in inheritsFromType.GetProperties())
                     {
                         if (values[info2.Name] == null)
                         {
                             ProfileProvider     provider           = hasLowTrust ? ProfileManager.Provider : null;
                             bool                isReadOnly         = false;
                             SettingsSerializeAs providerSpecific   = SettingsSerializeAs.ProviderSpecific;
                             string              defaultValue       = string.Empty;
                             bool                allow              = false;
                             string              customProviderData = null;
                             foreach (Attribute attribute in Attribute.GetCustomAttributes(info2, true))
                             {
                                 if (attribute is SettingsSerializeAsAttribute)
                                 {
                                     providerSpecific = ((SettingsSerializeAsAttribute)attribute).SerializeAs;
                                 }
                                 else if (attribute is SettingsAllowAnonymousAttribute)
                                 {
                                     allow = ((SettingsAllowAnonymousAttribute)attribute).Allow;
                                     if (!fAnonEnabled && allow)
                                     {
                                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Annoymous_id_module_not_enabled", new object[] { info2.Name }), profileAppConfig.ElementInformation.Properties["inherits"].Source, profileAppConfig.ElementInformation.Properties["inherits"].LineNumber);
                                     }
                                 }
                                 else if (attribute is ReadOnlyAttribute)
                                 {
                                     isReadOnly = ((ReadOnlyAttribute)attribute).IsReadOnly;
                                 }
                                 else if (attribute is DefaultSettingValueAttribute)
                                 {
                                     defaultValue = ((DefaultSettingValueAttribute)attribute).Value;
                                 }
                                 else if (attribute is CustomProviderDataAttribute)
                                 {
                                     customProviderData = ((CustomProviderDataAttribute)attribute).CustomProviderData;
                                 }
                                 else if (hasLowTrust && (attribute is ProfileProviderAttribute))
                                 {
                                     provider = ProfileManager.Providers[((ProfileProviderAttribute)attribute).ProviderName];
                                     if (provider == null)
                                     {
                                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_provider_not_found", new object[] { ((ProfileProviderAttribute)attribute).ProviderName }), profileAppConfig.ElementInformation.Properties["inherits"].Source, profileAppConfig.ElementInformation.Properties["inherits"].LineNumber);
                                     }
                                 }
                             }
                             SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
                             attributes.Add("AllowAnonymous", allow);
                             if (!string.IsNullOrEmpty(customProviderData))
                             {
                                 attributes.Add("CustomProviderData", customProviderData);
                             }
                             SettingsProperty property = new SettingsProperty(info2.Name, info2.PropertyType, provider, isReadOnly, defaultValue, providerSpecific, attributes, false, true);
                             s_Properties.Add(property);
                         }
                     }
                 }
                 if (profileAppConfig.PropertySettings != null)
                 {
                     AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, profileAppConfig.PropertySettings, null);
                     foreach (ProfileGroupSettings settings in profileAppConfig.PropertySettings.GroupSettings)
                     {
                         AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, settings.PropertySettings, settings.Name);
                     }
                 }
             }
             catch (Exception exception)
             {
                 if (s_InitializeException == null)
                 {
                     s_InitializeException = exception;
                 }
             }
             if (s_Properties == null)
             {
                 s_Properties = new SettingsPropertyCollection();
             }
             s_Properties.SetReadOnly();
             s_Initialized = true;
         }
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
     }
 }