本文整理汇总了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;
}
示例2: CanConvert
public override bool CanConvert(Type objectType)
{
if (objectType == null)
{
throw Error.ArgumentNull("objectType");
}
return objectType.IsAssignableFrom(typeof(ISelectExpandWrapper));
}
示例3: CanConvert
public override bool CanConvert(Type objectType)
{
if (objectType.IsAssignableFrom(typeof(IDictionaryConvertible)))
{
return true;
}
return false;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}