internal static unsafe bool InternalEqualTypes(object a, object b) { if (a.GetType() == b.GetType()) { return(true); } MethodTable *pMTa = RuntimeHelpers.GetMethodTable(a); MethodTable *pMTb = RuntimeHelpers.GetMethodTable(b); bool ret; // only use QCall to check the type equivalence scenario if (pMTa->HasTypeEquivalence && pMTb->HasTypeEquivalence) { ret = RuntimeHelpers.AreTypesEquivalent(pMTa, pMTb); } else { ret = false; } GC.KeepAlive(a); GC.KeepAlive(b); return(ret); }
private unsafe CorElementType InternalGetCorElementType() { CorElementType elementType = InternalGetCorElementType(RuntimeHelpers.GetMethodTable(this)); GC.KeepAlive(this); return(elementType); }
public override unsafe bool Equals([NotNullWhen(true)] object?obj) { if (null == obj) { return(false); } if (GetType() != obj.GetType()) { return(false); } // if there are no GC references in this object we can avoid reflection // and do a fast memcmp if (CanCompareBits(this)) { return(SpanHelpers.SequenceEqual( ref RuntimeHelpers.GetRawData(this), ref RuntimeHelpers.GetRawData(obj), RuntimeHelpers.GetMethodTable(this)->GetNumInstanceFieldBytes())); } FieldInfo[] thisFields = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int i = 0; i < thisFields.Length; i++) { object?thisResult = thisFields[i].GetValue(this); object?thatResult = thisFields[i].GetValue(obj); if (thisResult == null) { if (thatResult != null) { return(false); } } else if (!thisResult.Equals(thatResult)) { return(false); } } return(true); }
// Copies length elements from sourceArray, starting at index 0, to // destinationArray, starting at index 0. // public static unsafe void Copy(Array sourceArray, Array destinationArray, int length) { if (sourceArray == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.sourceArray); } if (destinationArray == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.destinationArray); } MethodTable *pMT = RuntimeHelpers.GetMethodTable(sourceArray); if (pMT == RuntimeHelpers.GetMethodTable(destinationArray) && !pMT->IsMultiDimensionalArray && (uint)length <= sourceArray.NativeLength && (uint)length <= destinationArray.NativeLength) { nuint byteCount = (uint)length * (nuint)pMT->ComponentSize; ref byte src = ref Unsafe.As <RawArrayData>(sourceArray).Data; ref byte dst = ref Unsafe.As <RawArrayData>(destinationArray).Data;
// Note: Callers are required to keep obj alive internal static unsafe bool IsPinnable(object?obj) => (obj == null) || !RuntimeHelpers.GetMethodTable(obj)->ContainsGCPointers;
public static ref byte GetArrayDataReference(Array array) { // If needed, we can save one or two instructions per call by marking this method as intrinsic and asking the JIT // to special-case arrays of known type and dimension. // See comment on RawArrayData (in RuntimeHelpers.CoreCLR.cs) for details return(ref Unsafe.AddByteOffset(ref Unsafe.As <RawData>(array).Data, (nuint)RuntimeHelpers.GetMethodTable(array)->BaseSize - (nuint)(2 * sizeof(IntPtr)))); }