Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }