annotate Source/Reflection/ObjectFactoryAttribute.cs @ 9:1e85f66cf767 default tip

update bltoolkit
author nickolay
date Thu, 05 Apr 2018 20:53:26 +0300
parents f990fcb411a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
1 using System;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
2 using System.Diagnostics.CodeAnalysis;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
3
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
4 namespace BLToolkit.Reflection
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
5 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
6 [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
7 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
8 public class ObjectFactoryAttribute : Attribute
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
9 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
10 public ObjectFactoryAttribute(Type type)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
11 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
12 if (type == null) throw new ArgumentNullException("type");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
13
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
14 _objectFactory = Activator.CreateInstance(type) as IObjectFactory;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
15
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
16 if (_objectFactory == null)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
17 throw new ArgumentException(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
18 string.Format("Type '{0}' does not implement IObjectFactory interface.", type));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
19 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
20
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
21 private readonly IObjectFactory _objectFactory;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
22 public IObjectFactory ObjectFactory
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
23 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
24 get { return _objectFactory; }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
25 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
26 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
27 }