Пример #1
0
        /// <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());
        }
Пример #2
0
        public static unsafe TField GetValue <TField>(this FieldInfo fi, object obj)
        {
            TypedReference tr;

            TypedReferenceTools.MakeTypedReference(&tr, obj, fi);
            return(__refvalue(tr, TField));
        }
Пример #3
0
        public static unsafe void SetValue <TField>(this FieldInfo fi, object obj, TField value)
        {
            TypedReference tr;

            TypedReferenceTools.MakeTypedReference(&tr, obj, fi);
            __refvalue(tr, TField) = value;
        }
Пример #4
0
        /// <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));
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 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);
     }
                ));
 }
Пример #9
0
 public static TRet MakeReference <TRet>(object target, FieldInfo[] fields, Func <SafeReference, TRet> func)
 {
     return(TypedReferenceTools.MakeTypedReference(target, fields, tr => Create(tr, func)));
 }
Пример #10
0
 public static void MakeReference(object target, FieldInfo[] fields, Action <SafeReference> act)
 {
     TypedReferenceTools.MakeTypedReference(target, fields, tr => Create(tr, act));
 }
Пример #11
0
 public TRet GetReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(TypedReferenceTools.MakeTypedReference(Target, new[] { Field }, tr => SafeReference.Create(tr, func)));
 }
Пример #12
0
 public TRet GetReference <TRet>(TypedReferenceTools.TypedRefFunc <TRet> func)
 {
     return(TypedReferenceTools.MakeTypedReference(Target, new[] { Field }, func));
 }
Пример #13
0
 public TRet GetReference <TRet>(TypedReferenceTools.TypedRefFunc <TRet> func)
 {
     return(TypedReferenceTools.MakeTypedReference(Instance, func));
 }