本文整理汇总了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);
}
示例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));
}
}
示例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;
}
示例4: BuildItem
public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
{
BuilderHelper.CheckParameter("ClassName", itemData);
return plugin.InstantiatePluginObject(itemData.Attributes["ClassName"]);
}