CKTIS / C#
System.Reflection.MethodInfo: practical reference
System.Reflection.MethodInfo: practical reference: MethodInfo describes a method and enables Invoke or delegate creation.
Version: .NET API; verified against .NET 10 reference surface
Syntax
System.Reflection.MethodInfo /* select a documented member or constructor */MethodInfo describes a method and enables Invoke or delegate creation.
Use it for controlled invocation of a method selected from metadata.
Invoke wraps the method exception in TargetInvocationException and requires compatible arguments.
Generic methods require MakeGenericMethod, and an overload must be selected unambiguously.
The complete program actually uses System.Reflection.MethodInfo; its exact expected stdout is True.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var method = typeof(string).GetMethod(nameof(string.StartsWith), new[] { typeof(string) })!;
Console.WriteLine(method.Invoke("abc", new object[] { "a" }));
Result
True
The complete program actually uses `System.Reflection.MethodInfo`; its exact expected stdout is `True`.