Merge pull request #2638 from gofman/fixprintsettings
[mono.git] / mcs / class / System.Web / System.Web.Profile / ProfileBase.cs
index 73543f9f260ba8d4002bcda9d6b15662c4b0a99f..a6a26d7e7ccc95079b13fad82d00bc8a007f9ffe 100644 (file)
@@ -27,7 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System;
 using System.Configuration;
 using System.Configuration.Provider;
@@ -47,22 +46,7 @@ namespace System.Web.Profile
                SettingsPropertyValueCollection _propertiyValues = null;
                const string Profiles_SettingsPropertyCollection = "Profiles.SettingsPropertyCollection";
 
-#if TARGET_J2EE
-               static SettingsPropertyCollection _properties
-               {
-                       get
-                       {
-                               object o = AppDomain.CurrentDomain.GetData (Profiles_SettingsPropertyCollection);
-                               return (SettingsPropertyCollection) o;
-                       }
-                       set
-                       {
-                               AppDomain.CurrentDomain.SetData (Profiles_SettingsPropertyCollection, value);
-                       }
-               }
-#else
                static SettingsPropertyCollection _properties = null;
-#endif
 
                static void InitProperties ()
                {
@@ -76,14 +60,14 @@ namespace System.Web.Profile
                                ProfilePropertySettingsCollection ppsc = pgs.PropertySettings;
 
                                for (int s = 0; s < ppsc.Count; s++) {
-                                       SettingsProperty settingsProperty = CreateSettingsPropery (pgs, ppsc [s]);
-                                       ValidateProperty (settingsProperty, ppsc [i].ElementInformation);
+                                       SettingsProperty settingsProperty = CreateSettingsProperty (pgs, ppsc [s]);
+                                       ValidateProperty (settingsProperty, ppsc [s].ElementInformation);
                                        properties.Add (settingsProperty);
                                }
                        }
 
                        for (int s = 0; s < ps.Count; s++) {
-                               SettingsProperty settingsProperty = CreateSettingsPropery (null, ps [s]);
+                               SettingsProperty settingsProperty = CreateSettingsProperty (null, ps [s]);
                                ValidateProperty (settingsProperty, ps [s].ElementInformation);
                                properties.Add (settingsProperty);
                        }
@@ -96,7 +80,7 @@ namespace System.Web.Profile
                                                PropertyInfo [] pi = properiesType.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                                                if (pi.Length > 0)
                                                        for (int i = 0; i < pi.Length; i++)
-                                                               properties.Add (CreateSettingsPropery (pi [i]));
+                                                               properties.Add (CreateSettingsProperty (pi [i]));
 
                                                if (properiesType.BaseType == null || 
                                                        properiesType.BaseType == typeof (ProfileBase))
@@ -199,7 +183,7 @@ namespace System.Web.Profile
 
                static Type GetPropertyType (ProfileGroupSettings pgs, ProfilePropertySettings pps)
                {
-                       Type type = Type.GetType (pps.Type);
+                       Type type = HttpApplication.LoadType (pps.Type);
                        if (type != null)
                                return type;
 
@@ -240,12 +224,13 @@ namespace System.Web.Profile
                                        elementInfo.Source, elementInfo.LineNumber);
                }
 
-               static SettingsProperty CreateSettingsPropery (PropertyInfo property)
+               static SettingsProperty CreateSettingsProperty (PropertyInfo property)
                {
                        SettingsProperty sp = new SettingsProperty (property.Name);
-
-                       Attribute [] attributes = (Attribute [])property.GetCustomAttributes (typeof (SettingsSerializeAsAttribute), false);
+                       Attribute [] attributes = (Attribute [])property.GetCustomAttributes (false);
                        SettingsAttributeDictionary attDict = new SettingsAttributeDictionary();
+                       bool defaultAssigned = false;
+                       
                        sp.SerializeAs = SettingsSerializeAs.ProviderSpecific;
                        sp.PropertyType = property.PropertyType;
                        sp.IsReadOnly = false;
@@ -253,24 +238,23 @@ namespace System.Web.Profile
                        sp.ThrowOnErrorSerializing = true;
 
                        for (int i = 0; i < attributes.Length; i++) {
-                               if (attributes [i] is DefaultSettingValueAttribute)
+                               if (attributes [i] is DefaultSettingValueAttribute) {
                                        sp.DefaultValue = ((DefaultSettingValueAttribute) attributes [i]).Value;
-
-                               else if (attributes [i] is SettingsProviderAttribute) {
-                                       Type providerType = Type.GetType (((SettingsProviderAttribute) attributes [i]).ProviderTypeName);
+                                       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)
+                               } else if (attributes [i] is SettingsSerializeAsAttribute) {
                                        sp.SerializeAs = ((SettingsSerializeAsAttribute) attributes [i]).SerializeAs;
-
-                               else if (
-                                       attributes [i] is SettingsAllowAnonymousAttribute ||
-                                       attributes [i] is ApplicationScopedSettingAttribute ||
-                                       attributes [i] is UserScopedSettingAttribute ||
-                                       attributes [i] is SettingsDescriptionAttribute  ||
-                                       attributes [i] is SettingAttribute)
+                               } 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]);
                        }
 
@@ -280,11 +264,15 @@ namespace System.Web.Profile
                        if (sp.Attributes ["AllowAnonymous"] == null)
                                sp.Attributes ["AllowAnonymous"] = false;
 
+                       if (!defaultAssigned && sp.PropertyType == typeof (string) && sp.DefaultValue == null)
+                               sp.DefaultValue = String.Empty;
+                       
                        return sp;
                }
-               static SettingsProperty CreateSettingsPropery (ProfileGroupSettings pgs, ProfilePropertySettings pps)
+               
+               static SettingsProperty CreateSettingsProperty (ProfileGroupSettings pgs, ProfilePropertySettings pps)
                {
-                       string name = ((pgs == null) ? "" : pgs.Name + ".") + pps.Name;
+                       string name = ((pgs == null) ? String.Empty : pgs.Name + ".") + pps.Name;
                        SettingsProperty sp = new SettingsProperty (name);
 
                        sp.Attributes.Add ("AllowAnonymous", pps.AllowAnonymous);
@@ -359,7 +347,7 @@ namespace System.Web.Profile
                        }
                }
 
-               public static SettingsPropertyCollection Properties {
+               public new static SettingsPropertyCollection Properties {
                        get {
                                if (_properties == null)
                                        InitProperties ();
@@ -377,4 +365,3 @@ namespace System.Web.Profile
 
 }
 
-#endif