123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SuperSocket.Common;
- namespace SuperSocket.SocketBase.Provider
- {
-
-
-
- [Serializable]
- public class ExportFactory
- {
-
-
-
-
-
-
- public string TypeName { get; set; }
- private Type m_LoadedType;
- [NonSerialized]
- private object m_Instance;
-
-
-
- public ExportFactory()
- {
- }
-
-
-
-
- public ExportFactory(object instance)
- {
- m_Instance = instance;
- }
-
-
-
-
- public ExportFactory(string typeName)
- {
- TypeName = typeName;
- }
-
-
-
- public void EnsureInstance()
- {
- if (m_Instance != null)
- return;
- m_Instance = CreateInstance();
- }
- private object CreateInstance()
- {
- if (m_LoadedType == null)
- {
- m_LoadedType = AssemblyUtil.GetType(TypeName, true, true);
- }
- return Activator.CreateInstance(m_LoadedType);
- }
-
-
-
-
-
- public T CreateExport<T>()
- {
- if (m_Instance != null)
- return (T)m_Instance;
- return (T)CreateInstance();
- }
-
-
-
-
-
-
- public T CreateExport<T>(Func<Type, object> creator)
- {
- if (m_LoadedType == null)
- {
- m_LoadedType = AssemblyUtil.GetType(TypeName, true, true);
- }
- return (T)creator(m_LoadedType);
- }
- }
- }
|