本文整理汇总了C#中IKVM.Reflection.Type.IsSubclassOf方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsSubclassOf方法的具体用法?C# Type.IsSubclassOf怎么用?C# Type.IsSubclassOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.IsSubclassOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSubclassOf
internal static bool IsSubclassOf(Type type, Type baseClass)
{
#if WINRT
return type.GetTypeInfo().IsSubclassOf(baseClass);
#else
return type.IsSubclassOf(baseClass);
#endif
}
示例2: IsDelegate
private static bool IsDelegate(Type type)
{
// HACK non-public delegates do not get the special treatment (because they are likely to refer to
// non-public types in the arg list and they're not really useful anyway)
// NOTE we don't have to check in what assembly the type lives, because this is a DotNetTypeWrapper,
// we know that it is a different assembly.
if (!type.IsAbstract && type.IsSubclassOf(Types.MulticastDelegate) && type.IsVisible)
{
MethodInfo invoke = type.GetMethod("Invoke");
if (invoke != null)
{
foreach (ParameterInfo p in invoke.GetParameters())
{
// we don't support delegates with pointer parameters
if (IsPointerType(p.ParameterType))
{
return false;
}
}
return !IsPointerType(invoke.ReturnType);
}
}
return false;
}
示例3: IsAttribute
private static bool IsAttribute(Type type)
{
if (!type.IsAbstract && type.IsSubclassOf(Types.Attribute) && type.IsVisible)
{
//
// Based on the number of constructors and their arguments, we distinguish several types
// of attributes:
// | def ctor | single 1-arg ctor
// -----------------------------------------------------------------
// complex only (i.e. Annotation{N}) | |
// all optional fields/properties | X |
// required "value" | | X
// optional "value" | X | X
// -----------------------------------------------------------------
//
// TODO currently we don't support "complex only" attributes.
//
ConstructorInfo defCtor;
ConstructorInfo singleOneArgCtor;
AttributeAnnotationTypeWrapper.GetConstructors(type, out defCtor, out singleOneArgCtor);
return defCtor != null || singleOneArgCtor != null;
}
return false;
}
示例4: GetExplicit
public static Conversion GetExplicit(Operand op, Type to, bool onlyStandard, ITypeMapper typeMapper)
{
// try implicit
Conversion conv = GetImplicit(op, to, onlyStandard, typeMapper);
if (conv.IsValid)
return conv;
Type from = Operand.GetType(op, typeMapper);
Type fromUnderlying = Helpers.GetNullableUnderlyingType(@from);
if (fromUnderlying == to)
return new UnwrapNullable(typeMapper);
Type toUnderlying = Helpers.GetNullableUnderlyingType(to);
if (toUnderlying != null && fromUnderlying != null)
{
var c = GetExplicit(new FakeTypedOperand(fromUnderlying), toUnderlying, onlyStandard, typeMapper);
if (c.IsValid) return new ConvertNullable(typeMapper, c);
}
// section 6.3.2 - Standard explicit conversions
if (onlyStandard)
{
if (from == null || !GetImplicit(to, @from, true, typeMapper).IsValid)
return new Invalid(typeMapper);
}
TypeCode tcFrom = Type.GetTypeCode(from);
TypeCode tcTo = Type.GetTypeCode(to);
byte ct = _convTable[(int)tcFrom][(int)tcTo];
// section 6.2.1 - Explicit numeric conversions, 6.2.2 - Explicit enumeration conversions
if ((from.IsPrimitive || from.IsEnum || Helpers.AreTypesEqual(from, typeof(decimal), typeMapper)) && (to.IsPrimitive || to.IsEnum || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper)))
{
if (ct == D)
return new Direct(typeMapper); // this can happen for conversions involving enum-s
if (ct <= E)
{
if (Helpers.AreTypesEqual(from, typeof(decimal), typeMapper) || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper))
// decimal is handled as user-defined conversion, but as it is a standard one, always enable UDC processing
onlyStandard = false;
else
return new Primitive(typeMapper);
}
}
// section 6.2.5 - User-defined explicit conversions (details in section 6.4.4)
if (!(onlyStandard || Helpers.AreTypesEqual(from, typeof(object), typeMapper) || Helpers.AreTypesEqual(to, typeof(object), typeMapper) || from.IsInterface || to.IsInterface ||
to.IsSubclassOf(from) || from.IsSubclassOf(to)))
{
List<UserDefined> candidates = null;
FindCandidates(ref candidates, FindExplicitMethods(from, to, typeMapper), op, to, GetExplicit, typeMapper);
if (candidates != null)
{
if (candidates.Count == 1)
return candidates[0];
return UserDefined.FindExplicit(candidates, @from, to, typeMapper);
}
}
// section 6.2.3 - Explicit reference conversions, 6.2.4 - Unboxing conversions
// TODO: not really according to spec, but mostly works
if (!from.IsValueType && from.IsAssignableFrom(to))
{
if (to.IsValueType)
return new Unboxing(typeMapper);
else
return new Cast(typeMapper);
}
return new Invalid(typeMapper);
}
示例5: GetImplicit
//.........这里部分代码省略.........
if (to.GetArrayRank() == from.GetArrayRank())
{
if (to.GetElementType().Equals(from.GetElementType()))
return new Direct(typeMapper);
}
}
TypeCode tcFrom = Type.GetTypeCode(from);
TypeCode tcTo = Type.GetTypeCode(to);
byte ct = _convTable[(int)tcFrom][(int)tcTo];
// section 6.1.2 - Implicit numeric conversions
if (from != null && (from.IsPrimitive || Helpers.AreTypesEqual(from, typeof(decimal), typeMapper)) && (to.IsPrimitive || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper)))
{
if (ct <= I)
{
if (Helpers.AreTypesEqual(from, typeof(decimal), typeMapper) || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper))
// decimal is handled as user-defined conversion, but as it is a standard one, always enable UDC processing
onlyStandard = false;
else
return new Primitive(typeMapper);
}
}
IntLiteral intLit = op as IntLiteral;
// section 6.1.3 - Implicit enumeration conversions
if (!onlyStandard && to.IsEnum && (object)intLit != null && intLit.Value == 0)
return new Primitive(typeMapper);
// section 6.1.4 - Implicit reference conversions
if ((from == null || !from.IsValueType) && !to.IsValueType)
{
if (from == null) // from the null type to any reference type
return new Direct(typeMapper);
if (to.IsAssignableFrom(from)) // the rest
return new Direct(typeMapper);
}
if (from == null) // no other conversion from null type is possible
return new Invalid(typeMapper);
// section 6.1.5 - Boxing conversions
if (from.IsValueType)
{
if (to.IsAssignableFrom(from))
return new Boxing(typeMapper);
}
// section 6.1.6 - Implicit constant expression conversions
if ((object)intLit != null && Helpers.AreTypesEqual(from, typeof(int), typeMapper) && to.IsPrimitive)
{
int val = intLit.Value;
switch (tcTo)
{
case TypeCode.SByte:
if (val >= sbyte.MinValue && val <= sbyte.MaxValue)
return new Direct(typeMapper);
break;
case TypeCode.Byte:
if (val >= byte.MinValue && val <= byte.MaxValue)
return new Direct(typeMapper);
break;
case TypeCode.Int16:
if (val >= short.MinValue && val <= short.MaxValue)
return new Direct(typeMapper);
break;
case TypeCode.UInt16:
if (val >= ushort.MinValue && val <= ushort.MaxValue)
return new Direct(typeMapper);
break;
case TypeCode.UInt32:
if (val >= 0)
return new Direct(typeMapper);
break;
case TypeCode.UInt64:
if (val >= 0)
return new Direct(typeMapper);
break;
}
}
// section 6.1.7 - User-defined implicit conversions (details in section 6.4.3)
if (onlyStandard || Helpers.AreTypesEqual(from, typeof(object), typeMapper) || Helpers.AreTypesEqual(to, typeof(object), typeMapper) || from.IsInterface || to.IsInterface ||
to.IsSubclassOf(from) || from.IsSubclassOf(to))
return new Invalid(typeMapper); // skip not-permitted conversion attempts (section 6.4.1)
List<UserDefined> candidates = null;
FindCandidates(ref candidates, FindImplicitMethods(from, to, typeMapper), op, to, GetImplicit, typeMapper);
if (candidates == null)
return new Invalid(typeMapper);
if (candidates.Count == 1)
return candidates[0];
return UserDefined.FindImplicit(candidates, @from, to, typeMapper);
}
示例6: GetTypeKind
string GetTypeKind (Type t)
{
if (t.IsEnum)
return "enum";
if (t.IsClass) {
if (t.IsSubclassOf (type_multicast_delegate))
return "delegate";
else
return "class";
}
if (t.IsInterface)
return "interface";
if (t.IsValueType)
return "struct";
return "class";
}