0
|
1 using System;
|
|
2 using System.Diagnostics.CodeAnalysis;
|
|
3
|
|
4 namespace BLToolkit.Reflection
|
|
5 {
|
|
6 [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
|
|
7 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
|
|
8 public class ObjectFactoryAttribute : Attribute
|
|
9 {
|
|
10 public ObjectFactoryAttribute(Type type)
|
|
11 {
|
|
12 if (type == null) throw new ArgumentNullException("type");
|
|
13
|
|
14 _objectFactory = Activator.CreateInstance(type) as IObjectFactory;
|
|
15
|
|
16 if (_objectFactory == null)
|
|
17 throw new ArgumentException(
|
|
18 string.Format("Type '{0}' does not implement IObjectFactory interface.", type));
|
|
19 }
|
|
20
|
|
21 private readonly IObjectFactory _objectFactory;
|
|
22 public IObjectFactory ObjectFactory
|
|
23 {
|
|
24 get { return _objectFactory; }
|
|
25 }
|
|
26 }
|
|
27 }
|