示例#1
0
 public static bool AreTypesEquivalent(IClrObject self, IClrObject other)
 {
     if (self.GetType() != other.GetType())
     {
         return(false);
     }
     return(ClrTypeEqualityComparer.Instance.Equals(self.Type, other.Type));
 }
示例#2
0
 public static T CastAs <T>(this IClrObject obj)
 {
     if (Equals(default(T), obj))
     {
         return(default(T));
     }
     if (TryCastAs(obj, out T result))
     {
         return(result);
     }
     throw new InvalidCastException($"This object is a {obj.GetType().Name} and cannot be accessed as a {typeof(T).Name}");
 }
示例#3
0
        /// <summary>
        /// Two objects at the same address in the same heap should be of the same type.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public static bool AssertTypesEquivalent(IClrObject self, IClrObject other)
        {
            if (!ReferenceEquals(self.Type.Heap, other.Type.Heap))
            {
                return(false);
            }

            Debug.Assert(ClrTypeEqualityComparer.Instance.Equals(self.Type, other.Type),
                         "Mismatched ClrTypes at the same address.",
                         "This: {0}\nOther: {1}",
                         self.Type,
                         other.Type);

            if (self.GetType() == other.GetType())
            {
                return(true);
            }

            Debug.Fail("Mismatched IClrObject types at the same address.", $"This: {self.GetType()}\nOther: {other.GetType()}");
            return(false);
        }