/// <summary> /// Активирует сервис по имени класса /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="activationType"></param> /// <returns></returns> public T Activate <T>(string name, BSharpActivationType activationType = BSharpActivationType.Auto) where T : class { var runtimeclass = GetRuntimeClass(name); if (null == runtimeclass) { throw new BSharpRuntimeException("cannot create runtime class with name " + name); } return(Activate <T>(runtimeclass, activationType)); }
/// <summary> /// Создать типизированный объект из динамического объекта BSharp /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T Activate <T>(IBSharpRuntimeClass runtimeclass, BSharpActivationType activationType) where T : class { IBSharpRuntimeActivatorService activator = Activators .OrderBy(_ => _.Index) .FirstOrDefault(_ => _.CanActivate <T>(runtimeclass, activationType)); if (null == activator) { throw new BSharpRuntimeException("cannot find activator for " + runtimeclass.Fullname + " to create requested service " + typeof(T).Name); } return(activator.Activate <T>(runtimeclass, activationType)); }
/// <summary> /// Проверяет поддержку сериализации /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public bool CanActivate <T>(IBSharpRuntimeClass rtcls, BSharpActivationType activationType = BSharpActivationType.Auto) where T : class { if (BSharpActivationType.Auto == activationType) { activationType = DetectActivationtType <T>(rtcls); } if (BSharpActivationType.Client == activationType) { return(GetCanActivateClient <T>()); } if (BSharpActivationType.Configured == activationType) { return(GetCanActivateConfigured <T>(rtcls)); } throw new Exception("invalid activation type " + activationType); }
/// <summary> /// Создать типизированный объект из динамического объекта BSharp /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T Activate <T>(IBSharpRuntimeClass rtcls, BSharpActivationType activationType = BSharpActivationType.Auto) where T : class { if (activationType == BSharpActivationType.Auto) { activationType = DetectActivationtType <T>(rtcls); } if (!CanActivate <T>(rtcls, activationType)) { return(default(T)); } switch (activationType) { case BSharpActivationType.Client: return(ActivateClientType <T>(rtcls)); case BSharpActivationType.Configured: return(ActivateConfiguredType <T>(rtcls)); } return(default(T)); }