protected Delegate GenerateDynamicShim(Type returnType = null) { var expressionParamsArray = ExpressionParameters.Select(p => p.Type).ToArray(); Type[] paramTypesArray; if (Method.IsStatic) { paramTypesArray = expressionParamsArray; } else { var invokingTypeArray = new Type[] { DeclaringType }; paramTypesArray = new Type[expressionParamsArray.Length + 1]; invokingTypeArray.CopyTo(paramTypesArray, 0); expressionParamsArray.CopyTo(paramTypesArray, 1); } var dynamicMethod = new DynamicMethod("shimmy_" + Method.Name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, Method.ReturnType, paramTypesArray, DeclaringType, false); return(ShimmedMemberHelper.GenerateDynamicShim(dynamicMethod, LibraryReferenceGuid, paramTypesArray, returnType)); }
public ShimReplacement(ShimmedMember parent, Type returnType, object returnValue, bool isPassThrough = false) { Parent = parent ?? throw new ArgumentNullException(nameof(parent)); ReturnType = returnType ?? throw new ArgumentNullException(nameof(ReturnType)); IsPassThrough = isPassThrough; HasReturnValue = ShimmedMemberHelper.MemberCanReturn(parent.Member) && ReturnType != typeof(void); if (HasReturnValue) { ReturnValue = returnValue; } }
private Delegate GenerateDynamicShim() { var expressionParamsArray = ExpressionParameters.Select(p => p.Type).ToArray(); var dynamicMethod = new DynamicMethod("shimmy_ctor_" + Constructor.Name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, Constructor.DeclaringType, expressionParamsArray, Constructor.DeclaringType, false); return(ShimmedMemberHelper.GenerateDynamicShim(dynamicMethod, LibraryReferenceGuid, expressionParamsArray, Constructor.DeclaringType)); }
public ShimmedConstructor(ConstructorInfo constructor) : base() { Init(constructor, constructor.DeclaringType, ShimmedMemberHelper.GetDefaultValue(constructor.DeclaringType)); }