當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.GetInterfaces方法代碼示例

本文整理匯總了C#中System.Type.GetInterfaces方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.GetInterfaces方法的具體用法?C# Type.GetInterfaces怎麽用?C# Type.GetInterfaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.GetInterfaces方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadAllToCache

        /// <summary>
        /// Dumps everything of a single type into the cache from the filesystem for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>full or partial success</returns>
        public static bool LoadAllToCache(Type objectType)
        {
            if (!objectType.GetInterfaces().Contains(typeof(IData)))
                return false;

            var fileAccessor = new NetMud.DataAccess.FileSystem.BackingData();
            var typeDirectory = fileAccessor.BaseDirectory + fileAccessor.CurrentDirectoryName + objectType.Name + "/";

            if (!fileAccessor.VerifyDirectory(typeDirectory, false))
            {
                LoggingUtility.LogError(new AccessViolationException(String.Format("Current directory for type {0} does not exist.", objectType.Name)));
                return false;
            }

            var filesDirectory = new DirectoryInfo(typeDirectory);

            foreach (var file in filesDirectory.EnumerateFiles())
            {
                try
                {
                    BackingDataCache.Add(fileAccessor.ReadEntity(file, objectType));
                }
                catch(Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return true;
        }
開發者ID:SwiftAusterity,項目名稱:NetMud,代碼行數:36,代碼來源:BackingData.cs

示例2: IsCollectionType

 /// <summary>
 /// Determines whether the specified property type is a collection.
 /// </summary>
 /// <param name="propertyType">Type of the property.</param>
 /// <returns></returns>
 public static bool IsCollectionType(Type propertyType)
 {
     return (propertyType.GetInterfaces().Contains(typeof(IList)) ||
             propertyType.GetInterfaces().Contains(typeof(ICollection)) ||
             propertyType.GetInterfaces().Contains(typeof(IDictionary)) ||
             propertyType.IsArray);
 }
開發者ID:castle-it,項目名稱:sharp2Js,代碼行數:12,代碼來源:Helpers.cs

示例3: Initialise

        /// <summary>
        /// Initialises the Factory property based on the type to which the attribute is applied.
        /// </summary>
        /// <param name="decoratedType">The type to which the attribute is applied</param>
        public virtual void Initialise(Type decoratedType)
        {
            if (Initialised)
            {
                throw new InvalidOperationException("Already initialised!");
            }

            var name = decoratedType.Name.ToProperCase();
            var alias = decoratedType.Name.ToCamelCase();
            if (Name == null)
            {
                Name = name;
            }
            if (Alias == null)
            {
                Alias = alias;
            }
            if (AllowedChildren == null && decoratedType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListViewDocumentType<>)))
            {
                var type = decoratedType.GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListViewDocumentType<>)).GetGenericArguments().First();

                if (type.GetCodeFirstAttribute<DocumentTypeAttribute>(false) != null)
                {
                    AllowedChildren = new Type[] { type };
                }
            }
            Initialised = true;
        }
開發者ID:DanMannMann,項目名稱:UmbracoCodeFirst,代碼行數:32,代碼來源:DocumentTypeAttribute.cs

示例4: AppendBaseClasses

        public void AppendBaseClasses(Type type)
        {
            if (((type.BaseType == null) || (type.BaseType == typeof(object))) && (type.GetInterfaces().Length == 0))
            {
                return;
            }

            // Dont use base types in comparing declarations.. someday, would be good to do a more intelligent compare (implemented interfaces removed is possibly a breaking change?)
            AppendMode restore = _mode;
            _mode &= ~AppendMode.Text;

            AppendText(" : ");

            if ((type.BaseType != null) && (type.BaseType != typeof(object)))
            {
                AppendType(type.BaseType);
                AppendText(", ");
            }

            foreach (Type intf in type.GetInterfaces())
            {
                AppendType(intf);
                AppendText(", ");
            }

            RemoveCharsFromEnd(2);

            _mode = restore;
        }
開發者ID:redoz,項目名稱:bitdiffer,代碼行數:29,代碼來源:CodeStringBuilder.cs

