本文整理汇总了C#中IKVM.Reflection.Type.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Equals方法的具体用法?C# Type.Equals怎么用?C# Type.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImplicit
// the sections mentioned in comments of this method are from C# specification v1.2
public static Conversion GetImplicit(Operand op, Type to, bool onlyStandard, ITypeMapper typeMapper)
{
Type from = Operand.GetType(op, typeMapper);
Type toUnderlying = Helpers.GetNullableUnderlyingType(to);
if (to.Equals(from))
return new Direct(typeMapper);
Type fromUnderlying = Helpers.GetNullableUnderlyingType(@from);
if (toUnderlying != null)
{
if (fromUnderlying != null)
{
Conversion c = GetImplicit(new FakeTypedOperand(fromUnderlying), toUnderlying, onlyStandard, typeMapper);
if (c.IsValid) return new ConvertNullable(typeMapper, c);
}
else
{
Conversion c = GetImplicit(op, toUnderlying, onlyStandard, typeMapper);
if (c.IsValid) return new WrapNullable(typeMapper, c);
}
}
// required for arrays created from TypeBuilder-s
if (from != null && to.IsArray && from.IsArray)
{
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;
//.........这里部分代码省略.........
示例2: GetDirect
public static Conversion GetDirect(Type @from, Type to, ITypeMapper typeMapper)
{
if (to.Equals(from))
return new Direct(typeMapper);
return new Invalid(typeMapper);
}