+ static Type GetPropertyType (ProfileGroupSettings pgs, ProfilePropertySettings pps)
+ {
+ Type type = HttpApplication.LoadType (pps.Type);
+ if (type != null)
+ return type;
+
+ Type profileType = null;
+ if (pgs == null)
+ profileType = ProfileParser.GetProfileCommonType (HttpContext.Current);
+ else
+ profileType = ProfileParser.GetProfileGroupType (HttpContext.Current, pgs.Name);
+
+ if (profileType == null)
+ return null;
+
+ PropertyInfo pi = profileType.GetProperty (pps.Name);
+ if (pi != null)
+ return pi.PropertyType;
+
+ return null;
+ }
+
+ static void ValidateProperty (SettingsProperty settingsProperty, ElementInformation elementInfo)
+ {
+ string exceptionMessage = string.Empty;
+ if (!AnonymousIdentificationModule.Enabled &&
+ (bool) settingsProperty.Attributes ["AllowAnonymous"])
+ exceptionMessage = "Profile property '{0}' allows anonymous users to store data. " +
+ "This requires that the AnonymousIdentification feature be enabled.";
+
+ if (settingsProperty.PropertyType == null)
+ exceptionMessage = "The type specified for a profile property '{0}' could not be found.";
+
+ if (settingsProperty.SerializeAs == SettingsSerializeAs.Binary &&
+ !settingsProperty.PropertyType.IsSerializable)
+ exceptionMessage = "The type for the property '{0}' cannot be serialized " +
+ "using the binary serializer, since the type is not marked as serializable.";
+
+ if (exceptionMessage.Length > 0)
+ throw new ConfigurationErrorsException (string.Format (exceptionMessage, settingsProperty.Name),
+ elementInfo.Source, elementInfo.LineNumber);
+ }
+
+ static SettingsProperty CreateSettingsProperty (PropertyInfo property)
+ {
+ SettingsProperty sp = new SettingsProperty (property.Name);
+ Attribute [] attributes = (Attribute [])property.GetCustomAttributes (false);
+ SettingsAttributeDictionary attDict = new SettingsAttributeDictionary();
+ bool defaultAssigned = false;
+
+ sp.SerializeAs = SettingsSerializeAs.ProviderSpecific;
+ sp.PropertyType = property.PropertyType;
+ sp.IsReadOnly = false;
+ sp.ThrowOnErrorDeserializing = false;
+ sp.ThrowOnErrorSerializing = true;
+
+ for (int i = 0; i < attributes.Length; i++) {
+ if (attributes [i] is DefaultSettingValueAttribute) {
+ sp.DefaultValue = ((DefaultSettingValueAttribute) attributes [i]).Value;
+ defaultAssigned = true;
+ } else if (attributes [i] is SettingsProviderAttribute) {
+ Type providerType = HttpApplication.LoadType (((SettingsProviderAttribute) attributes [i]).ProviderTypeName);
+ sp.Provider = (SettingsProvider) Activator.CreateInstance (providerType);
+ sp.Provider.Initialize (null, null);
+ } else if (attributes [i] is SettingsSerializeAsAttribute) {
+ sp.SerializeAs = ((SettingsSerializeAsAttribute) attributes [i]).SerializeAs;
+ } else if (attributes [i] is SettingsAllowAnonymousAttribute) {
+ sp.Attributes ["AllowAnonymous"] = ((SettingsAllowAnonymousAttribute) attributes [i]).Allow;
+ } else if (attributes [i] is CustomProviderDataAttribute) {
+ sp.Attributes ["CustomProviderData"] = ((CustomProviderDataAttribute) attributes [i]).CustomProviderData;
+ } else if (attributes [i] is ApplicationScopedSettingAttribute ||
+ attributes [i] is UserScopedSettingAttribute ||
+ attributes [i] is SettingsDescriptionAttribute ||
+ attributes [i] is SettingAttribute)
+ attDict.Add (attributes [i].GetType (), attributes [i]);