本文整理汇总了C#中IPicoContainer.GetComponentInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IPicoContainer.GetComponentInstance方法的具体用法?C# IPicoContainer.GetComponentInstance怎么用?C# IPicoContainer.GetComponentInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPicoContainer
的用法示例。
在下文中一共展示了IPicoContainer.GetComponentInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveInstance
public virtual object ResolveInstance(IPicoContainer container, IComponentAdapter adapter, Type expectedType)
{
IComponentAdapter componentAdapter = ResolveAdapter(container, adapter, expectedType);
if (componentAdapter != null)
{
return container.GetComponentInstance(componentAdapter.ComponentKey);
}
return null;
}
示例2: GetCollectionInstance
private ICollection GetCollectionInstance(IPicoContainer container, Type expectedType, IDictionary adapterList)
{
Type collectionType = expectedType;
if (collectionType.IsInterface)
{
// The order of tests are significant. The least generic types last.
if (typeof (IList).IsAssignableFrom(collectionType))
{
collectionType = typeof (ArrayList);
}
// } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
// collectionType = ArrayBlockingQueue.class;
// } else if (Queue.class.isAssignableFrom(collectionType)) {
// collectionType = LinkedList.class;
/*} else if (SortedSet.class.isAssignableFrom(collectionType)) {
collectionType = TreeSet.class;
} else if (Set.class.isAssignableFrom(collectionType)) {
collectionType = HashSet.class;
}*/
else if (typeof (ICollection).IsAssignableFrom(collectionType))
{
collectionType = typeof (ArrayList);
}
}
try
{
IList result = (IList) Activator.CreateInstance(collectionType);
foreach (DictionaryEntry entry in adapterList)
{
IComponentAdapter componentAdapter = (IComponentAdapter) entry.Value;
result.Add(container.GetComponentInstance(componentAdapter.ComponentKey));
}
return result;
}
catch (Exception e)
{
throw new PicoInitializationException(e);
}
}
示例3: GetDictionaryInstance
private IDictionary GetDictionaryInstance(IPicoContainer container, Type expectedType, IDictionary adapterList)
{
Type collectionType = expectedType;
if (collectionType.IsInterface)
{
collectionType = typeof(Hashtable);
}
try
{
IDictionary result = (IDictionary) Activator.CreateInstance(collectionType);
foreach (DictionaryEntry entry in adapterList)
{
Object key = entry.Key;
result.Add(key, container.GetComponentInstance(key));
}
return result;
}
catch (Exception e)
{
throw new PicoInitializationException(e);
}
}
示例4: GetArrayInstance
private object[] GetArrayInstance(IPicoContainer container, Type expectedType, IDictionary adapterList)
{
object[] result = (object[]) Array.CreateInstance(expectedType.GetElementType(), adapterList.Count);
int i = 0;
foreach (DictionaryEntry entry in adapterList)
{
IComponentAdapter componentAdapter = (IComponentAdapter) entry.Value;
result[i] = container.GetComponentInstance(componentAdapter.ComponentKey);
i++;
}
return result;
}