示例5: ExcludedTypes

 private bool ExcludedTypes(Type type)
 {
     return type != typeof(SecureSocketStyxEngine) &&
            !type.GetInterfaces().Contains(typeof(IHostConfiguration)) &&
            !type.GetInterfaces().Contains(typeof(IHandshakeNegotiator)) &&
            !type.GetInterfaces().Contains(typeof(ILogger));
 }
開發者ID:ReactiveMarkets,項目名稱:Styx,代碼行數:7,代碼來源:TinyIoCBootstrapper.cs

示例6: GetLeastGeneralCommonType

 private Type GetLeastGeneralCommonType(Type type1, Type type2)
 {
     if (type1.IsInterface)
     {
         if (type2.GetInterfaces().Contains(type1)) return type1;
         if (type2.IsInterface)
         {
             if (type1.GetInterfaces().Contains(type2)) return type2;
         }
         return typeof(object);
     }
     else
     {
         if (type2.IsInterface)
         {
             if (type1.GetInterfaces().Contains(type2)) return type2;
             return typeof(object);
         }
         Type current = type1;
         List<Type> types = new List<Type>();
         while (current != null)
         {
             types.Add(current);
             current = current.BaseType;
         }
         current = type2;
         while (!types.Contains(current))
         {
             current = current.BaseType;
         }
         return current;
     }
 }
開發者ID:FrederikP,項目名稱:NMF,代碼行數:33,代碼來源:ObservableExpressionBinder.Reflection.cs

示例7: Resolve

        public override object Resolve(Type jobType)
        {

            var instance = _container.TryGetInstance(jobType);

            // since it fails we can try to get the first interface and request from container
            if (instance == null && jobType.GetInterfaces().Count() > 0)
                instance = _container.GetInstance(jobType.GetInterfaces().FirstOrDefault());

            return instance;

        }
開發者ID:sbosell,項目名稱:Hangfire.LightInject,代碼行數:12,代碼來源:LightInjectJobActivator.cs

示例8: ActivateJob

        public override object ActivateJob(Type jobType)
        {
            // this will fail if you do self referencing job queues on a class with an interface:
            //  BackgroundJob.Enqueue(() => this.SendSms(message)); 
            var instance = _container.TryGetInstance(jobType);

            // since it fails we can try to get the first interface and request from container
            if (instance==null && jobType.GetInterfaces().Count()>0)
                instance = _container.GetInstance(jobType.GetInterfaces().FirstOrDefault());

            return instance;
            
        }
開發者ID:sbosell,項目名稱:Hangfire.LightInject,代碼行數:13,代碼來源:LightInjectJobActivator.cs

