本文整理汇总了C#中IContainer.CreateObject方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.CreateObject方法的具体用法?C# IContainer.CreateObject怎么用?C# IContainer.CreateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.CreateObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUntypedParsers
private static IEnumerable<IUntypedMarkupParserImpl> GetUntypedParsers(Assembly asm, IContainer container) {
var seq = ( from tp in asm.GetTypes()
let attr = (UntypedMarkupParserImplAttribute)Attribute.GetCustomAttribute(tp, typeof(UntypedMarkupParserImplAttribute))
where attr != null
orderby attr.Priority descending
select tp);
var result = new List<IUntypedMarkupParserImpl>();
foreach (var tp in seq) {
if (!typeof(IUntypedMarkupParserImpl).IsAssignableFrom(tp))
throw new InvalidOperationException("The type " + tp.FullName + ", which is decorated with a UntypedMarkupParserImplAttribute, does not implement IUntypedMarkupParserImpl.");
if (tp.GetConstructor(Type.EmptyTypes) == null)
throw new InvalidOperationException("The type " + tp.FullName + ", which is decorated with a UntypedMarkupParserImplAttribute, does not have a parameterless public constructor.");
result.Add((IUntypedMarkupParserImpl)container.CreateObject(tp));
}
return result;
}
示例2: AddTypedMarkupParsersToDictionary
private static void AddTypedMarkupParsersToDictionary(Assembly asm, IDictionary<string, ITypedMarkupParserImpl> parsers, IContainer container) {
var seq = ( from tp in asm.GetTypes()
let p = new { tp, attr = (TypedMarkupParserImplAttribute)Attribute.GetCustomAttribute(tp, typeof(TypedMarkupParserImplAttribute)) }
where p.attr != null
group p by p.attr.Prefix into g
select g);
foreach (var g in seq) {
if (g.Count() > 1)
throw new InvalidOperationException("The plugin assembly " + asm.GetName().Name + " defines more than one typed markup processor for the prefix " + g.Key + ".");
var tp = g.Single().tp;
if (!typeof(ITypedMarkupParserImpl).IsAssignableFrom(tp))
throw new InvalidOperationException("The type " + tp.FullName + ", which is decorated with a TypedMarkupParserImplAttribute, does not implement ITypedMarkupParserImpl.");
if (tp.GetConstructor(Type.EmptyTypes) == null)
throw new InvalidOperationException("The type " + tp.FullName + ", which is decorated with a TypedMarkupParserImplAttribute, does not have a parameterless public constructor.");
if (!parsers.ContainsKey(g.Key))
parsers.Add(g.Key, (ITypedMarkupParserImpl)container.CreateObject(tp));
}
}