Repository: alloy-framework/alloy
Pull request #205 (2025-06-18 18:34:33)

[csharp] Add doc support for class members
Noticed that this was still needed, similar to classMethods and such


github-actions[bot]: <!--chronus-github-change-commenter-->
All changed packages have been documented.
 - :white_check_mark: `@alloy-js/csharp`

<details>
<summary>Show changes</summary>

### `@alloy-js/csharp` - _fix_ [✏️](https://github.com/maorleger/alloy/edit/class-member-docs/.chronus/changes/class-member-docs-2025-5-18-18-33-47.md?pr=/alloy-framework/alloy/pull/205)
> Add doc support to class members
</details>

pkg-pr-new[bot]: 
[Open in StackBlitz](https://pkg.pr.new/template/f10ba3eb-3200-48d0-ae5a-c0e256e14703)


<details><summary><b>@alloy-js/babel-plugin</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/babel-plugin@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/babel-plugin-jsx-dom-expressions</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/babel-plugin-jsx-dom-expressions@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/babel-preset</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/babel-preset@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/cli</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/cli@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/core</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/core@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/create</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/create@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/csharp</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/csharp@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/java</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/java@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/json</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/json@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/markdown</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/markdown@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/prettier-plugin-alloy</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/prettier-plugin-alloy@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/rollup-plugin</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/rollup-plugin@205
```

</p></details>
      
    

<details><summary><b>@alloy-js/typescript</b></summary><p>

```
npm i https://pkg.pr.new/alloy-framework/alloy/@alloy-js/typescript@205
```

</p></details>
      
    

_commit: <a href="https://github.com/alloy-framework/alloy/runs/44365563593"><code>c3d94b2</code></a>_


Patch:
diff --git a/.chronus/changes/class-member-docs-2025-5-18-18-33-47.md b/.chronus/changes/class-member-docs-2025-5-18-18-33-47.md
new file mode 100644
index 0000000..bc56bbe
--- /dev/null
+++ b/.chronus/changes/class-member-docs-2025-5-18-18-33-47.md
@@ -0,0 +1,7 @@
+---
+changeKind: fix
+packages:
+  - "@alloy-js/csharp"
+---
+
+Add doc support to class members
\ No newline at end of file
diff --git a/packages/csharp/src/components/ClassDeclaration.tsx b/packages/csharp/src/components/ClassDeclaration.tsx
index 53a2f9c..c1a2e03 100644
--- a/packages/csharp/src/components/ClassDeclaration.tsx
+++ b/packages/csharp/src/components/ClassDeclaration.tsx
@@ -170,6 +170,8 @@ export interface ClassMemberProps extends AccessModifiers {
   name: string;
   type: core.Children;
   refkey?: core.Refkey;
+  /** Doc comment */
+  doc?: core.Children;
 }
 
 // a C# class member (i.e. a field within a class like "private int count")
@@ -194,6 +196,7 @@ export function ClassMember(props: ClassMemberProps) {
   const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
   return (
     <core.Declaration symbol={memberSymbol}>
+      <DocWhen doc={props.doc} />
       {modifiers}
       {props.type} <Name />
     </core.Declaration>


Test patch:
diff --git a/packages/csharp/test/class.test.tsx b/packages/csharp/test/class-declaration.test.tsx
similarity index 93%
rename from packages/csharp/test/class.test.tsx
rename to packages/csharp/test/class-declaration.test.tsx
index 31b940e..932085b 100644
--- a/packages/csharp/test/class.test.tsx
+++ b/packages/csharp/test/class-declaration.test.tsx
@@ -2,8 +2,8 @@ import * as core from "@alloy-js/core";
 import * as coretest from "@alloy-js/core/testing";
 import { describe, expect, it } from "vitest";
 import * as csharp from "../src/index.js";
-import { ClassDeclaration } from "../src/index.js";
-import * as utils from "./utils.js";
+import { ClassDeclaration, ClassMember } from "../src/index.js";
+import * as utils from "./utils.jsx";
 
 it("declares class with no members", () => {
   expect(
@@ -310,3 +310,20 @@ it("specify doc comment", () => {
     class Test;
   `);
 });
+
+it("supports class member doc comments", () => {
+  expect(
+    <utils.TestNamespace>
+      <ClassDeclaration name="Test" doc="This is a test">
+        <ClassMember name="Member" public type="int" doc="This is a member" />
+      </ClassDeclaration>
+    </utils.TestNamespace>,
+  ).toRenderTo(`
+    /// This is a test
+    class Test
+    {
+      /// This is a member
+      public int Member
+    }
+  `);
+});