本文整理汇总了C#中MosaType.GetEnumUnderlyingType方法的典型用法代码示例。如果您正苦于以下问题:C# MosaType.GetEnumUnderlyingType方法的具体用法?C# MosaType.GetEnumUnderlyingType怎么用?C# MosaType.GetEnumUnderlyingType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MosaType
的用法示例。
在下文中一共展示了MosaType.GetEnumUnderlyingType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeArgumentSize
private int ComputeArgumentSize(MosaType type, object value)
{
if (type.IsEnum)
type = type.GetEnumUnderlyingType();
switch (type.TypeCode)
{
// 1 byte
case MosaTypeCode.Boolean:
case MosaTypeCode.U1:
case MosaTypeCode.I1:
return 1;
// 2 bytes
case MosaTypeCode.Char:
case MosaTypeCode.U2:
case MosaTypeCode.I2:
return 2;
// 4 bytes
case MosaTypeCode.U4:
case MosaTypeCode.I4:
case MosaTypeCode.R4:
return 4;
// 8 bytes
case MosaTypeCode.U8:
case MosaTypeCode.I8:
case MosaTypeCode.R8:
return 8;
// SZArray
case MosaTypeCode.SZArray:
Debug.Assert(value is MosaCustomAttribute.Argument[]);
var arr = (MosaCustomAttribute.Argument[])value;
int size = 0;
foreach (var elem in arr)
size += ComputeArgumentSize(elem.Type, elem.Value);
return size;
// String
case MosaTypeCode.String:
return TypeLayout.NativePointerSize;
default:
if (type.FullName == "System.Type")
{
return TypeLayout.NativePointerSize;
}
else
throw new NotSupportedException();
}
}
示例2: WriteArgument
private void WriteArgument(EndianAwareBinaryWriter writer, LinkerSymbol symbol, MosaType type, object value)
{
if (type.IsEnum)
type = type.GetEnumUnderlyingType();
switch (type.TypeCode)
{
// 1 byte
case MosaTypeCode.Boolean:
writer.Write((bool)value);
break;
case MosaTypeCode.U1:
writer.Write((byte)value);
break;
case MosaTypeCode.I1:
writer.Write((sbyte)value);
break;
// 2 bytes
case MosaTypeCode.Char:
writer.Write((char)value);
break;
case MosaTypeCode.U2:
writer.Write((ushort)value);
break;
case MosaTypeCode.I2:
writer.Write((short)value);
break;
// 4 bytes
case MosaTypeCode.U4:
writer.Write((uint)value);
break;
case MosaTypeCode.I4:
writer.Write((int)value);
break;
case MosaTypeCode.R4:
writer.Write((float)value);
break;
// 8 bytes
case MosaTypeCode.U8:
writer.Write((ulong)value);
break;
case MosaTypeCode.I8:
writer.Write((long)value);
break;
case MosaTypeCode.R8:
writer.Write((double)value);
break;
// SZArray
case MosaTypeCode.SZArray:
Debug.Assert(value is MosaCustomAttribute.Argument[]);
var arr = (MosaCustomAttribute.Argument[])value;
writer.Write(arr.Length, TypeLayout.NativePointerSize);
foreach (var elem in arr)
WriteArgument(writer, symbol, elem.Type, elem.Value);
break;
// String
case MosaTypeCode.String:
// Since strings are immutable, make it an object that we can just use
var str = (string)value;
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, symbol, (int)writer.Position, 0, "System.String" + Metadata.TypeDefinition, SectionKind.ROData, 0);
writer.WriteZeroBytes(TypeLayout.NativePointerSize * 2);
writer.Write(str.Length, TypeLayout.NativePointerSize);
writer.Write(System.Text.Encoding.Unicode.GetBytes(str));
break;
default:
if (type.FullName == "System.Type")
{
var valueType = (MosaType)value;
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, symbol, (int)writer.Position, 0, valueType.FullName + Metadata.TypeDefinition, SectionKind.ROData, 0);
writer.WriteZeroBytes(TypeLayout.NativePointerSize);
}
else
throw new NotSupportedException();
break;
}
}