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


C# IContainer.CreateObject方法代码示例

本文整理汇总了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;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:16,代码来源:SaltarelleParserFactory.Server.cs

示例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));
			}
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:19,代码来源:SaltarelleParserFactory.Server.cs


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