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


C# Type.IsInterface方法代码示例

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


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

示例1: IsGenericTypeOf

        public static bool IsGenericTypeOf(this Type t, Type genericDefinition, out Type[] genericParameters)
        {
            genericParameters = new Type[] { };
            if (!genericDefinition.IsGenericType())
            {
                return false;
            }

            var isMatch = t.IsGenericType() && t.GetGenericTypeDefinition() == genericDefinition.GetGenericTypeDefinition();
            if (!isMatch && t.GetBaseType() != null)
            {
                isMatch = IsGenericTypeOf(t.GetBaseType(), genericDefinition, out genericParameters);
            }
            if (!isMatch && genericDefinition.IsInterface() && t.GetInterfaces().Any())
            {
                foreach (var i in t.GetInterfaces())
                {
                    if (i.IsGenericTypeOf(genericDefinition, out genericParameters))
                    {
                        isMatch = true;
                        break;
                    }
                }
            }

            if (isMatch && !genericParameters.Any())
            {
                genericParameters = t.GetGenericArguments();
            }
            return isMatch;
        }
开发者ID:wholroyd,项目名称:ShareFile-NET,代码行数:31,代码来源:TypeExtensions.cs

示例2: ToClass

 public static RubyClass ToClass(RubyContext/*!*/ context, Type/*!*/ self)
 {
     if (self.IsInterface()) {
         RubyExceptions.CreateTypeError("Cannot convert a CLR interface to a Ruby class");
     }
     return context.GetClass(self);
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:TypeOps.cs

示例3: CreateDictionary

        public static object CreateDictionary(Type dictionaryType, Type keyType, Type valueType)
        {
            var type = dictionaryType.IsInterface()
                ? typeof (Dictionary<,>).MakeGenericType(keyType, valueType)
                : dictionaryType;

            return CreateObject(type);
        }
开发者ID:redwyre,项目名称:AutoMapper,代码行数:8,代码来源:ObjectCreator.cs

示例4: CreateObject

 public static object CreateObject(Type type)
 {
     return type.IsArray
         ? CreateArray(type.GetElementType(), 0)
         : type == typeof (string)
             ? null
             : type.IsInterface() && type.IsDictionaryType()
                 ? CreateDictionary(type) 
                 : DelegateFactory.CreateCtor(type)();
 }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:10,代码来源:ObjectCreator.cs

示例5: CreateDictionary

        public static object CreateDictionary(Type dictionaryType)
        {
            Type keyType = dictionaryType.GetTypeInfo().GenericTypeArguments[0];
            Type valueType = dictionaryType.GetTypeInfo().GenericTypeArguments[1];
            var type = dictionaryType.IsInterface()
                ? typeof (Dictionary<,>).MakeGenericType(keyType, valueType)
                : dictionaryType;

            return DelegateFactory.CreateCtor(type)();
        }
开发者ID:sh-sabooni,项目名称:AutoMapper,代码行数:10,代码来源:ObjectCreator.cs

示例6: IsPrimitiveOrClass

		private bool IsPrimitiveOrClass(Type type)
		{
			if ((type.IsPrimitive() && type != typeof(IntPtr)))
			{
				return true;
			}
			return ((type.IsClass() || type.IsInterface()) &&
			        type.IsGenericParameter == false &&
			        type.IsByRef == false);
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:10,代码来源:DefaultValueExpression.cs

示例7: AddEmptyInterface

		public void AddEmptyInterface(Type @interface)
		{
			DebugExtender.Assert(@interface != null, "@interface == null", "Shouldn't be adding empty interfaces...");
			DebugExtender.Assert(@interface.IsInterface(), "@interface.IsInterface()", "Should be adding interfaces only...");
			DebugExtender.Assert(!interfaces.Contains(@interface), "!interfaces.Contains(@interface)",
			             "Shouldn't be adding same interface twice...");
			DebugExtender.Assert(!empty.Contains(@interface), "!empty.Contains(@interface)",
			             "Shouldn't be adding same interface twice...");
			empty.Add(@interface);
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:10,代码来源:MixinContributor.cs

示例8: GetTryConvertReturnValue

        /// <summary>
        /// Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or
        /// ExplicitTry.
        /// </summary>
        public static Expression GetTryConvertReturnValue(Type type)
        {
            Expression res;
            if (type.IsInterface() || type.IsClass()) {
                res = AstUtils.Constant(null, type);
            } else {
                res = AstUtils.Constant(null);
            }

            return res;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:15,代码来源:DefaultBinder.Conversions.cs

示例9: GetImplementedInterfaces

        public static IEnumerable<Type> GetImplementedInterfaces(Type type)
        {
            if (type.IsInterface())
            {
                yield return type;
            }

            foreach (var implementedInterface in type.GetInterfaces())
            {
                yield return implementedInterface;
            }
        }
开发者ID:nbarbettini,项目名称:YamlDotNet,代码行数:12,代码来源:ReflectionUtility.cs

示例10: CreateProxyUsingCastleProxyGenerator

 private object CreateProxyUsingCastleProxyGenerator(Type typeToProxy, Type[] additionalInterfaces,
                                                     object[] constructorArguments,
                                                     IInterceptor interceptor,
                                                     ProxyGenerationOptions proxyGenerationOptions)
 {
     if (typeToProxy.IsInterface())
     {
         VerifyNoConstructorArgumentsGivenForInterface(constructorArguments);
         return _proxyGenerator.CreateInterfaceProxyWithoutTarget(typeToProxy, additionalInterfaces, proxyGenerationOptions, interceptor);
     }
     return _proxyGenerator.CreateClassProxy(typeToProxy, additionalInterfaces, proxyGenerationOptions, constructorArguments, interceptor);
 }
开发者ID:nsubstitute,项目名称:NSubstitute,代码行数:12,代码来源:CastleDynamicProxyFactory.cs

示例11: CreateProviderForType

        IProvider CreateProviderForType(
            Type contractType, IPrefabInstantiator instantiator)
        {
            if (contractType == typeof(GameObject))
            {
                return new PrefabGameObjectProvider(instantiator);
            }

            Assert.That(contractType.IsInterface() || contractType.DerivesFrom<Component>());

            return new GetFromPrefabComponentProvider(
                contractType, instantiator);
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:13,代码来源:PrefabResourceBindingFinalizer.cs

示例12: RegisterValidator

        public static void RegisterValidator(this Container container, Type validator, ReuseScope scope=ReuseScope.None)
        {
            var baseType = validator.BaseType();
            if (validator.IsInterface() || baseType == null) return;
            while (!baseType.IsGenericType())
            {
                baseType = baseType.BaseType();
            }

            var dtoType = baseType.GetGenericArguments()[0];
            var validatorType = typeof(IValidator<>).GetCachedGenericType(dtoType);

            container.RegisterAutoWiredType(validator, validatorType, scope);
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:14,代码来源:ValidationFeature.cs

示例13: CodeTypeReference

        public CodeTypeReference(Type type) {
            if (type == null)
                throw new ArgumentNullException("type");
            
            if (type.IsArray) {
                this.arrayRank = type.GetArrayRank();
                this.arrayElementType = new CodeTypeReference(type.GetElementType());
                this.baseType = null;
            } else {
                InitializeFromType(type);
                this.arrayRank = 0;
                this.arrayElementType = null;
            }

            this.isInterface = type.IsInterface();
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:CodeTypeReference.cs

示例14: Create

		public object Create(Type type)
		{
			if (type.IsInterface())
			{
				Type implementationType;
				if (defaultInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out implementationType))
				{
					type = implementationType.MakeGenericType(type.GetGenericArguments());
				}
			}

			try
			{
				return Activator.CreateInstance(type);
			}
			catch (Exception err)
			{
				var message = string.Format("Failed to create an instance of type '{0}'.", type);
				throw new InvalidOperationException(message, err);
			}
		}
开发者ID:ChelseaLing,项目名称:AssetGraph,代码行数:21,代码来源:DefaultObjectFactory.cs

示例15: GetNamespacesUsed

        public HashSet<string> GetNamespacesUsed(Type type)
        {
            var to = new HashSet<string>();

            if (type.IsUserType() || type.IsInterface() || type.IsOrHasGenericInterfaceTypeOf(typeof(IEnumerable<>)))
            {
                foreach (var pi in GetInstancePublicProperties(type))
                {
                    if (pi.PropertyType.Namespace != null)
                    {
                        to.Add(pi.PropertyType.Namespace);
                    }

                    if (pi.PropertyType.IsGenericType())
                    {
                        pi.PropertyType.GetGenericArguments()
                            .Where(x => x.Namespace != null).Each(x => to.Add(x.Namespace));
                    }
                }

                if (type.IsGenericType())
                {
                    type.GetGenericArguments()
                        .Where(x => x.Namespace != null).Each(x => to.Add(x.Namespace));
                }
            }

            if (type.Namespace != null)
            {
                to.Add(type.Namespace);
            }

            return to;
        }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:34,代码来源:NativeTypesMetadata.cs


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