本文整理汇总了C#中System.Factory.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.ThrowIfNull方法的具体用法?C# Factory.ThrowIfNull怎么用?C# Factory.ThrowIfNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Factory
的用法示例。
在下文中一共展示了Factory.ThrowIfNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public Factory Register(Factory factory, Type serviceType, object serviceKey)
{
var implementationType = factory.ThrowIfNull().ImplementationType;
if (implementationType != null && serviceType.ThrowIfNull() != typeof(object))
{
Throw.If(!implementationType.GetImplementedTypes().Contains(serviceType),
Error.EXPECTED_IMPL_TYPE_ASSIGNABLE_TO_SERVICE_TYPE, implementationType, serviceType);
}
lock (_syncRoot)
{
if (factory.Setup.Type == FactoryType.Decorator)
{
_decorators = _decorators.AddOrUpdate(serviceType, new[] { new DecoratorsEntry(factory) }, Sugar.Append);
return factory;
}
var entry = _factories.GetOrAdd(serviceType, _ => new FactoriesEntry());
if (serviceKey == null)
{ // default factories will contain all the factories and LastDefault will just point to the latest,
// for memory saving reasons.
if (entry.LastDefaultFactory != null)
entry.DefaultFactories = (entry.DefaultFactories
?? HashTree<int, Factory>.Empty.AddOrUpdate(entry.MaxDefaultIndex++, entry.LastDefaultFactory))
.AddOrUpdate(entry.MaxDefaultIndex++, factory);
entry.LastDefaultFactory = factory;
}
else if (serviceKey is int)
{
var index = (int)serviceKey;
entry.DefaultFactories = (entry.DefaultFactories ?? HashTree<int, Factory>.Empty).AddOrUpdate(index, factory);
entry.MaxDefaultIndex = Math.Max(entry.MaxDefaultIndex, index) + 1;
}
else if (serviceKey is string)
{
var name = (string)serviceKey;
var named = entry.NamedFactories = entry.NamedFactories ?? new Dictionary<string, Factory>();
if (named.ContainsKey(name))
Throw.If(true, Error.DUPLICATE_SERVICE_NAME, serviceType, name, named[name].ImplementationType);
named.Add(name, factory);
}
}
return factory;
}