本文整理汇总了C#中System.Type.CanBeCastTo方法的典型用法代码示例。如果您正苦于以下问题:C# Type.CanBeCastTo方法的具体用法?C# Type.CanBeCastTo怎么用?C# Type.CanBeCastTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.CanBeCastTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetermineLoaderType
public static Type DetermineLoaderType(Type type)
{
if (type.CanBeCastTo<IApplicationLoader>()) return type;
if (type.CanBeCastTo<FubuRegistry>()) return typeof (FubuRegistryLoader<>).MakeGenericType(type);
throw new ArgumentOutOfRangeException("type", "Only IApplicationLoader types can be used here");
}
示例2: Process
public void Process(Type type, Registry registry) {
if (type.CanBeCastTo<Controller>() && !type.IsAbstract) {
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
else if (type.CanBeCastTo<ApiController>() && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
示例3: IsWebFormView
public static bool IsWebFormView(Type type)
{
return type != typeof(FubuPage)
&& !type.IsOpenGeneric()
&& type.CanBeCastTo<Page>()
&& type.CanBeCastTo<IFubuPage>();
}
示例4: IsLoaderTypeCandidate
public static bool IsLoaderTypeCandidate(Type type)
{
if (type.IsOpenGeneric()) return false;
if (!type.IsConcreteWithDefaultCtor()) return false;
if (type.CanBeCastTo<FubuRegistry>()) return true;
return type.CanBeCastTo<IApplicationLoader>();
}
示例5: Process
public void Process(Type type, Registry registry)
{
if (type.CanBeCastTo<ITeam>() && type != typeof(ITeam))
{
registry.For(typeof(ITeam)).Add(type);
}
}
示例6: CreateCollectionDefinition
internal static SequenceDefinition CreateCollectionDefinition(Type type)
{
// IEnumerable<T> with Add(T) method
Type itemType = type.GetGenericInterfaceType(typeof(IEnumerable<>));
if (itemType != null)
{
MethodInfo addMethod = type.GetMethod("Add", new[] { itemType });
if (addMethod != null)
{
return new CollectionDefinition(type, itemType, ObjectInterfaceProvider.GetAction(addMethod));
}
}
// IEumerable with Add(object) method
if (type.CanBeCastTo(typeof(IEnumerable)))
{
MethodInfo addMethod = type.GetMethod("Add", new[] { typeof(object) });
if (addMethod != null)
{
return new CollectionDefinition(type, typeof(object), ObjectInterfaceProvider.GetAction(addMethod));
}
}
return null;
}
示例7: Process
public void Process(Type type, Registry registry)
{
if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());// will create a new instance per request
}
}
示例8: Process
public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
{
if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
示例9: RulesFor
public IEnumerable<IValidationRule> RulesFor(Type type)
{
if (type.CanBeCastTo<IValidated>())
{
yield return new SelfValidatingClassRule(type);
}
}
示例10: DetermineLoaderType
public static Type DetermineLoaderType(Type type)
{
if (type.CanBeCastTo<IApplicationLoader>()) return type;
if (type.CanBeCastTo<IBootstrapper>())
{
return typeof (BootstrapperApplicationLoader<>).MakeGenericType(type);
}
var @interface = type.FindInterfaceThatCloses(typeof (IApplicationSource<,>));
if (@interface == null) throw new ArgumentOutOfRangeException("type must implement either IBootstrapper, IApplicationLoader, or IApplicationSource<TApplication,TRuntime> (FubuMVC's IApplicationSource)");
var genericArguments = @interface.GetGenericArguments();
return typeof (ApplicationLoader<,,>)
.MakeGenericType(type, genericArguments.First(), genericArguments.Last());
}
示例11: Process
private void Process(Type type, Registry registry)
{
if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
示例12: Process
public void Process(Type type, Registry registry)
{
if (type.CanBeCastTo(typeof(BaseDataService<>)) && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
示例13: Find
public ConstructorInfo Find(Type pluggedType)
{
// if this rule does not apply to the pluggedType,
// just return null to denote "not applicable"
if (!pluggedType.CanBeCastTo<BaseThing>()) return null;
return pluggedType.GetConstructor(new Type[] {typeof (IWidget)});
}
示例14: Process
public void Process(Type type, Registry registry)
{
if (type.CanBeCastTo<IValueProvider>())
{
var factoryType = typeof(StructureMapValueProviderFactory<>).MakeGenericType(type);
registry.For<ValueProviderFactory>().Use(c => (ValueProviderFactory)c.GetInstance(factoryType));
}
}
示例15: Find
public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph)
{
// if this rule does not apply to the pluggedType,
// just return null to denote "not applicable"
if (!pluggedType.CanBeCastTo<BaseThing>()) return null;
return pluggedType.GetConstructor(new[] {typeof (IWidget)});
}