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


C# MosaType.GetEnumUnderlyingType方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:52,代码来源:MetadataStage.cs

示例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;
            }
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:90,代码来源:MetadataStage.cs


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