Backport XML documentation for DynamicMethod and DynamicILInfo from dotnet-api-docs#124227
Backport XML documentation for DynamicMethod and DynamicILInfo from dotnet-api-docs#124227
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs
Show resolved
Hide resolved
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
All feedback addressed in commit 2f4fe14. Changes include:
|
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
Show resolved
Hide resolved
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
|
@copilot Can you update the instructions at #124227 (comment) with the backtick vs. |
Updated instructions for backporting XML documentation from dotnet-api-docs to dotnet/runtime: XML Documentation Backport Process:
|
|
Tagging subscribers to this area: @dotnet/area-system-reflection-emit |
|
@copilot Please switch the URL form. This is the base URL we want, up to and including the branch name: https://github.com/dotnet/docs/raw/main/ |
Co-authored-by: richlander <2608468+richlander@users.noreply.github.com>
| Console.WriteLine("\r\nName: {0}", hello.Name); | ||
| #endregion | ||
|
|
||
| #region DeclaringType |
There was a problem hiding this comment.
I think about samples as code snippets that demonstrate the typical usage pattern of the API and that one can copy&paste into their code and then modify to suit their needs. Is my thinking correct?
This code snippet is not anything like that. It largely duplicates boring parts of the documentation, e.g. https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.dynamicmethod.declaringtype says "Gets the type that declares the method, which is always null for dynamic methods." and this code sample shows that it is the case. It is not useful.
This is what a good basic example for DynamicMethod can look like (generated via "Give me a basic example of DynamicMethod use"):
using System;
using System.Reflection.Emit;
class Program
{
static void Main()
{
// Create a dynamic method that returns int and takes two ints
DynamicMethod dynamicAdd = new DynamicMethod(
"AddNumbers", // method name
typeof(int), // return type
new Type[] { typeof(int), typeof(int) } // parameter types
);
// Get IL generator
ILGenerator il = dynamicAdd.GetILGenerator();
// Load first argument
il.Emit(OpCodes.Ldarg_0);
// Load second argument
il.Emit(OpCodes.Ldarg_1);
// Add them
il.Emit(OpCodes.Add);
// Return result
il.Emit(OpCodes.Ret);
// Create delegate
var addDelegate = (Func<int, int, int>)dynamicAdd.CreateDelegate(typeof(Func<int, int, int>));
// Execute dynamic method
int result = addDelegate(5, 7);
Console.WriteLine(result); // Output: 12
}
}
| /// .NET Framework: <see langword="true" /> if the current dynamic method is security-critical or security-safe-critical; <see langword="false" /> if it is transparent. | ||
| /// </value> | ||
| /// <remarks> | ||
| /// For more information about this API, see <see href="https://github.com/dotnet/docs/raw/main/docs/fundamentals/runtime-libraries/system-reflection-emit-dynamicmethod-issecuritycritical.md">Supplemental API remarks for DynamicMethod.IsSecurityCritical</see>. |
There was a problem hiding this comment.
I do like the idea of moving the documentation for complicated .NET Framework specific details somewhere else.
docs/fundamentals does not sound like the right directory for that. It is anything but fundamentals. Can it live under directory that suggest it is .NET Framework specific and not really relevant for modern .NET?
| // This file contains code examples for XML documentation. | ||
| // The examples are referenced by the DynamicMethod class documentation using #region names. | ||
|
|
||
| #pragma warning disable CS8321 // Local function is declared but never used |
There was a problem hiding this comment.
The #pragmas and #regions are not pretty. Samples should be nice clean code.
| /// <exception cref="InvalidOperationException">The dynamic method has no method body.</exception> | ||
| /// <exception cref="ArgumentException"><paramref name="delegateType" /> has the wrong number of parameters or the wrong parameter types.</exception> | ||
| /// <remarks> | ||
| /// For more information about this API, see <see href="https://github.com/dotnet/docs/raw/main/docs/fundamentals/runtime-libraries/system-reflection-emit-dynamicmethod-createdelegate.md">Supplemental API remarks for DynamicMethod.CreateDelegate</see>. |
There was a problem hiding this comment.
Majority of this doc are several samples. Should it live here together with the samples instead?
| /// <param name="parameterTypes">An array of <see cref="Type" /> objects specifying the types of the parameters of the dynamic method, or <see langword="null" /> if the method has no parameters.</param> | ||
| /// <exception cref="ArgumentException">An element of <paramref name="parameterTypes" /> is <see langword="null" /> or <see cref="Void" />.</exception> | ||
| /// <exception cref="ArgumentNullException"><paramref name="name" /> is <see langword="null" />.</exception> | ||
| /// <exception cref="NotSupportedException">.NET Framework and .NET Core versions older than 2.1: <paramref name="returnType" /> is a type for which <see cref="Type.IsByRef" /> returns <see langword="true" />.</exception> |
There was a problem hiding this comment.
Would be feasible to drop quirks of very old .NET Core versions from the documentation?
| /// <exception cref="ArgumentNullException"><paramref name="name" /> is <see langword="null" />.</exception> | ||
| /// <exception cref="NotSupportedException">.NET Framework and .NET Core versions older than 2.1: <paramref name="returnType" /> is a type for which <see cref="Type.IsByRef" /> returns <see langword="true" />.</exception> | ||
| /// <remarks> | ||
| /// For more information about this API, see <see href="https://github.com/dotnet/docs/raw/main/docs/fundamentals/runtime-libraries/system-reflection-emit-dynamicmethod.md">Supplemental API remarks for DynamicMethod</see>. |
There was a problem hiding this comment.
Similar to my other comment- most of this doc is .NET Framework specific (all the discussion about obsolete partial trust, reflection permissions, ...).
| // Delegate and method creation | ||
| // | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
For types and methods that have split runtime-specific, OS-specific or architecture-specific implementation, I think we should add partial methods into the neutral file (DynamicMethod.cs in this case) and keep the documentation there. Otherwise, it is not obvious where the source of truth of the documentation lives.
|
@copilot please respond to all feedback. |
I've reviewed all of @jkotas's feedback. The comments raise significant concerns that suggest this PR may need a fundamentally different approach: Key Issues Identified:
Recommendation: These concerns suggest the PR needs substantial rework beyond simple fixes. The fundamental questions are:
@gewarren, given the scope of these concerns, would you prefer that I: |
Contributes to dotnet/dotnet-api-docs#12307.
Description
Backported XML documentation comments from
dotnet/dotnet-api-docsto theDynamicMethodandDynamicILInfoclasses. Per requirements, specific members (constructors,CreateDelegate,GetILGenerator,Invoke,IsSecurityCritical) include remarks linking to supplemental API documentation. Each member links to its specific article in the dotnet/docs repository.These documents will become available when dotnet/docs#51571 merges.
Changes Made
DynamicMethod Documentation
<summary>and<remarks>with supplemental link to theDynamicMethodclass declaration<summary>,<param>,<exception>, and<remarks>with supplemental links to the parent type articleDynamicILInfo Documentation
<summary>and<remarks>with supplemental link to theDynamicILInfoclass in CoreCLR implementation<summary>,<param>,<exception>, and<remarks>Code Examples
#regionblocks, following the Newtonsoft.Json documentation pattern<example>sections to 12 DynamicMethod members (Name, DeclaringType, ReflectedType, Module, Attributes, CallingConvention, GetParameters, ReturnType, ReturnTypeCustomAttributes, DefineParameter, ToString, InitLocals) that reference the Examples.cs file using<code lang="cs" source="../../../../samples/System/Reflection/Emit/DynamicMethod.Examples.cs" region="..." />Other Changes
https://github.com/dotnet/docs/raw/main/format per guidelines<c>tags instead of backticksKnown Issues / Pending Feedback
Several concerns have been raised by @jkotas regarding this PR's approach:
docs/fundamentals(comments 2887319023, 2887364803)These concerns may require a fundamental rework of the PR's approach. Awaiting guidance from @gewarren on how to proceed.
Files Modified
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs- Main file with complete documentation including all remarks and example references (407 lines added)src/libraries/System.Private.CoreLib/samples/System/Reflection/Emit/DynamicMethod.Examples.cs- New file with code examples in #region blocks (143 lines added)src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs- CoreCLR-specific members with supplemental links (59 lines added, 11 lines modified)src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs- DynamicILInfo class documentation (137 lines added)src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs- Removed duplicate documentation (48 lines removed)src/libraries/System.Reflection.Emit.Lightweight/ref/System.Reflection.Emit.Lightweight.cs- Removed documentation (moved to source implementation)Total: ~698 net lines added across all implementations with complete remarks and examples backported from dotnet-api-docs.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.