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