当前位置: 首页>>代码示例>>C#>>正文


C# PluginRuntime.InstantiatePluginObject方法代码示例

本文整理汇总了C#中MediaPortal.Common.PluginManager.PluginRuntime.InstantiatePluginObject方法的典型用法代码示例。如果您正苦于以下问题:C# PluginRuntime.InstantiatePluginObject方法的具体用法?C# PluginRuntime.InstantiatePluginObject怎么用?C# PluginRuntime.InstantiatePluginObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MediaPortal.Common.PluginManager.PluginRuntime的用法示例。


在下文中一共展示了PluginRuntime.InstantiatePluginObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildItem

 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ServiceClassName", itemData);
   string serviceClassName = itemData.Attributes["ServiceClassName"];
   object serviceInstance = plugin.InstantiatePluginObject(serviceClassName);
   if (serviceInstance == null)
   {
     ServiceRegistration.Get<ILogger>().Warn("ServiceBuilder: Could not instantiate service class '{0}' in plugin '{1}' (id: '{2}')",
         serviceClassName, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId);
     return null;
   }
   string registrationClassAssembly;
   if (!itemData.Attributes.TryGetValue("RegistrationClassAssembly", out registrationClassAssembly))
     registrationClassAssembly = null;
   string registrationClassName;
   if (!itemData.Attributes.TryGetValue("RegistrationClassName", out registrationClassName))
     registrationClassName = null;
   Type registrationType;
   if (string.IsNullOrEmpty(registrationClassName))
     registrationType = serviceInstance.GetType();
   else
     registrationType = string.IsNullOrEmpty(registrationClassAssembly) ? plugin.GetPluginType(registrationClassName) :
         Type.GetType(registrationClassName + ", " + registrationClassAssembly);
   if (registrationType == null)
   {
     ServiceRegistration.Get<ILogger>().Warn("ServiceBuilder: Could not instantiate service registration type '{0}' (Assembly: '{1}') in plugin '{2}' (id: '{3}')",
         registrationClassName, registrationClassAssembly, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId);
     return null;
   }
   return new ServiceItem(registrationType, serviceInstance);
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:31,代码来源:ServiceBuilder.cs

示例2: BuildItem

 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BackgroundType type;
   string value = GetBackgroundAndType(itemData.Attributes, out type);
   switch (type)
   {
     case BackgroundType.Static:
       return new StaticBackgroundManager(value);
     case BackgroundType.Manager:
       // The cast is necessary here to ensure the returned instance is an IBackgroundManager
       return (IBackgroundManager) plugin.InstantiatePluginObject(value);
     default:
       throw new NotImplementedException(string.Format(
           "Background builder: Background type '{0}' is not implemented", type));
   }
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:16,代码来源:BackgroundBuilder.cs

示例3: Instantiate

 protected ConfigBase Instantiate(ConfigBaseMetadata metadata, PluginRuntime pluginRuntime)
 {
   ServiceRegistration.Get<ILogger>().Debug("ConfigurationNode: Loading configuration item '{0}'", metadata.Location);
   ConfigBase result;
   if (metadata.GetType() == typeof(ConfigGroupMetadata))
     result = new ConfigGroup();
   else if (metadata.GetType() == typeof(ConfigSectionMetadata))
     result = new ConfigSection();
   else if (metadata.GetType() == typeof(ConfigSettingMetadata))
   {
     ConfigSettingMetadata csm = (ConfigSettingMetadata) metadata;
     try
     {
       ConfigSetting cs = (ConfigSetting) pluginRuntime.InstantiatePluginObject(csm.ClassName);
       if (cs == null)
         throw new ArgumentException(string.Format("Configuration class '{0}' not found", csm.ClassName));
       cs.Load();
       if (csm.ListenTo != null)
         foreach (string listenToLocation in csm.ListenTo)
         {
           IConfigurationNode node;
           if (FindNode(listenToLocation, out node))
             if (node.ConfigObj is ConfigSetting)
               cs.ListenTo((ConfigSetting) node.ConfigObj);
             else
               ServiceRegistration.Get<ILogger>().Warn("ConfigurationNode '{0}': Trying to listen to setting, but location '{1}' references a {2}",
                                                Location, listenToLocation, node.ConfigObj.GetType().Name);
         }
       result = cs;
     }
     catch (Exception ex)
     {
       ServiceRegistration.Get<ILogger>().Error("Error loading configuration class '{0}'", ex, csm.ClassName);
       return null;
     }
   }
   else
     throw new NotImplementedException(string.Format("Unknown child class '{0}' of '{1}'", metadata.GetType().FullName, typeof(ConfigBaseMetadata).FullName));
   result.SetMetadata(metadata);
   return result;
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:41,代码来源:ConfigurationNode.cs

示例4: BuildItem

 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   return plugin.InstantiatePluginObject(itemData.Attributes["ClassName"]);
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:5,代码来源:InstanceBuilder.cs


注:本文中的MediaPortal.Common.PluginManager.PluginRuntime.InstantiatePluginObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。