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


C# Type.Is方法代码示例

本文整理汇总了C#中System.Type.Is方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Is方法的具体用法?C# Type.Is怎么用?C# Type.Is使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Type的用法示例。


在下文中一共展示了Type.Is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Close

 // this has been through red and green phase, it has yet to see it's refactor phase
 public Type Close(Type conversionPatternType, Type sourceType, Type targetType)
 {
     var @interface = conversionPatternType.GetInterface(typeof (IConversionPattern<,>));
     if (@interface == null)
     {
         throw new ArgumentException(string.Format("Type {0} doesn't implement {1} and therefore is invalid for this operation.", conversionPatternType, typeof (IConversionPattern<,>)));
     }
     var arguments = @interface.GetGenericArguments();
     var interfaceSourceType = arguments[0];
     var interfaceTargetType = arguments[1];
     if (conversionPatternType.IsGenericType == false)
     {
         if (sourceType.Is(interfaceSourceType) && targetType.Is(interfaceTargetType))
         {
             return conversionPatternType;
         }
         return null;
     }
     var openClassArguments = conversionPatternType.GetGenericArguments();
     var parameters = new Type[openClassArguments.Length];
     if (TryAddParameters(sourceType, interfaceSourceType, parameters, openClassArguments) == false)
     {
         return null;
     }
     if (TryAddParameters(targetType, interfaceTargetType, parameters, openClassArguments) == false)
     {
         return null;
     }
     if (parameters.Any(p => p == null))
     {
         return null;
     }
     return conversionPatternType.MakeGenericType(parameters);
 }
开发者ID:kkozmic,项目名称:Cartographer,代码行数:35,代码来源:ConversionPatternGenericCloser.cs

示例2: CanConvert

 public override bool CanConvert(Type objectType)
 {
     // Type should not be a User or Device since these have their specific serializers.
     // This serializer should be used for any other type that inherits from article.
     if (objectType != typeof(User) && objectType != typeof(Device))
         return objectType.Is<Article>();
     else 
         return false;
 }
开发者ID:neilunadkat,项目名称:appacitive-dotnet-sdk,代码行数:9,代码来源:ArticleConverter.cs

示例3: To

        public IBindingScope To(Type concreteType)
        {
            Assert.IsNotNull(concreteType);
            Assert.IsTrue(concreteType.IsConcrete());
            Assert.IsTrue(concreteType.Is(ContractType));

            return ToMethod(c => c.Container.Instantiator
                .Instantiate(new InjectionContext { Container = c.Container, DeclaringType = concreteType }));
        }
开发者ID:Magicolo,项目名称:PseudoFramework,代码行数:9,代码来源:BindingContract.cs

