Skip to content

Commit 5540036

Browse files
authored
Merge pull request #9207 from dotnet/main
2 parents c670bc4 + c3a3aad commit 5540036

File tree

8 files changed

+145
-25
lines changed

8 files changed

+145
-25
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection.Metadata;
4+
using System.Reflection.PortableExecutable;
5+
6+
static class CustomAttributeSnippets
7+
{
8+
// <SnippetPrintAttributes>
9+
class MyAttribute : Attribute
10+
{
11+
public int X { get; set; }
12+
}
13+
14+
[My(X = 1)]
15+
class ExampleType1 { }
16+
17+
[My(X = 2)]
18+
class ExampleType2 { }
19+
20+
static void PrintCustomAttributes(MetadataReader mr, TypeDefinition t)
21+
{
22+
// Enumerate custom attributes on the type definition
23+
foreach (CustomAttributeHandle attrHandle in t.GetCustomAttributes())
24+
{
25+
CustomAttribute attr = mr.GetCustomAttribute(attrHandle);
26+
27+
// Display the attribute type full name
28+
if (attr.Constructor.Kind == HandleKind.MethodDefinition)
29+
{
30+
MethodDefinition mdef = mr.GetMethodDefinition((MethodDefinitionHandle)attr.Constructor);
31+
TypeDefinition tdef = mr.GetTypeDefinition(mdef.GetDeclaringType());
32+
Console.WriteLine($"Type: {mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
33+
}
34+
else if (attr.Constructor.Kind == HandleKind.MemberReference)
35+
{
36+
MemberReference mref = mr.GetMemberReference((MemberReferenceHandle)attr.Constructor);
37+
38+
if (mref.Parent.Kind == HandleKind.TypeReference)
39+
{
40+
TypeReference tref = mr.GetTypeReference((TypeReferenceHandle)mref.Parent);
41+
Console.WriteLine($"Type: {mr.GetString(tref.Namespace)}.{mr.GetString(tref.Name)}");
42+
}
43+
else if (mref.Parent.Kind == HandleKind.TypeDefinition)
44+
{
45+
TypeDefinition tdef = mr.GetTypeDefinition((TypeDefinitionHandle)mref.Parent);
46+
Console.WriteLine($"Type: {mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
47+
}
48+
}
49+
50+
// Display the attribute value
51+
byte[] data = mr.GetBlobBytes(attr.Value);
52+
Console.Write("Value: ");
53+
54+
for (int i = 0; i < data.Length; i++) Console.Write($"{data[i]:X2} ");
55+
56+
Console.WriteLine();
57+
}
58+
}
59+
60+
static void PrintTypesCustomAttributes(MetadataReader mr)
61+
{
62+
foreach (TypeDefinitionHandle tdh in mr.TypeDefinitions)
63+
{
64+
TypeDefinition t = mr.GetTypeDefinition(tdh);
65+
Console.WriteLine($"{mr.GetString(t.Namespace)}.{mr.GetString(t.Name)}");
66+
PrintCustomAttributes(mr, t);
67+
}
68+
}
69+
// </SnippetPrintAttributes>
70+
71+
public static void Run()
72+
{
73+
using var fs = new FileStream(typeof(Program).Assembly.Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
74+
using var peReader = new PEReader(fs);
75+
MetadataReader mr = peReader.GetMetadataReader();
76+
PrintTypesCustomAttributes(mr);
77+
}
78+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
class Program
4+
{
5+
static void Main()
6+
{
7+
CustomAttributeSnippets.Run();
8+
}
9+
}

xml/System.Diagnostics/ActivityTraceId.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ The characters in <paramref name="idData" /> are not all lower-case hexadecimal
405405
</ReturnValue>
406406
<Parameters />
407407
<Docs>
408-
<summary>Returns a 16-character hexadecimal string that represents this span ID.</summary>
408+
<summary>Returns a 32-character hexadecimal string that represents this span ID.</summary>
409409
<returns>The 32-character hexadecimal string representation of this trace ID.</returns>
410410
<remarks>To be added.</remarks>
411411
</Docs>

xml/System.Numerics/INumberBase`1.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,10 +1177,10 @@ For <xref:System.Numerics.IFloatingPointIeee754%601> this method matches the IEE
11771177
<Parameter Name="provider" Type="System.IFormatProvider" Index="1" FrameworkAlternate="net-8.0" />
11781178
</Parameters>
11791179
<Docs>
1180-
<param name="utf8Text">To be added.</param>
1181-
<param name="provider">To be added.</param>
1182-
<summary>To be added.</summary>
1183-
<returns>To be added.</returns>
1180+
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
1181+
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
1182+
<summary>Parses a span of UTF-8 characters into a value.</summary>
1183+
<returns>The result of parsing <paramref name="utf8Text" />.</returns>
11841184
<remarks>To be added.</remarks>
11851185
</Docs>
11861186
</Member>
@@ -1215,11 +1215,12 @@ For <xref:System.Numerics.IFloatingPointIeee754%601> this method matches the IEE
12151215
</Parameter>
12161216
</Parameters>
12171217
<Docs>
1218-
<param name="utf8Text">To be added.</param>
1219-
<param name="provider">To be added.</param>
1220-
<param name="result">To be added.</param>
1221-
<summary>To be added.</summary>
1222-
<returns>To be added.</returns>
1218+
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
1219+
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
1220+
<param name="result">On return, contains the result of successfully parsing <paramref name="utf8Text" /> or an undefined value on failure.</param>
1221+
<summary>Tries to parse a span of UTF-8 characters into a value.</summary>
1222+
<returns>
1223+
<see langword="true" /> if <paramref name="utf8Text" /> was successfully parsed; otherwise, <see langword="false" />.</returns>
12231224
<remarks>To be added.</remarks>
12241225
</Docs>
12251226
</Member>

xml/System.Reflection.Metadata/CustomAttribute.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@
3131
</Attribute>
3232
</Attributes>
3333
<Docs>
34-
<summary>To be added.</summary>
35-
<remarks>To be added.</remarks>
34+
<summary>Provides information about a custom attribute.</summary>
35+
<remarks>
36+
<format type="text/markdown"><![CDATA[
37+
38+
## Remarks
39+
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/).
40+
41+
## Examples
42+
This example shows how to print all custom attributes applied to the type definition:
43+
44+
:::code language="csharp" source="~/snippets/csharp/System.Reflection.Metadata/CustomAttribute/Overview/CustomAttributeSnippets.cs" id="SnippetPrintAttributes":::
45+
46+
]]></format>
47+
</remarks>
3648
</Docs>
3749
<Members>
3850
<Member MemberName="Constructor">

xml/System.Runtime.InteropServices/NFloat.xml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ This computes `cos(x * π)`.
13081308
<summary>To be added.</summary>
13091309
<returns>To be added.</returns>
13101310
<remarks>To be added.</remarks>
1311+
<inheritdoc cref="M:System.Numerics.ITrigonometricFunctions`1.DegreesToRadians(`0)" />
13111312
</Docs>
13121313
</Member>
13131314
<Member MemberName="E">
@@ -4540,11 +4541,12 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
45404541
</Parameter>
45414542
</Parameters>
45424543
<Docs>
4543-
<param name="utf8Text">To be added.</param>
4544-
<param name="provider">To be added.</param>
4545-
<summary>To be added.</summary>
4546-
<returns>To be added.</returns>
4544+
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
4545+
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
4546+
<summary>Parses a span of UTF-8 characters into a value.</summary>
4547+
<returns>The result of parsing <paramref name="utf8Text" />.</returns>
45474548
<remarks>To be added.</remarks>
4549+
<inheritdoc cref="M:System.IUtf8SpanParsable`1.Parse(System.ReadOnlySpan{System.Byte},System.IFormatProvider)" />
45484550
</Docs>
45494551
</Member>
45504552
<Member MemberName="Parse">
@@ -4714,6 +4716,7 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
47144716
<summary>To be added.</summary>
47154717
<returns>To be added.</returns>
47164718
<remarks>To be added.</remarks>
4719+
<inheritdoc cref="M:System.Numerics.INumberBase`1.Parse(System.ReadOnlySpan{System.Byte},System.Globalization.NumberStyles,System.IFormatProvider)" />
47174720
</Docs>
47184721
</Member>
47194722
<Member MemberName="Parse">
@@ -4929,6 +4932,7 @@ For <xref:System.Numerics.IFloatingPoint%601> this method matches the IEEE 754:2
49294932
<summary>To be added.</summary>
49304933
<returns>To be added.</returns>
49314934
<remarks>To be added.</remarks>
4935+
<inheritdoc cref="M:System.Numerics.ITrigonometricFunctions`1.RadiansToDegrees(`0)" />
49324936
</Docs>
49334937
</Member>
49344938
<Member MemberName="ReciprocalEstimate">
@@ -7025,10 +7029,11 @@ This computes `tan(x * π)`.
70257029
<Parameter Name="result" Type="System.Runtime.InteropServices.NFloat" RefType="out" Index="1" FrameworkAlternate="net-8.0" />
70267030
</Parameters>
70277031
<Docs>
7028-
<param name="utf8Text">To be added.</param>
7029-
<param name="result">To be added.</param>
7030-
<summary>To be added.</summary>
7031-
<returns>To be added.</returns>
7032+
<param name="utf8Text">A read-only UTF-8 character span that contains the number to convert.</param>
7033+
<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>
7034+
<summary>Tries to convert a UTF-8 character span containing the string representation of a number to its floating-point number equivalent.</summary>
7035+
<returns>
7036+
<see langword="true" /> if <paramref name="utf8Text" /> was converted successfully; otherwise, <see langword="false" />.</returns>
70327037
<remarks>To be added.</remarks>
70337038
</Docs>
70347039
</Member>
@@ -7131,12 +7136,14 @@ This computes `tan(x * π)`.
71317136
<Parameter Name="result" Type="System.Runtime.InteropServices.NFloat" RefType="out" Index="2" FrameworkAlternate="net-8.0" />
71327137
</Parameters>
71337138
<Docs>
7134-
<param name="utf8Text">To be added.</param>
7135-
<param name="provider">To be added.</param>
7136-
<param name="result">To be added.</param>
7137-
<summary>To be added.</summary>
7138-
<returns>To be added.</returns>
7139+
<param name="utf8Text">The span of UTF-8 characters to parse.</param>
7140+
<param name="provider">An object that provides culture-specific formatting information about <paramref name="utf8Text" />.</param>
7141+
<param name="result">On return, contains the result of successfully parsing <paramref name="utf8Text" /> or an undefined value on failure.</param>
7142+
<summary>Tries to parse a span of UTF-8 characters into a value.</summary>
7143+
<returns>
7144+
<see langword="true" /> if <paramref name="utf8Text" /> was successfully parsed; otherwise, <see langword="false" />.</returns>
71397145
<remarks>To be added.</remarks>
7146+
<inheritdoc cref="M:System.IUtf8SpanParsable`1.TryParse(System.ReadOnlySpan{System.Byte},System.IFormatProvider,`0@)" />
71407147
</Docs>
71417148
</Member>
71427149
<Member MemberName="TryParse">
@@ -7259,6 +7266,7 @@ This computes `tan(x * π)`.
72597266
<summary>To be added.</summary>
72607267
<returns>To be added.</returns>
72617268
<remarks>To be added.</remarks>
7269+
<inheritdoc cref="M:System.Numerics.INumberBase`1.TryParse(System.ReadOnlySpan{System.Byte},System.Globalization.NumberStyles,System.IFormatProvider,`0@)" />
72627270
</Docs>
72637271
</Member>
72647272
<Member MemberName="TryParse">

xml/System.Threading/ThreadPool.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,9 @@ If a thread pool implementation may have different types of work items, the coun
12681268
12691269
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.
12701270
1271+
> [!NOTE]
1272+
> 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.
1273+
12711274
]]></format>
12721275
</remarks>
12731276
<altmember cref="M:System.Threading.ThreadPool.GetMaxThreads(System.Int32@,System.Int32@)" />

0 commit comments

Comments
 (0)