Pārlūkot izejas kodu

* ProfileBase.cs: added inherited properties properties initialization

svn path=/trunk/mcs/; revision=70350
Vladimir Krasnov 19 gadi atpakaļ
vecāks
revīzija
3a522ff1bc

+ 4 - 0
mcs/class/System.Web/System.Web.Profile/ChangeLog

@@ -1,3 +1,7 @@
+2007-01-02  Vladimir Krasnov  <[email protected]>
+
+	* ProfileBase.cs: added inherited properties properties initialization
+
 2006-12-26  Vladimir Krasnov  <[email protected]>
 
 	* ProfileGroupBase.cs: fixed property name while getting from parent

+ 66 - 1
mcs/class/System.Web/System.Web.Profile/ProfileBase.cs

@@ -33,6 +33,7 @@ using System.Configuration;
 using System.Configuration.Provider;
 using System.Web.Security;
 using System.Web.Configuration;
+using System.Reflection;
 
 namespace System.Web.Profile
 {
@@ -87,6 +88,25 @@ namespace System.Web.Profile
 				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 (CreateSettingsPropery (pi [i]));
+
+						if (properiesType.BaseType == null || 
+							properiesType.BaseType == typeof (ProfileBase))
+							break;
+
+						properiesType = properiesType.BaseType;
+					}
+				}
+			}
+
 			properties.SetReadOnly ();
 			lock (Profiles_SettingsPropertyCollection) {
 				if (_properties == null)
@@ -188,7 +208,7 @@ namespace System.Web.Profile
 			if (profileType == null)
 				return null;
 
-			System.Reflection.PropertyInfo pi = profileType.GetProperty (pps.Name);
+			PropertyInfo pi = profileType.GetProperty (pps.Name);
 			if (pi != null)
 				return pi.PropertyType;
 
@@ -216,6 +236,48 @@ namespace System.Web.Profile
 					elementInfo.Source, elementInfo.LineNumber);
 		}
 
+		static SettingsProperty CreateSettingsPropery (PropertyInfo property)
+		{
+			SettingsProperty sp = new SettingsProperty (property.Name);
+
+			Attribute [] attributes = (Attribute [])property.GetCustomAttributes (typeof (SettingsSerializeAsAttribute), false);
+			SettingsAttributeDictionary attDict = new SettingsAttributeDictionary();
+			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;
+
+				else if (attributes [i] is SettingsProviderAttribute) {
+					Type providerType = Type.GetType (((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 ||
+					attributes [i] is ApplicationScopedSettingAttribute ||
+					attributes [i] is UserScopedSettingAttribute ||
+					attributes [i] is SettingsDescriptionAttribute  ||
+					attributes [i] is SettingAttribute)
+					attDict.Add (attributes [i].GetType (), attributes [i]);
+			}
+
+			if (sp.Provider == null)
+				sp.Provider = ProfileManager.Provider;
+
+			if (sp.Attributes ["AllowAnonymous"] == null)
+				sp.Attributes ["AllowAnonymous"] = false;
+
+			return sp;
+		}
 		static SettingsProperty CreateSettingsPropery (ProfileGroupSettings pgs, ProfilePropertySettings pps)
 		{
 			string name = ((pgs == null) ? "" : pgs.Name + ".") + pps.Name;
@@ -257,6 +319,9 @@ namespace System.Web.Profile
 			_settingsContext = new SettingsContext ();
 			_settingsContext.Add ("UserName", username);
 			_settingsContext.Add ("IsAuthenticated", isAuthenticated);
+			SettingsProviderCollection spc = new SettingsProviderCollection();
+			spc.Add (ProfileManager.Provider);
+			base.Initialize (Context, ProfileBase.Properties, spc);
 		}
 
 		public override void Save ()