/// <summary> /// Returns the internal pointer to a boxed instance's value. DOESN'T pin the reference. /// </summary> /// <param name="obj">The boxed instance.</param> /// <returns>The internal pointer.</returns> public static unsafe IntPtr GetDataPointer(ValueType obj) { TypedReference tr; TypedReferenceTools.MakeTypedReference(&tr, obj); return(tr.ToPointer()); }
public static unsafe TField GetValue <TField>(this FieldInfo fi, object obj) { TypedReference tr; TypedReferenceTools.MakeTypedReference(&tr, obj, fi); return(__refvalue(tr, TField)); }
public static unsafe void SetValue <TField>(this FieldInfo fi, object obj, TField value) { TypedReference tr; TypedReferenceTools.MakeTypedReference(&tr, obj, fi); __refvalue(tr, TField) = value; }
/// <summary> /// Converts an enum value to a primitive value. /// </summary> /// <param name="enm">The enum value to convert.</param> /// <returns>The converted primitive value.</returns> public static unsafe TValue ToValue <TEnum, TValue>(TEnum enm) where TEnum : struct, TEnumBase where TValue : struct, IComparable, IFormattable, IComparable <TValue>, IEquatable <TValue> { var tr = __makeref(enm); TypedReferenceTools.ChangeType(&tr, typeof(TValue)); return(__refvalue(tr, TValue)); }
public static unsafe ValueType Box(ArgIterator arg) { ValueType empty = (ValueType)FormatterServices.GetUninitializedObject(typeof(ArgIterator)); TypedReference innerRef; TypedReferenceTools.MakeTypedReference(&innerRef, empty); __refvalue(innerRef, ArgIterator) = arg; return(empty); }
public static unsafe ValueType Box(RuntimeArgumentHandle arg) { ValueType empty = (ValueType)FormatterServices.GetUninitializedObject(typeof(RuntimeArgumentHandle)); TypedReference innerRef; TypedReferenceTools.MakeTypedReference(&innerRef, empty); __refvalue(innerRef, RuntimeArgumentHandle) = arg; return(empty); }
public static unsafe ValueType Box(TypedReference arg) { ValueType empty = (ValueType)FormatterServices.GetUninitializedObject(typeof(TypedReference)); TypedReference innerRef; //TypedReference to a TypedReference... TypedReferenceTools.MakeTypedReference(&innerRef, empty); __refvalue(innerRef, TypedReference) = arg; return(empty); }
public static unsafe int GetOffset(this FieldInfo field) { return(InteropTools.Pin( FormatterServices.GetUninitializedObject(field.DeclaringType), delegate(object inst) { TypedReference tr0, tr1; TypedReferenceTools.MakeTypedReference(&tr0, inst); TypedReferenceTools.MakeTypedReference(&tr1, inst, field); byte *p0 = (byte *)tr0.ToPointer(); byte *p1 = (byte *)tr1.ToPointer(); return (int)(p1 - p0); } )); }
public static TRet MakeReference <TRet>(object target, FieldInfo[] fields, Func <SafeReference, TRet> func) { return(TypedReferenceTools.MakeTypedReference(target, fields, tr => Create(tr, func))); }
public static void MakeReference(object target, FieldInfo[] fields, Action <SafeReference> act) { TypedReferenceTools.MakeTypedReference(target, fields, tr => Create(tr, act)); }
public TRet GetReference <TRet>(Func <SafeReference, TRet> func) { return(TypedReferenceTools.MakeTypedReference(Target, new[] { Field }, tr => SafeReference.Create(tr, func))); }
public TRet GetReference <TRet>(TypedReferenceTools.TypedRefFunc <TRet> func) { return(TypedReferenceTools.MakeTypedReference(Target, new[] { Field }, func)); }
public TRet GetReference <TRet>(TypedReferenceTools.TypedRefFunc <TRet> func) { return(TypedReferenceTools.MakeTypedReference(Instance, func)); }