Skip to content

Commit

Permalink
Merge pull request #9207 from dotnet/main
Browse files Browse the repository at this point in the history
  • Loading branch information
BillWagner authored Aug 22, 2023
2 parents c670bc4 + c3a3aad commit 5540036
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;

static class CustomAttributeSnippets
{
// <SnippetPrintAttributes>
class MyAttribute : Attribute
{
public int X { get; set; }
}

[My(X = 1)]
class ExampleType1 { }

[My(X = 2)]
class ExampleType2 { }

static void PrintCustomAttributes(MetadataReader mr, TypeDefinition t)
{
// Enumerate custom attributes on the type definition
foreach (CustomAttributeHandle attrHandle in t.GetCustomAttributes())
{
CustomAttribute attr = mr.GetCustomAttribute(attrHandle);

// Display the attribute type full name
if (attr.Constructor.Kind == HandleKind.MethodDefinition)
{
MethodDefinition mdef = mr.GetMethodDefinition((MethodDefinitionHandle)attr.Constructor);
TypeDefinition tdef = mr.GetTypeDefinition(mdef.GetDeclaringType());
Console.WriteLine($"Type: {mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
}
else if (attr.Constructor.Kind == HandleKind.MemberReference)
{
MemberReference mref = mr.GetMemberReference((MemberReferenceHandle)attr.Constructor);

if (mref.Parent.Kind == HandleKind.TypeReference)
{
TypeReference tref = mr.GetTypeReference((TypeReferenceHandle)mref.Parent);
Console.WriteLine($"Type: {mr.GetString(tref.Namespace)}.{mr.GetString(tref.Name)}");
}
else if (mref.Parent.Kind == HandleKind.TypeDefinition)
{
TypeDefinition tdef = mr.GetTypeDefinition((TypeDefinitionHandle)mref.Parent);
Console.WriteLine($"Type: {mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
}
}

// Display the attribute value
byte[] data = mr.GetBlobBytes(attr.Value);
Console.Write("Value: ");

for (int i = 0; i < data.Length; i++) Console.Write($"{data[i]:X2} ");

Console.WriteLine();
}
}

static void PrintTypesCustomAttributes(MetadataReader mr)
{
foreach (TypeDefinitionHandle tdh in mr.TypeDefinitions)
{
TypeDefinition t = mr.GetTypeDefinition(tdh);
Console.WriteLine($"{mr.GetString(t.Namespace)}.{mr.GetString(t.Name)}");
PrintCustomAttributes(mr, t);
}
}
// </SnippetPrintAttributes>

public static void Run()
{
using var fs = new FileStream(typeof(Program).Assembly.Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var peReader = new PEReader(fs);
MetadataReader mr = peReader.GetMetadataReader();
PrintTypesCustomAttributes(mr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

class Program
{
static void Main()
{
CustomAttributeSnippets.Run();
}
}
2 changes: 1 addition & 1 deletion xml/System.Diagnostics/ActivityTraceId.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ The characters in <paramref name="idData" /> are not all lower-case hexadecimal
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a 16-character hexadecimal string that represents this span ID.</summary>
<summary>Returns a 32-character hexadecimal string that represents this span ID.</summary>
<returns>The 32-character hexadecimal string representation of this trace ID.</returns>
<remarks>To be added.</remarks>
</Docs>
Expand Down
19 changes: 10 additions & 9 deletions xml/System.Numerics/INumberBase`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,10 @@ For <xref:System.Numerics.IFloatingPointIeee754%601> this method matches the IEE
<Parameter Name="provider" Type="System.IFormatProvider" Index="1" FrameworkAlternate="net-8.0" />
</Parameters>
<Docs>
<param name="utf8Text">To be added.</param>
<param name="provider">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
<summary>Parses a span of UTF-8 characters into a value.</summary>
<returns>The result of parsing <paramref name="utf8Text" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
Expand Down Expand Up @@ -1215,11 +1215,12 @@ For <xref:System.Numerics.IFloatingPointIeee754%601> this method matches the IEE
</Parameter>
</Parameters>
<Docs>
<param name="utf8Text">To be added.</param>
<param name="provider">To be added.</param>
<param name="result">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
<param name="result">On return, contains the result of successfully parsing <paramref name="utf8Text" /> or an undefined value on failure.</param>
<summary>Tries to parse a span of UTF-8 characters into a value.</summary>
<returns>
<see langword="true" /> if <paramref name="utf8Text" /> was successfully parsed; otherwise, <see langword="false" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
Expand Down
16 changes: 14 additions & 2 deletions xml/System.Reflection.Metadata/CustomAttribute.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@
</Attribute>
</Attributes>
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
<summary>Provides information about a custom attribute.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A custom attribute is an annotation that associates additional information with a metadata element, such as an assembly, type, or method. You can use the <xref:System.Reflection.Metadata.MetadataReader.GetCustomAttribute(System.Reflection.Metadata.CustomAttributeHandle)> method to get a custom attribute instance. For more information about attributes in .NET, see [Extend metadata using attributes](/dotnet/standard/attributes/).
## Examples
This example shows how to print all custom attributes applied to the type definition:
:::code language="csharp" source="~/snippets/csharp/System.Reflection.Metadata/CustomAttribute/Overview/CustomAttributeSnippets.cs" id="SnippetPrintAttributes":::
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName="Constructor">
Expand Down
34 changes: 21 additions & 13 deletions xml/System.Runtime.InteropServices/NFloat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ This computes `cos(x * π)`.
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.Numerics.ITrigonometricFunctions`1.DegreesToRadians(`0)" />
</Docs>
</Member>
<Member MemberName="E">
Expand Down Expand Up @@ -4540,11 +4541,12 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
</Parameter>
</Parameters>
<Docs>
<param name="utf8Text">To be added.</param>
<param name="provider">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
<summary>Parses a span of UTF-8 characters into a value.</summary>
<returns>The result of parsing <paramref name="utf8Text" />.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.IUtf8SpanParsable`1.Parse(System.ReadOnlySpan{System.Byte},System.IFormatProvider)" />
</Docs>
</Member>
<Member MemberName="Parse">
Expand Down Expand Up @@ -4714,6 +4716,7 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.Numerics.INumberBase`1.Parse(System.ReadOnlySpan{System.Byte},System.Globalization.NumberStyles,System.IFormatProvider)" />
</Docs>
</Member>
<Member MemberName="Parse">
Expand Down Expand Up @@ -4929,6 +4932,7 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.Numerics.ITrigonometricFunctions`1.RadiansToDegrees(`0)" />
</Docs>
</Member>
<Member MemberName="ReciprocalEstimate">
Expand Down Expand Up @@ -7025,10 +7029,11 @@ This computes `tan(x * π)`.
<Parameter Name="result" Type="System.Runtime.InteropServices.NFloat" RefType="out" Index="1" FrameworkAlternate="net-8.0" />
</Parameters>
<Docs>
<param name="utf8Text">To be added.</param>
<param name="result">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<param name="utf8Text">A read-only UTF-8 character span that contains the number to convert.</param>
<param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="utf8Text" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="utf8Text" /> is <see cref="P:System.ReadOnlySpan`1.Empty" /> or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
<summary>Tries to convert a UTF-8 character span containing the string representation of a number to its floating-point number equivalent.</summary>
<returns>
<see langword="true" /> if <paramref name="utf8Text" /> was converted successfully; otherwise, <see langword="false" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
Expand Down Expand Up @@ -7131,12 +7136,14 @@ This computes `tan(x * π)`.
<Parameter Name="result" Type="System.Runtime.InteropServices.NFloat" RefType="out" Index="2" FrameworkAlternate="net-8.0" />
</Parameters>
<Docs>
<param name="utf8Text">To be added.</param>
<param name="provider">To be added.</param>
<param name="result">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
<param name="result">On return, contains the result of successfully parsing <paramref name="utf8Text" /> or an undefined value on failure.</param>
<summary>Tries to parse a span of UTF-8 characters into a value.</summary>
<returns>
<see langword="true" /> if <paramref name="utf8Text" /> was successfully parsed; otherwise, <see langword="false" />.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.IUtf8SpanParsable`1.TryParse(System.ReadOnlySpan{System.Byte},System.IFormatProvider,`0@)" />
</Docs>
</Member>
<Member MemberName="TryParse">
Expand Down Expand Up @@ -7259,6 +7266,7 @@ This computes `tan(x * π)`.
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
<inheritdoc cref="M:System.Numerics.INumberBase`1.TryParse(System.ReadOnlySpan{System.Byte},System.Globalization.NumberStyles,System.IFormatProvider,`0@)" />
</Docs>
</Member>
<Member MemberName="TryParse">
Expand Down
3 changes: 3 additions & 0 deletions xml/System.Threading/ThreadPool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,9 @@ If a thread pool implementation may have different types of work items, the coun
Setting the thread pool size too large can cause performance problems. If too many threads are executing at the same time, the task switching overhead becomes a significant factor.
> [!NOTE]
> The thread pool may have upper limits for the maximum thread counts (such as `short.MaxValue`, depending on the implementation). The argument values are capped to the upper limit, so even when the method returns `true`, the actual maximum thread counts may be lower than requested.
]]></format>
</remarks>
<altmember cref="M:System.Threading.ThreadPool.GetMaxThreads(System.Int32@,System.Int32@)" />
Expand Down

0 comments on commit 5540036

Please sign in to comment.