示例9: EnumerateGenericIntefaces

		private static IEnumerable<Type> EnumerateGenericIntefaces( Type source, Type genericType, bool includesOwn )
		{
			return
				( includesOwn ? new[] { source }.Concat( source.GetInterfaces() ) : source.GetInterfaces() )
				.Where( @interface =>
					@interface.GetIsGenericType()
					&& ( genericType.GetIsGenericTypeDefinition()
						? @interface.GetGenericTypeDefinition() == genericType
						: @interface == genericType
					)
				).Select( @interface => // If source is GenericTypeDefinition, type def is only valid type (i.e. has name)
					source.GetIsGenericTypeDefinition() ? @interface.GetGenericTypeDefinition() : @interface
				);
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:14,代碼來源:GenericTypeExtensions.cs

示例10: CreateTypeBuilder

        public ITypeBuilder CreateTypeBuilder(Type type)
        {
            // Check which ICollection<T> is implemented
            var interfaceType = (from @interface in new[] {type}.Concat(type.GetInterfaces())
                                 where
                                     @interface.IsGenericType &&
                                     @interface.GetGenericTypeDefinition() == typeof (ICollection<>)
                                 select @interface)
                .FirstOrDefault();

            if (interfaceType == null)
            {
                // Check if it is IEnumerable<T>
                interfaceType = (from @interface in new[] {type}.Concat(type.GetInterfaces())
                                 where
                                     @interface.IsGenericType &&
                                     @interface.GetGenericTypeDefinition() == typeof (IEnumerable<>)
                                 select @interface)
                    .FirstOrDefault();
            }
            if (interfaceType == null)
            {
                return null;
            }

            var elementType = interfaceType.GetGenericArguments()[0];

            // Determine concrete ICollection<T> to instantiate
            var listType = type.IsInterface
                               ? typeof (List<>).MakeGenericType(elementType)
                               : type;

            if (!type.IsAssignableFrom(listType))
            {
                return null;
            }

            // List must have default constructor
            if (listType.GetConstructor(Type.EmptyTypes) == null)
            {
                return null;
            }

            return
                ((ITypeBuilderFactory)
                 typeof (CollectionBuilderFactory<,>)
                     .MakeGenericType(listType, interfaceType.GetGenericArguments()[0])
                     .GetConstructor(Type.EmptyTypes)
                     .Invoke(new object[0])).CreateTypeBuilder(type);
        }
開發者ID:mikaelharsjo,項目名稱:Kiwi.Json,代碼行數:50,代碼來源:CollectionBuilderFactory.cs

示例11: GetAllServiceTypesFor

 private static IEnumerable<Type> GetAllServiceTypesFor(Type t)
 {
     if (t == null)
     {
         return new List<Type>();
     }
     List<Type> list2 = new List<Type>(t.GetInterfaces()) { t };
     List<Type> list = list2;
     foreach (Type type in t.GetInterfaces())
     {
         list.AddRange(GetAllServiceTypesFor(type));
     }
     return list;
 }
開發者ID:lozanotek,項目名稱:MvcTurbine.NServiceBus,代碼行數:14,代碼來源:WindsorObjectBuilder.cs

示例12: ConcurrentAttribute

        public ConcurrentAttribute(ConcurrentBehavior behavior, Type resolver)
        {
            this.Behavior = behavior;

            if (behavior == ConcurrentBehavior.Dynamic)
            {
                if (resolver.GetInterfaces().Length != 1 ||
                    resolver.GetInterfaces()[0] != typeof(IUserDefinedMergeResolver))
                {
                    throw new ArgumentException("User defined resolver type missing or not derived from IUserDefinedMergeResolver");
                }

                this.Resolver = resolver;
            }
        }
開發者ID:nemanjazz,項目名稱:iog,代碼行數:15,代碼來源:ConcurrentAttribute.cs

示例13: Register

 public void Register(IIocBuilder builder, Type type)
 {
     if (!type.IsAbstract && type.IsClass)
     {
         var itypes = type.GetInterfaces();
         if (itypes != null && itypes.Length > 0)
         {
             var itype = type.GetInterfaces()[0];
             if (itype.IsGenericType && itype.GetGenericTypeDefinition().Equals(typeof(IMessageMapper<>)))
             {
                 builder.RegisterType(itype, type, LifeTimeScope.Transient, type.FullName);
             }
         }
     }
 }
開發者ID:cairabbit,項目名稱:daf,代碼行數:15,代碼來源:AutoRegisterMessageMapper.cs

示例14: FindIEnumerable

        private static Type FindIEnumerable(Type seqType)
        {
            if (seqType == null || seqType == typeof(string))
                return null;

            if (seqType.IsArray)
                return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());

            if (seqType.IsGenericType)
                foreach (var arg in seqType.GetGenericArguments())
                {
                    var ienum = typeof(IEnumerable<>).MakeGenericType(arg);

                    if (ienum.IsAssignableFrom(seqType))
                        return ienum;
                }

            var ifaces = seqType.GetInterfaces();

            if (ifaces != null)
                foreach (var iface in ifaces)
                {
                    var ienum = FindIEnumerable(iface);

                    if (ienum != null)
                        return ienum;
                }

            if (seqType.BaseType != null && seqType.BaseType != typeof(object))
                return FindIEnumerable(seqType.BaseType);

            return null;
        }
開發者ID:yakonstantine,項目名稱:CrossQuery-Framework,代碼行數:33,代碼來源:TypeSystem.cs

示例15: GetEnumerableType

 private static Type GetEnumerableType(Type type)
 {
     return type.GetInterfaces()
         .Where(intType => intType.IsGenericType && intType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
         .Select(intType => intType.GetGenericArguments()[0])
         .FirstOrDefault();
 }
開發者ID:philiplaureano,項目名稱:Wire,代碼行數:7,代碼來源:FSharpListSerializerFactory.cs


注:本文中的System.Type.GetInterfaces方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。