本文整理汇总了C#中IComponentContext.InjectProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IComponentContext.InjectProperties方法的具体用法?C# IComponentContext.InjectProperties怎么用?C# IComponentContext.InjectProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IComponentContext
的用法示例。
在下文中一共展示了IComponentContext.InjectProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInjector
/// <summary>
/// Override to return a closure that injects properties into a target.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>The injector.</returns>
protected override Func<object, object> GetInjector(IComponentContext context)
{
if (context == null)
throw new ArgumentNullException("context");
return target =>
{
var targetType = target.GetType();
if (targetType.GetCustomAttributes(typeof(InjectPropertiesAttribute), true).Length > 0)
{
return context.InjectProperties(target);
}
else if (targetType.GetCustomAttributes(typeof(InjectUnsetPropertiesAttribute), true).Length > 0)
{
return context.InjectUnsetProperties(target);
}
else
{
return target;
}
};
}
示例2: ResolveScriptDependency
protected SchedulerTaskScriptDependencies ResolveScriptDependency(ISchedulerTaskScript script, IComponentContext context)
{
if (script.DependencyClassType == null || script.DependencyClassType == typeof(void))
{
//TODO: return some default dependency
return null;
}
var result = context.ResolveOptional(script.DependencyClassType) as SchedulerTaskScriptDependencies;
//creating instance manually
if (result == null)
{
result = Activator.CreateInstance(script.DependencyClassType)
as SchedulerTaskScriptDependencies;
if (result == null) throw new Exception("Script Dependency can not be resolved. Check the dependency type");
context.InjectProperties(result);
}
if(result==null) throw new Exception("Script Dependency can not be resolved");
return result;
}