SetMethodParameters() public method

Assigns parameters to the target method.
public SetMethodParameters ( ) : void
return void
 /// <summary>
 /// Sets the default method options for the GetServiceHashCode method.
 /// </summary>
 /// <param name="targetType">The targe type.</param>
 /// <param name="shouldBeVisible">A boolean flag that determines whether or not the method should be publicly visible.</param>
 /// <param name="options">The <see cref="MethodBuilderOptions"/> object to be modified.</param>
 private static void DefineOptions(TypeDefinition targetType, bool shouldBeVisible, MethodBuilderOptions options)
 {
     options.HostType = targetType;
     options.MethodName = "GetServiceHashCode";
     options.ReturnType = typeof(int);
     options.SetMethodParameters(typeof(Type), typeof(string));
     options.IsPublic = shouldBeVisible;
     options.IsStatic = true;
 }
Example #2
0
 /// <summary>
 /// Sets the default method options for the GetServiceHashCode method.
 /// </summary>
 /// <param name="targetType">The targe type.</param>
 /// <param name="shouldBeVisible">A boolean flag that determines whether or not the method should be publicly visible.</param>
 /// <param name="options">The <see cref="MethodBuilderOptions"/> object to be modified.</param>
 private static void DefineOptions(TypeDefinition targetType, bool shouldBeVisible, MethodBuilderOptions options)
 {
     options.HostType   = targetType;
     options.MethodName = "GetServiceHashCode";
     options.ReturnType = typeof(int);
     options.SetMethodParameters(typeof(System.Type), typeof(string));
     options.IsPublic = shouldBeVisible;
     options.IsStatic = true;
 }
Example #3
0
        /// <summary>
        /// Adds a method override for a particular <paramref name="targetMethod"/>.
        /// </summary>
        /// <param name="targetMethod">The target method.</param>
        /// <param name="hostType">The type that will host the new method.</param>
        /// <returns>The overridden method.</returns>
        public MethodDefinition AddOverrideFor(MethodInfo targetMethod, TypeDefinition hostType)
        {
            var module = hostType.Module;
            var options = new MethodBuilderOptions();

            options.IsPublic = true;
            options.MethodName = targetMethod.Name;

            var parameterTypes = new List<System.Type>();
            foreach (var param in targetMethod.GetParameters())
            {
                parameterTypes.Add(param.ParameterType);
            }

            options.HostType = hostType;
            options.SetMethodParameters(parameterTypes.ToArray());
            options.ReturnType = targetMethod.ReturnType;

            var builder = new MethodBuilder();
            return builder.CreateMethod(options);
        }
Example #4
0
        /// <summary>
        /// Adds a method override for a particular <paramref name="targetMethod"/>.
        /// </summary>
        /// <param name="targetMethod">The target method.</param>
        /// <param name="hostType">The type that will host the new method.</param>
        /// <returns>The overridden method.</returns>
        public MethodDefinition AddOverrideFor(MethodInfo targetMethod, TypeDefinition hostType)
        {
            var module  = hostType.Module;
            var options = new MethodBuilderOptions();

            options.IsPublic   = true;
            options.MethodName = targetMethod.Name;

            var parameterTypes = new List <Type>();

            foreach (var param in targetMethod.GetParameters())
            {
                parameterTypes.Add(param.ParameterType);
            }

            options.HostType = hostType;
            options.SetMethodParameters(parameterTypes.ToArray());
            options.ReturnType = targetMethod.ReturnType;

            var builder = new MethodBuilder();

            return(builder.CreateMethod(options));
        }