-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add XML documentation to DynamicMethod from dotnet-api-docs #124227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/backport-xml-doc-comments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b02414b
Initial plan
Copilot f1fa223
Add XML documentation to DynamicMethod class
Copilot 2f4fe14
Address review feedback: add missing remarks and fix supplemental links
Copilot 69754d8
Remove duplicate documentation from Mono file
Copilot ac08171
Add example sections to DynamicMethod documentation
Copilot 488b3c0
Convert examples to inline C# code and remove VB references
Copilot 7802100
Move code examples to separate file with #region blocks
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Examples.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // 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 | ||
|
|
||
| using System; | ||
| using System.Reflection; | ||
| using System.Reflection.Emit; | ||
|
|
||
| namespace System.Reflection.Emit.Examples | ||
| { | ||
| internal static class DynamicMethodExamples | ||
| { | ||
| private static void Examples() | ||
| { | ||
| // Note: 'hello' represents a DynamicMethod instance used in the examples below | ||
|
|
||
| #region Name | ||
| // Display the name specified when the dynamic method was created. | ||
| // Note that the name can be blank. | ||
| Console.WriteLine("\r\nName: {0}", hello.Name); | ||
| #endregion | ||
|
|
||
| #region DeclaringType | ||
| // Display the declaring type, which is always null for dynamic | ||
| // methods. | ||
| if (hello.DeclaringType == null) | ||
| { | ||
| Console.WriteLine("\r\nDeclaringType is always null for dynamic methods."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("DeclaringType: {0}", hello.DeclaringType); | ||
| } | ||
| #endregion | ||
|
|
||
| #region ReflectedType | ||
| // For dynamic methods, the reflected type is always null. | ||
| if (hello.ReflectedType == null) | ||
| { | ||
| Console.WriteLine("\r\nReflectedType is null."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("\r\nReflectedType: {0}", hello.ReflectedType); | ||
| } | ||
| #endregion | ||
|
|
||
| #region Module | ||
| // Display the module specified when the dynamic method was created. | ||
| Console.WriteLine("\r\nModule: {0}", hello.Module); | ||
| #endregion | ||
|
|
||
| #region Attributes | ||
| // Display MethodAttributes for the dynamic method, set when | ||
| // the dynamic method was created. | ||
| Console.WriteLine("\r\nMethod Attributes: {0}", hello.Attributes); | ||
| #endregion | ||
|
|
||
| #region CallingConvention | ||
| // Display the calling convention of the dynamic method, set when the | ||
| // dynamic method was created. | ||
| Console.WriteLine("\r\nCalling convention: {0}", hello.CallingConvention); | ||
| #endregion | ||
|
|
||
| #region GetParameters | ||
| // Display parameter information. | ||
| ParameterInfo[] parameters = hello.GetParameters(); | ||
| Console.WriteLine("\r\nParameters: name, type, ParameterAttributes"); | ||
| foreach( ParameterInfo p in parameters ) | ||
| { | ||
| Console.WriteLine("\t{0}, {1}, {2}", | ||
| p.Name, p.ParameterType, p.Attributes); | ||
| } | ||
| #endregion | ||
|
|
||
| #region ReturnType | ||
| // If the method has no return type, ReturnType is System.Void. | ||
| Console.WriteLine("\r\nReturn type: {0}", hello.ReturnType); | ||
| #endregion | ||
|
|
||
| #region ReturnTypeCustomAttributes | ||
| // ReturnTypeCustomAttributes returns an ICustomeAttributeProvider | ||
| // that can be used to enumerate the custom attributes of the | ||
| // return value. At present, there is no way to set such custom | ||
| // attributes, so the list is empty. | ||
| if (hello.ReturnType == typeof(void)) | ||
| { | ||
| Console.WriteLine("The method has no return type."); | ||
| } | ||
| else | ||
| { | ||
| ICustomAttributeProvider caProvider = hello.ReturnTypeCustomAttributes; | ||
| object[] returnAttributes = caProvider.GetCustomAttributes(true); | ||
| if (returnAttributes.Length == 0) | ||
| { | ||
| Console.WriteLine("\r\nThe return type has no custom attributes."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("\r\nThe return type has the following custom attributes:"); | ||
| foreach( object attr in returnAttributes ) | ||
| { | ||
| Console.WriteLine("\t{0}", attr.ToString()); | ||
| } | ||
| } | ||
| } | ||
| #endregion | ||
|
|
||
| #region DefineParameter | ||
| // Add parameter information to the dynamic method. (This is not | ||
| // necessary, but can be useful for debugging.) For each parameter, | ||
| // identified by position, supply the parameter attributes and a | ||
| // parameter name. | ||
| hello.DefineParameter(1, ParameterAttributes.In, "message"); | ||
| hello.DefineParameter(2, ParameterAttributes.In, "valueToReturn"); | ||
| #endregion | ||
|
|
||
| #region ToString | ||
| Console.WriteLine("\r\nToString: {0}", hello.ToString()); | ||
| #endregion | ||
|
|
||
| #region InitLocals | ||
| // Display the default value for InitLocals. | ||
| if (hello.InitLocals) | ||
| { | ||
| Console.Write("\r\nThis method contains verifiable code."); | ||
| } | ||
| else | ||
| { | ||
| Console.Write("\r\nThis method contains unverifiable code."); | ||
| } | ||
| Console.WriteLine(" (InitLocals = {0})", hello.InitLocals); | ||
| #endregion | ||
| } | ||
|
|
||
| // Placeholder for the DynamicMethod variable used in examples | ||
| private static DynamicMethod hello = null!; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Why didn't you backport the <remarks> here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added GetDynamicILInfo remarks in commit 2f4fe14.