summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenId/Configuration/StoreElement.cs
blob: d2c94cb27df6394234099cfc033e68ce88bf7f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Configuration;

namespace DotNetOpenId.Configuration {
	internal class StoreConfigurationElement<T> : ConfigurationElement {
		public StoreConfigurationElement() { }

		const string customStoreTypeConfigName = "type";
		[ConfigurationProperty(customStoreTypeConfigName)]
		//[SubclassTypeValidator(typeof(T))]
		public string TypeName {
			get { return (string)this[customStoreTypeConfigName]; }
			set { this[customStoreTypeConfigName] = value; }
		}

		public Type CustomStoreType {
			get { return string.IsNullOrEmpty(TypeName) ? null : Type.GetType(TypeName); }
		}

		public T CreateInstanceOfStore(T defaultValue) {
			return CustomStoreType != null ? (T)Activator.CreateInstance(CustomStoreType) : defaultValue;
		}
	}
}