Esempio n. 1
0
 /// <summary>
 /// Call an instance method on a given type, taking zero arguments
 /// </summary>
 /// <typeparam name="TEmit"></typeparam>
 /// <typeparam name="TCallee"></typeparam>
 /// <param name="emitter"></param>
 /// <param name="methodName"></param>
 public static void CallRuntimeThis0 <TEmit, TCallee>(this OptimisingEmitter <TEmit> emitter, string methodName)
 {
     using (var local = emitter.DeclareLocal(typeof(TCallee), "CallRuntimeThis0_Callee", false))
     {
         emitter.StoreLocal(local);
         emitter.LoadLocalAddress(local, false);
         emitter.CallRuntimeN <TEmit, TCallee>(methodName);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Get the value of a field (even a private one) on a type
        /// </summary>
        /// <typeparam name="TEmit"></typeparam>
        /// <typeparam name="TType"></typeparam>
        /// <param name="emitter"></param>
        /// <param name="fieldName"></param>
        public static void GetRuntimeFieldValue <TEmit, TType>(this OptimisingEmitter <TEmit> emitter, string fieldName)
        {
            var field = typeof(TType).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static) !;

            using (var local = emitter.DeclareLocal(typeof(TType), "GetRuntimeFieldValue_Callee", false))
            {
                emitter.StoreLocal(local);
                emitter.LoadLocalAddress(local, true);
                emitter.LoadField(field);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get the value of a property on a type
        /// </summary>
        /// <typeparam name="TEmit"></typeparam>
        /// <typeparam name="TType"></typeparam>
        /// <param name="emitter"></param>
        /// <param name="propertyName"></param>
        public static void GetRuntimePropertyValue <TEmit, TType>(this OptimisingEmitter <TEmit> emitter, string propertyName)
        {
            // ReSharper disable once PossibleNullReferenceException
            var method = typeof(TType).GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static) !.GetMethod !;

            using (var local = emitter.DeclareLocal(typeof(TType), "GetRuntimePropertyValue_Callee", false))
            {
                emitter.StoreLocal(local);
                emitter.LoadLocalAddress(local, true);
                emitter.Call(method);
            }
        }