当前位置: 首页>>代码示例>>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;未经允许,请勿转载。