public static object GetSimpleValue(ClrDynamic obj) { if (obj.IsNull()) { return(null); } ClrType type = obj.Type; ClrHeap heap = type.Heap; if (type.IsPrimitive || type.IsString) { return(type.GetValue(obj.Address)); } ulong address = obj.IsInterior ? obj.Address : obj.Address + (ulong)heap.PointerSize; switch (type.Name) { case GuidTypeName: { byte[] buffer = ReadBuffer(heap, address, 16); return(new Guid(buffer)); } case TimeSpanTypeName: { byte[] buffer = ReadBuffer(heap, address, 8); long ticks = BitConverter.ToInt64(buffer, 0); return(new TimeSpan(ticks)); } case DateTimeTypeName: { byte[] buffer = ReadBuffer(heap, address, 8); ulong dateData = BitConverter.ToUInt64(buffer, 0); return(GetDateTime(dateData)); } case IPAddressTypeName: { return(GetIPAddress(obj)); } } throw new InvalidOperationException(string.Format("SimpleValue not available for type '{0}'", type.Name)); }
private static IPAddress GetIPAddress(ClrDynamic ipAddress) { const int AddressFamilyInterNetworkV6 = 23; const int IPv4AddressBytes = 4; const int IPv6AddressBytes = 16; const int NumberOfLabels = IPv6AddressBytes / 2; byte[] bytes; int family = (int)ipAddress["m_Family"].SimpleValue; if (family == AddressFamilyInterNetworkV6) { bytes = new byte[IPv6AddressBytes]; int j = 0; var numbers = ipAddress["m_Numbers"]; for (int i = 0; i < NumberOfLabels; i++) { ushort number = (ushort)numbers[i].SimpleValue; bytes[j++] = (byte)((number >> 8) & 0xFF); bytes[j++] = (byte)(number & 0xFF); } } else { long address = (long)ipAddress["m_Address"].SimpleValue; bytes = new byte[IPv4AddressBytes]; bytes[0] = (byte)(address); bytes[1] = (byte)(address >> 8); bytes[2] = (byte)(address >> 16); bytes[3] = (byte)(address >> 24); } return(new IPAddress(bytes)); }
public ClrObjectWrapper(ClrDynamic item) { Object = item; }
public static ClrObjectWrapper Wrap(this ClrDynamic item) { return(new ClrObjectWrapper(item)); }
public static ClrDynamic DowncastToBase(this ClrDynamic clrObject) { return(clrObject?.Type?.BaseType != null ? new ClrDynamic(clrObject.Address, clrObject.Type.BaseType) : null); }
public IEnumerable <ClrDynamic> GetReferenceBy(ClrDynamic o) { return(m_referenceMap.GetReferenceBy(o)); }