示例4: JobConfiguration

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="jobType">The type of the class that implements the job</param>
        /// <param name="builder">The trigger builder</param>
        public JobConfiguration(
            Type jobType,
            Func<TriggerBuilder> builder)
        {
            jobType.Is<IJob>();
            builder.NotNull(nameof(builder));

            JobType = jobType;
            TriggerBuilder = builder;
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:15,代码来源:JobConfiguration.cs

示例5: ToFactory

        public IBindingScope ToFactory(Type factoryType)
        {
            Assert.IsNotNull(factoryType);
            Assert.IsTrue(factoryType.Is<IInjectionFactory>());

            Container.Binder.Bind(factoryType).ToSelf().AsSingleton();

            return ToMethod(c => ((IInjectionFactory)c.Container.Resolver
                .Resolve(new InjectionContext { Container = c.Container, ContractType = factoryType }))
                .Create(c));
        }
开发者ID:Magicolo,项目名称:PseudoFramework,代码行数:11,代码来源:BindingContract.cs

示例6: SelectInterceptors

		public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
		{
			if (type.Is<ICatalog>())
			{
				if (method.Name == "AddItem")
				{
					return interceptors;
				}
			}
			return null;
		}
开发者ID:dohansen,项目名称:Windsor,代码行数:11,代码来源:DummyInterceptorSelector.cs

示例7: AbstractHandler

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="exceptionMessage">Exception message to be included in the new exception</param>
        /// <param name="exceptionType">Type of the new exception to be created</param>
        public AbstractHandler(
            string exceptionMessage,
            Type exceptionType)
        {
            exceptionMessage.NotNullOrEmpty(nameof(exceptionMessage));
            exceptionType.NotNull(nameof(exceptionType));
            exceptionType.Is<Exception>();

            _exceptionMessage = exceptionMessage;
            ExceptionType = exceptionType;
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:16,代码来源:AbstractHandler.cs

示例8: ConvertibleAttribute

		/// <summary>
		///   Defines the <see cref = "ITypeConverter" /> to be used to convert the type
		/// </summary>
		/// <param name = "converterType"></param>
		public ConvertibleAttribute(Type converterType)
		{
			if (converterType.Is<ITypeConverter>() == false)
			{
				throw new ArgumentException(
					string.Format("ConverterType {0} does not implement {1} interface", converterType.FullName,
					              typeof(ITypeConverter).FullName), "converterType");
			}

			this.converterType = converterType;
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:15,代码来源:ConvertibleAttribute.cs

示例9: Generate

        /// <summary>
        /// Generates the key that should be use to cache/retrieve the content
        /// for the given controllerType and action name
        /// </summary>
        /// <param name="controllerType">The controller type (must be ApiController)</param>
        /// <param name="actionName">The action name</param>
        /// <param name="context">The action context</param>
        /// <returns>The key for the given controller type and action name</returns>
        /// <exception cref="ArgumentException">If controller type is not an ApiController</exception>
        public virtual string Generate(
            Type controllerType,
            string actionName,
            HttpActionContext context)
        {
            controllerType.NotNull(nameof(controllerType));
            controllerType.Is<ApiController>();
            actionName.NotNullOrEmpty(nameof(actionName));
            context.NotNull(nameof(context));

            return "{0}-{1}".AsFormat(controllerType.FullName, actionName);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:21,代码来源:DefaultCacheKeyGenerator.cs

示例10: InvalidateXReferencedOutputCacheAttribute

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="controllerType">The controller type (must be ApiController)</param>
        /// <param name="actionName">The action name</param>
        /// <param name="cacheKeyGeneratorType">The type of the class responsible for generating the keys</param>
        public InvalidateXReferencedOutputCacheAttribute(
            Type controllerType,
            string actionName,
            Type cacheKeyGeneratorType = null)
        {
            controllerType.NotNull(nameof(controllerType));
            controllerType.Is<ApiController>();
            actionName.NotNullOrEmpty(nameof(actionName));

            ActionName = actionName;
            ControllerType = controllerType;
            CacheKeyGeneratorType = cacheKeyGeneratorType ?? typeof(DefaultCacheKeyGenerator);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:19,代码来源:InvalidateXReferencedOutputCacheAttribute.cs

示例11: GetValue

        public override object GetValue(IContent content, PropertyInfo property, Type collectionItemType)
        {
            // Let's support both Pages and ContentReference collections
            bool returnReferences = collectionItemType.Is<ContentReference>();

            var descendents = ContentLoader.GetDescendents(content.ContentLink);

            var result = returnReferences
                ? descendents.ToList()
                : GetPagesCollection(() => descendents, collectionItemType);

            return result;
        }
开发者ID:VladimirLevchuk,项目名称:EPiProperties,代码行数:13,代码来源:DescendentsPropertyGetter.cs

示例12: ExtractInvokeMethod

		public static MethodInfo ExtractInvokeMethod(Type service)
		{
			if (!service.Is<MulticastDelegate>())
			{
				return null;
			}

			var invoke = GetInvokeMethod(service);
			if (!HasReturn(invoke))
			{
				return null;
			}

			return invoke;
		}
开发者ID:CV1,项目名称:Windsor,代码行数:15,代码来源:DelegateFactory.cs

示例13: AddNodeProcessor

		public void AddNodeProcessor(Type type)
		{
			if (type.Is<IXmlNodeProcessor>())
			{
				var processor = type.CreateInstance<IXmlNodeProcessor>();
				foreach(var nodeType in processor.AcceptNodeTypes)
				{
					RegisterProcessor(nodeType, processor);
				}
			}
			else
			{
				throw new XmlProcessorException("{0} does not implement IElementProcessor interface", type.FullName);
			}
		}
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:15,代码来源:DefaultXmlProcessorEngine.cs

示例14: JobAttribute

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="processorType">The type that implments IProcessor</param>
        public JobAttribute(Type processorType)
        {
            processorType.Is<IProcessor>();

            ProcessorType = processorType;
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:10,代码来源:JobAttribute.cs

示例15: CanConvert

 public override bool CanConvert(Type objectType)
 {
     return objectType.Is<APConnection>();
 }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:4,代码来源:ConnectionConverter.cs


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