Exemple #1
0
        DbgDotNetValue TryGetDotNetValue(ILValue value, bool canCreateValues)
        {
            if (value is IDebuggerRuntimeILValue rtValue)
            {
                return(rtValue.GetDotNetValue());
            }
            if (canCreateValues)
            {
                if (value.IsNull)
                {
                    return(new SyntheticNullValue(value.Type ?? frame.Module.AppDomain.GetReflectionAppDomain().System_Void));
                }

                object newValue;
                var    type = value.Type;
                switch (value.Kind)
                {
                case ILValueKind.Int32:
                    int v32 = ((ConstantInt32ILValue)value).Value;
                    switch (DmdType.GetTypeCode(type))
                    {
                    case TypeCode.Boolean:  newValue = v32 != 0; break;

                    case TypeCode.Char:             newValue = (char)v32; break;

                    case TypeCode.SByte:    newValue = (sbyte)v32; break;

                    case TypeCode.Byte:             newValue = (byte)v32; break;

                    case TypeCode.Int16:    newValue = (short)v32; break;

                    case TypeCode.UInt16:   newValue = (ushort)v32; break;

                    case TypeCode.Int32:    newValue = v32; break;

                    case TypeCode.UInt32:   newValue = (uint)v32; break;

                    default:                                newValue = null; break;
                    }
                    break;

                case ILValueKind.Int64:
                    long v64 = ((ConstantInt64ILValue)value).Value;
                    switch (DmdType.GetTypeCode(type))
                    {
                    case TypeCode.Int64:    newValue = v64; break;

                    case TypeCode.UInt64:   newValue = (ulong)v64; break;

                    default:                                newValue = null; break;
                    }
                    break;

                case ILValueKind.Float:
                    double r8 = ((ConstantFloatILValue)value).Value;
                    switch (DmdType.GetTypeCode(type))
                    {
                    case TypeCode.Single:   newValue = (float)r8; break;

                    case TypeCode.Double:   newValue = r8; break;

                    default:                                newValue = null; break;
                    }
                    break;

                case ILValueKind.NativeInt:
                    if (value is ConstantNativeIntILValue ci)
                    {
                        if (type == type.AppDomain.System_IntPtr)
                        {
                            if (PointerSize == 4)
                            {
                                newValue = new IntPtr(ci.Value32);
                            }
                            else
                            {
                                newValue = new IntPtr(ci.Value64);
                            }
                        }
                        else if (type == type.AppDomain.System_UIntPtr)
                        {
                            if (PointerSize == 4)
                            {
                                newValue = new UIntPtr(ci.UnsignedValue32);
                            }
                            else
                            {
                                newValue = new UIntPtr(ci.UnsignedValue64);
                            }
                        }
                        else
                        {
                            newValue = null;
                        }
                    }
                    else
                    {
                        newValue = null;
                    }
                    break;

                case ILValueKind.Type:
                    if (value is ConstantStringILValueImpl sv)
                    {
                        newValue = sv.Value;
                    }
                    else
                    {
                        newValue = null;
                    }
                    break;

                default:
                    newValue = null;
                    break;
                }
                if (newValue != null)
                {
                    return(RecordValue(runtime.CreateValue(context, frame, newValue, cancellationToken)));
                }
            }
            return(null);
        }