/// <summary> /// Regisgters <see cref="MethodBase"/> usage to the current emitting session. /// </summary> /// <param name="method">The <see cref="MethodBase"/> to be registered.</param> /// <returns> /// <see cref=" Action{T1,T2}"/> to emit serializer retrieval instructions. /// The 1st argument should be <see cref="TracingILGenerator"/> to emit instructions. /// The 2nd argument should be argument index of the serializer holder, normally 0 (this pointer). /// This value will not be <c>null</c>. /// </returns> public Action <TracingILGenerator, int> RegisterMethodCache(MethodBase method) { #if !NETSTANDARD1_1 && !NETSTANDARD1_3 var key = method.MethodHandle; #else var key = method; #endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 CachedMethodBase result; if (!this._cachedMethodBases.TryGetValue(key, out result)) { Contract.Assert(method.DeclaringType != null, "method.DeclaringType != null"); result = new CachedMethodBase( method, this.DefineInitonlyField( "_function" + method.DeclaringType.Name + "_" + method.Name + this._cachedMethodBases.Count, typeof(MethodBase) ) ); this._cachedMethodBases.Add(key, result); } return ((il, thisIndex) => { il.EmitAnyLdarg(thisIndex); il.EmitLdfld(result.StorageFieldBuilder); }); }
public string RegisterCachedMethodBase(MethodBase method) { var key = method.MethodHandle; CachedMethodBase cachedMethod; if (!this._cachedPropertyAccessors.TryGetValue(key, out cachedMethod)) { Contract.Assert(method.DeclaringType != null, "method.DeclaringType != null"); cachedMethod = new CachedMethodBase( method, "_methodBase" + method.DeclaringType.Name.Replace('`', '_') + "_" + method.Name + this._cachedPropertyAccessors.Count.ToString(CultureInfo.InvariantCulture) ); this._cachedPropertyAccessors.Add(key, cachedMethod); this._buildingType.Members.Add( new CodeMemberField( typeof(MethodBase), cachedMethod.StorageFieldName ) ); } return(cachedMethod.StorageFieldName); }
public override Action <TracingILGenerator, int> RegisterMethod(MethodBase method) { if (this._typeBuilder.IsCreated()) { throw new InvalidOperationException("Type is already built."); } var key = method.MethodHandle; CachedMethodBase result; if (!this._cachedMethodBases.TryGetValue(key, out result)) { Contract.Assert(method.DeclaringType != null, "method.DeclaringType != null"); result = new CachedMethodBase( method, this._typeBuilder.DefineField( "_function" + method.DeclaringType.Name + "_" + method.Name + this._cachedMethodBases.Count, typeof(FieldInfo), FieldAttributes.Private | FieldAttributes.InitOnly ) ); this._cachedMethodBases.Add(key, result); } return ((il, thisIndex) => { il.EmitAnyLdarg(thisIndex); il.EmitLdfld(result.StorageFieldBuilder); }); }