示例#1
0
 public static TRet Create <TRet>(out T value, Func <OutputAccessor <T>, TRet> func)
 {
     return(SafeReference.CreateOut(
                out value,
                r => func(new OutputAccessor <T>(r))
                ));
 }
示例#2
0
 public static void Create(out T value, Action <OutputAccessor <T> > act)
 {
     SafeReference.CreateOut(
         out value,
         r => act(new OutputAccessor <T>(r))
         );
 }
示例#3
0
 public static TRet Create <TRet>(ref T value, Func <ReferenceAccessor <T>, TRet> func)
 {
     return(SafeReference.Create(
                ref value,
                r => func(new ReferenceAccessor <T>(r))
                ));
 }
示例#4
0
 public static void Create(ref T value, Action <ReferenceAccessor <T> > act)
 {
     SafeReference.Create(
         ref value,
         r => act(new ReferenceAccessor <T>(r))
         );
 }
示例#5
0
 public TRet GetReference <TRet>(int index, Func <SafeReference, TRet> func)
 {
     if (index < 0 || index >= count)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     return(SafeReference.Create(ref _items[index], func));
 }
示例#6
0
 /// <summary>
 /// Pins a reference in a memory and constructs its pin handle.
 /// </summary>
 /// <param name="r">The reference to pin.</param>
 protected void ReferenceAction(SafeReference r)
 {
     using (var re1 = new AutoResetEvent(false))
     {
         var thr = new Thread(
             delegate()
         {
             r.GetReference(                             //References are thread-unsafe!
                 tr => {
                                                         #if STORE_REFERENCE
                 {
                     SafeReference.Create(
                         tr,
                         r2 => {
                         Reference = r2;
                         re1.Set();
                         Reset.WaitOne();
                     }
                         );
                 }
                                                         #else
                 {
                     tr.Pin(
                         delegate {
                         re1.Set();
                         Reset.WaitOne();
                     }
                         );
                 }
                                                         #endif
             }
                 );
         }
             );
         thr.Start();
         re1.WaitOne();
     }
 }
示例#7
0
 public static void SetValueDirect(this FieldInfo fi, SafeReference sr, object value)
 {
     sr.GetReference(tr => fi.SetValueDirect(tr, value));
 }
示例#8
0
 public ReferenceAccessor(SafeReference r) : base(r)
 {
 }
示例#9
0
 /// <summary>
 /// Changes the address of a <see cref="SafeReference"/>.
 /// </summary>
 /// <param name="target">The target reference.</param>
 /// <param name="addr">The new address.</param>
 public static void ChangeAddress(SafeReference target, IntPtr addr)
 {
     target.ChangeAddress(addr);
 }
示例#10
0
 /// <summary>
 /// Returns the address of a <see cref="SafeReference"/>.
 /// </summary>
 /// <param name="target">The target reference.</param>
 /// <returns>The address of the reference.</returns>
 public static IntPtr GetAddress(SafeReference target)
 {
     return(target.GetAddress());
 }
示例#11
0
        // I wonder if it's necessary not to return the actual pointer, since these functions
        // don't attempt to pin the reference at all. I am not sure if the CLR would move it.

        /// <summary>
        /// Changes the type of a <see cref="SafeReference"/> to a new one.
        /// </summary>
        /// <param name="target">The target reference.</param>
        /// <param name="newType">The new type of the reference.</param>
        public static unsafe void ChangeType(SafeReference target, Type newType)
        {
            target.ChangeType(newType);
        }
示例#12
0
 public static TField GetValueDirect <TField>(this FieldInfo fi, SafeReference sr)
 {
     return(sr.GetReference(tr => GetValueDirect <TField>(fi, tr)));
 }
示例#13
0
 public TRet GetReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(SafeReference.GetBoxedReference(Instance, func));
 }
示例#14
0
 public TRet GetTempReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(GetTempReference(tr => SafeReference.Create(tr, func)));
 }
示例#15
0
 public TRet GetReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(TypedReferenceTools.MakeTypedReference(Target, new[] { Field }, tr => SafeReference.Create(tr, func)));
 }
示例#16
0
 public TRet GetReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(SafeReference.Create(__makeref(Array[Index]), func));
 }
示例#17
0
 /// <summary>
 /// Pins a reference in a memory and constructs its pin handle.
 /// </summary>
 /// <param name="obj">The reference to pin.</param>
 public OutPinHandle(out T obj)
 {
     SafeReference.CreateOut(out obj, ReferenceAction);
 }
示例#18
0
 /// <summary>
 /// Pins a reference in a memory and constructs its pin handle.
 /// </summary>
 /// <param name="obj">The reference to pin.</param>
 public RefPinHandle(ref T obj)
 {
     SafeReference.Create(ref obj, ReferenceAction);
 }
示例#19
0
 public OutputAccessor(SafeReference r)
 {
     Ref = r;
 }
示例#20
0
 /// <summary>
 /// Obtains a reference to an element in this array.
 /// </summary>
 public TRet GetReference <TRet>(int index, Func <SafeReference, TRet> func)
 {
     return(SafeReference.Create(ref array[index].Value, func));
 }
示例#21
0
 public static object GetValueDirect(this FieldInfo fi, SafeReference sr)
 {
     return(sr.GetReference(tr => fi.GetValueDirect(tr)));
 }
示例#22
0
 public void GetTempReference(Action <SafeReference> act)
 {
     GetTempReference(tr => SafeReference.Create(tr, act));
 }
示例#23
0
 public static void SetValueDirect <TField>(this FieldInfo fi, SafeReference sr, TField value)
 {
     sr.GetReference(tr => SetValueDirect <TField>(fi, tr, value));
 }
示例#24
0
 public TypedContainer(SafeReference sr) : this()
 {
     Type  = sr.Type;
     Value = sr.Value;
 }
示例#25
0
 public TRet GetReference <TRet>(Func <SafeReference, TRet> func)
 {
     return(SafeReference.Create(__makeref(Value), func));
 }