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


C# Type.IsAssignableFrom方法代码示例

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


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

示例1: Find

		public object Find (Type type)
		{
			foreach (object value in List)
				if (type.IsAssignableFrom (value.GetType ()))
					return value;
			return null;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:ServiceDescriptionFormatExtensionCollection.cs

示例2: CanConvert

 public override bool CanConvert(Type objectType)
 {
     if (objectType == null)
     {
         throw Error.ArgumentNull("objectType");
     }
     return objectType.IsAssignableFrom(typeof(ISelectExpandWrapper));
 }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:8,代码来源:SelectExpandWrapperConverter.cs

示例3: CanConvert

 public override bool CanConvert(Type objectType)
 {
     if (objectType.IsAssignableFrom(typeof(IDictionaryConvertible)))
     {
         return true;
     }
     return false;
 }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:8,代码来源:SelectExpandWrapperConverter.cs

示例4: Cancellation_TriggersCancellationTokenSource

    public async void Cancellation_TriggersCancellationTokenSource(Type messageTypeToCancelOn)
    {
        var testCase = Mocks.ExecutionErrorTestCase("This is my error message");
        var messageBus = new SpyMessageBus(msg => !(messageTypeToCancelOn.IsAssignableFrom(msg.GetType())));
        var runner = new ExecutionErrorTestCaseRunner(testCase, messageBus, aggregator, tokenSource);

        await runner.RunAsync();

        Assert.True(tokenSource.IsCancellationRequested);
    }
开发者ID:Xarlot,项目名称:xunit,代码行数:10,代码来源:ExecutionErrorTestCaseRunnerTests.cs

示例5: FindContainer

 private Control FindContainer(MobileControl mc, Type containerType)
 {
     for (Control control = mc; control != null; control = control.Parent)
     {
         if (containerType.IsAssignableFrom(control.GetType()))
         {
             return control;
         }
     }
     return null;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:11,代码来源:FormConverter.cs

示例6: FindSuperviewOfType

    public static UIView FindSuperviewOfType(this UIView view, UIView stopAt, Type type)
    {
        if (view.Superview != null) {
            if (type.IsAssignableFrom(view.Superview.GetType()))
                return view.Superview;

            if (view.Superview != stopAt)
                return view.Superview.FindSuperviewOfType(stopAt, type);
        }

        return null;
    }
开发者ID:fdibartolo,项目名称:boletamovil,代码行数:12,代码来源:ViewExtensions.cs

示例7: GetCustomAttributes

 public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
 {
     if (inherit)
         throw new NotSupportedException();
     var attrs = PrimGetCustomAttributes();
     var n = 0;
     for (var i = 0; i < attrs.Length; i++)
     {
         if (attributeType.IsAssignableFrom(attrs[i].GetType()))
             n++;
     }
     if (n == attrs.Length)
         return attrs;
     var res = new object[n];
     n = 0;
     for (var i = 0; i < attrs.Length; i++)
     {
         if (attributeType.IsAssignableFrom(attrs[i].GetType()))
             res[n++] = attrs[i];
     }
     return res;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:22,代码来源:MemberInfo.cs

示例8: IsImplementInterface

 /// <summary>
 /// 指示当前类型是否实现指定的接口类型。
 /// </summary>
 /// <param name="type">当前类型。</param>
 /// <param name="interfaceType">接口类型。</param>
 /// <returns>指示是否实现了接口。</returns>
 /// <exception cref="System.ArgumentException"><c>interfaceType</c> 不是接口类型。</exception>
 /// <exception cref="System.ArgumentNullException"><c>type</c> 或 <c>interface</c> 为 null。</exception>
 public static bool IsImplementInterface(this Type type, Type interfaceType)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (interfaceType == null)
     {
         throw new ArgumentNullException("interfaceType");
     }
     if (interfaceType.IsInterface == false)
     {
         throw new ArgumentException("interfaceType 不是接口类型。");
     }
     return interfaceType.IsAssignableFrom(type);
 }
开发者ID:h82258652,项目名称:Common,代码行数:24,代码来源:TypeExtension.cs

示例9: while

	// Get the first object on the context stack of a particular type.
	public Object this[Type type]
			{
				get
				{
					int posn = size - 1;
					while(posn >= 0)
					{
						if(type.IsAssignableFrom(stack[posn].GetType()))
						{
							return stack[posn];
						}
						--posn;
					}
					return null;
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:17,代码来源:ContextStack.cs

示例10: Find

        public override IEnumerable<ModelItem> Find(ModelItem startingItem, Type type)
        {
            if (startingItem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("startingItem"));
            }

            if (type == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("type"));
            }
            Fx.Assert(!type.IsValueType, "hmm why would some one search for modelitems for value types?");
            return ModelTreeManager.Find(startingItem, delegate(ModelItem modelItem)
            {
                return type.IsAssignableFrom(modelItem.ItemType);
            }, false);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:17,代码来源:ModelServiceImpl.cs

示例11: AreAssignable

 //CONFORMING
 internal static bool AreAssignable(Type dest, Type src) {
     if (dest == src) {
         return true;
     }
     if (dest.IsAssignableFrom(src)) {
         return true;
     }
     if (dest.IsArray && src.IsArray && dest.GetArrayRank() == src.GetArrayRank() && AreReferenceAssignable(dest.GetElementType(), src.GetElementType())) {
         return true;
     }
     if (src.IsArray && dest.IsGenericType &&
         (dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IEnumerable<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IList<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.ICollection<>))
         && dest.GetGenericArguments()[0] == src.GetElementType()) {
         return true;
     }
     return false;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:20,代码来源:TypeUtils.cs

示例12: IsTypeCompatible

        public static bool IsTypeCompatible(Type childObjectType, Type parentObjectType)
        {
            if (!parentObjectType.IsGenericTypeDefinition)
            {
                return parentObjectType.IsAssignableFrom(childObjectType);
            }
            else if (parentObjectType.IsInterface)
            {
                Type[] interfaceTypes = childObjectType.GetInterfaces();
                foreach (Type interfaceType in interfaceTypes)
                {
                    if (interfaceType.IsGenericType)
                    {
                        if (interfaceType.GetGenericTypeDefinition() == parentObjectType)
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            else
            {
                Type current = childObjectType;
                while (current != null)
                {
                    if (current.IsGenericType)
                    {
                        if (current.GetGenericTypeDefinition() == parentObjectType)
                        {
                            return true;
                        }
                    }

                    current = current.BaseType;
                }

                return false;
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:41,代码来源:TypeUtilities.cs

示例13: CanDbConvert

 private static bool CanDbConvert(Type from, Type to) {
     from = System.Data.Linq.SqlClient.TypeSystem.GetNonNullableType(from);
     to = System.Data.Linq.SqlClient.TypeSystem.GetNonNullableType(to);
     if (from == to)
         return true;
     if (to.IsAssignableFrom(from))
         return true;
     var tcTo = Type.GetTypeCode(to);
     var tcFrom = Type.GetTypeCode(from);
     switch (tcTo) {
         case TypeCode.Int16: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte;
         case TypeCode.Int32: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16;
         case TypeCode.Int64: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16 || tcFrom == TypeCode.Int32 || tcFrom==TypeCode.UInt32;
         case TypeCode.UInt16: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte;
         case TypeCode.UInt32: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16;
         case TypeCode.UInt64: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16 || tcFrom == TypeCode.Int32 || tcFrom == TypeCode.UInt32;
         case TypeCode.Double: return tcFrom == TypeCode.Single;
         case TypeCode.Decimal: return tcFrom == TypeCode.Single || tcFrom == TypeCode.Double;
     }
     return false;
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:21,代码来源:SqlRetyper.cs

示例14: CanDbConvert

		private static bool CanDbConvert(Type from, Type to)
		{
			@from = TypeSystem.GetNonNullableType(@from);
			to = TypeSystem.GetNonNullableType(to);
			if(@from == to)
				return true;
			if(to.IsAssignableFrom(@from))
				return true;
			var tcTo = Type.GetTypeCode(to);
			var tcFrom = Type.GetTypeCode(@from);
			switch(tcTo)
			{
#warning [FB] REFACTOR SQL Server specific
				case TypeCode.Int16: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte;
				case TypeCode.Int32: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16;
				case TypeCode.Int64: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16 || tcFrom == TypeCode.Int32 || tcFrom == TypeCode.UInt32;
				case TypeCode.UInt16: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte;
				case TypeCode.UInt32: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16;
				case TypeCode.UInt64: return tcFrom == TypeCode.Byte || tcFrom == TypeCode.SByte || tcFrom == TypeCode.Int16 || tcFrom == TypeCode.UInt16 || tcFrom == TypeCode.Int32 || tcFrom == TypeCode.UInt32;
				case TypeCode.Double: return tcFrom == TypeCode.Single;
				case TypeCode.Decimal: return tcFrom == TypeCode.Single || tcFrom == TypeCode.Double;
			}
			return false;
		}
开发者ID:modulexcite,项目名称:LinqToSQL2,代码行数:24,代码来源:TypeCorrector.cs

示例15: IsDirectlyImplementedInterface

		// This returns true if this type directly (i.e. not inherited from the base class) implements the interface.
		// Note that a complicating factor is that the interface itself can be implemented by an interface that extends it.
		private bool IsDirectlyImplementedInterface(Type interfaceType)
		{
			foreach (Type iface in __GetDeclaredInterfaces())
			{
				if (interfaceType.IsAssignableFrom(iface))
				{
					return true;
				}
			}
			return false;
		}
开发者ID:ngraziano,项目名称:mono,代码行数:13,代码来源:Type.cs


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