當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。