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


C# Type.CanBeCastTo方法代码示例

本文整理汇总了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");
        }
开发者ID:cothienlac86,项目名称:fubumvc,代码行数:8,代码来源:ApplicationLoaderFinder.cs

示例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());
     }
 }
开发者ID:NemeStats,项目名称:NemeStats,代码行数:9,代码来源:ControllerConvention.cs

示例3: IsWebFormView

        public static bool IsWebFormView(Type type)
        {



            return type != typeof(FubuPage) 
                && !type.IsOpenGeneric()
                && type.CanBeCastTo<Page>() 
                && type.CanBeCastTo<IFubuPage>();
        }
开发者ID:DarthFubuMVC,项目名称:FubuMVC.WebForms,代码行数:10,代码来源:WebFormViewFacility.cs

示例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>();
        }
开发者ID:cothienlac86,项目名称:fubumvc,代码行数:10,代码来源:ApplicationLoaderFinder.cs

示例5: Process

 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo<ITeam>() && type != typeof(ITeam))
     {
         registry.For(typeof(ITeam)).Add(type);
     }
 }
开发者ID:goraw,项目名称:structuremap,代码行数:7,代码来源:MyRegistry.cs

示例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;
        }
开发者ID:soxtoby,项目名称:ForSerial,代码行数:25,代码来源:CollectionDefinition.cs

示例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
     }
 }
开发者ID:hebert26,项目名称:MVC.Training,代码行数:7,代码来源:ControllerConvention.cs

示例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());
     }
 }
开发者ID:huyquocmai,项目名称:WebFramework,代码行数:7,代码来源:ControllerConvention.cs

示例9: RulesFor

 public IEnumerable<IValidationRule> RulesFor(Type type)
 {
     if (type.CanBeCastTo<IValidated>())
     {
         yield return new SelfValidatingClassRule(type);
     }
 }
开发者ID:stevematney,项目名称:fubuvalidation,代码行数:7,代码来源:IValidated.cs

示例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());
        }
开发者ID:DarthFubuMVC,项目名称:bottles,代码行数:16,代码来源:BottleServiceApplication.cs

示例11: Process

 private void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
开发者ID:MattHoneycutt,项目名称:HeroicFramework,代码行数:7,代码来源:ControllerConvention.cs

示例12: Process

 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(typeof(BaseDataService<>)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
开发者ID:onnorh,项目名称:test,代码行数:7,代码来源:ServiceConvention.cs

示例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)});
        }
开发者ID:goraw,项目名称:structuremap,代码行数:8,代码来源:constructor_selection.cs

示例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));
     }
 }
开发者ID:rajeshpillai,项目名称:Fail-Tracker,代码行数:8,代码来源:ValueProviderScanner.cs

示例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)});
        }
开发者ID:slahn,项目名称:structuremap,代码行数:8,代码来源:constructor_selection.cs


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