@alloy-js/csharp 0.18.0-dev.6 → 0.18.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +2 -0
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +6 -1
  4. package/dist/src/components/ClassMethod.d.ts +11 -2
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +11 -2
  7. package/dist/src/components/doc/comment.d.ts +69 -0
  8. package/dist/src/components/doc/comment.d.ts.map +1 -0
  9. package/dist/src/components/doc/comment.js +71 -0
  10. package/dist/src/components/doc/comment.test.d.ts +2 -0
  11. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  12. package/dist/src/components/doc/comment.test.js +338 -0
  13. package/dist/src/components/index.d.ts +3 -1
  14. package/dist/src/components/index.d.ts.map +1 -1
  15. package/dist/src/components/index.js +3 -1
  16. package/dist/src/components/interface/declaration.d.ts +34 -0
  17. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  18. package/dist/src/components/interface/declaration.js +90 -0
  19. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  20. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  21. package/dist/src/components/interface/declaration.test.js +69 -0
  22. package/dist/src/components/interface/method.d.ts +18 -0
  23. package/dist/src/components/interface/method.d.ts.map +1 -0
  24. package/dist/src/components/interface/method.js +59 -0
  25. package/dist/src/components/interface/method.test.d.ts +2 -0
  26. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  27. package/dist/src/components/interface/method.test.js +131 -0
  28. package/dist/src/components/interface/property.d.ts +21 -0
  29. package/dist/src/components/interface/property.d.ts.map +1 -0
  30. package/dist/src/components/interface/property.js +59 -0
  31. package/dist/src/components/interface/property.test.d.ts +2 -0
  32. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  33. package/dist/src/components/interface/property.test.js +165 -0
  34. package/dist/src/modifiers.d.ts +0 -8
  35. package/dist/src/modifiers.d.ts.map +1 -1
  36. package/dist/src/modifiers.js +0 -4
  37. package/dist/src/name-policy.d.ts +1 -1
  38. package/dist/src/name-policy.d.ts.map +1 -1
  39. package/dist/src/name-policy.js +1 -0
  40. package/dist/test/class-method.test.js +21 -0
  41. package/dist/test/class.test.js +13 -0
  42. package/dist/test/vitest.setup.d.ts +2 -0
  43. package/dist/test/vitest.setup.d.ts.map +1 -0
  44. package/dist/test/vitest.setup.js +1 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +2 -2
  47. package/src/components/ClassDeclaration.tsx +4 -0
  48. package/src/components/ClassMethod.tsx +24 -3
  49. package/src/components/doc/comment.test.tsx +336 -0
  50. package/src/components/doc/comment.tsx +122 -0
  51. package/src/components/index.ts +3 -1
  52. package/src/components/interface/declaration.test.tsx +56 -0
  53. package/src/components/interface/declaration.tsx +109 -0
  54. package/src/components/interface/method.test.tsx +120 -0
  55. package/src/components/interface/method.tsx +82 -0
  56. package/src/components/interface/property.test.tsx +144 -0
  57. package/src/components/interface/property.tsx +90 -0
  58. package/src/modifiers.ts +0 -15
  59. package/src/name-policy.ts +2 -0
  60. package/temp/api.json +699 -81
  61. package/test/class-method.test.tsx +16 -0
  62. package/test/class.test.tsx +11 -0
  63. package/test/vitest.setup.ts +1 -0
  64. package/vitest.config.ts +3 -0
@@ -11,16 +11,33 @@ import {
11
11
  computeModifiersPrefix,
12
12
  getAccessModifier,
13
13
  getAsyncModifier,
14
- getMethodModifier,
15
- MethodModifiers,
14
+ makeModifiers,
16
15
  } from "../modifiers.js";
17
16
  import { useCSharpNamePolicy } from "../name-policy.js";
18
17
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
19
18
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
20
19
  import { ParameterProps, Parameters } from "./Parameters.jsx";
20
+ import { DocWhen } from "./doc/comment.jsx";
21
+
22
+ /** Method modifiers. Can only be one. */
23
+ export interface ClassMethodModifiers {
24
+ readonly abstract?: boolean;
25
+ readonly sealed?: boolean;
26
+ readonly static?: boolean;
27
+ readonly virtual?: boolean;
28
+ }
29
+
30
+ const getMethodModifier = makeModifiers<ClassMethodModifiers>([
31
+ "abstract",
32
+ "sealed",
33
+ "static",
34
+ "virtual",
35
+ ]);
21
36
 
22
37
  // properties for creating a method
23
- export interface ClassMethodProps extends AccessModifiers, MethodModifiers {
38
+ export interface ClassMethodProps
39
+ extends AccessModifiers,
40
+ ClassMethodModifiers {
24
41
  name: string;
25
42
  refkey?: Refkey;
26
43
  children?: Children;
@@ -31,6 +48,9 @@ export interface ClassMethodProps extends AccessModifiers, MethodModifiers {
31
48
  * If true, the method will be declared as an async method.
32
49
  */
33
50
  async?: boolean;
51
+
52
+ /** Doc comment */
53
+ doc?: Children;
34
54
  }
35
55
 
36
56
  // a C# class method
@@ -64,6 +84,7 @@ export function ClassMethod(props: ClassMethodProps) {
64
84
  return (
65
85
  <MemberDeclaration symbol={methodSymbol}>
66
86
  <Scope value={methodScope}>
87
+ <DocWhen doc={props.doc} />
67
88
  {modifiers}
68
89
  {returns} {name}({params})
69
90
  {props.abstract ? ";" : <Block newline>{props.children}</Block>}
@@ -0,0 +1,336 @@
1
+ import { expect, it } from "vitest";
2
+ import {
3
+ DocC,
4
+ DocCode,
5
+ DocComment,
6
+ DocCompletionList,
7
+ DocDescription,
8
+ DocExample,
9
+ DocException,
10
+ DocInclude,
11
+ DocItem,
12
+ DocList,
13
+ DocPara,
14
+ DocParam,
15
+ DocParamRef,
16
+ DocPermission,
17
+ DocRemarks,
18
+ DocResponse,
19
+ DocReturns,
20
+ DocSee,
21
+ DocSeeAlso,
22
+ DocSummary,
23
+ DocTerm,
24
+ DocTypeParam,
25
+ DocTypeParamRef,
26
+ DocValue,
27
+ } from "./comment.jsx";
28
+
29
+ it("define summary", () => {
30
+ expect(
31
+ <DocComment>
32
+ <DocSummary>This is a sample doc comment</DocSummary>
33
+ </DocComment>,
34
+ ).toRenderTo(`
35
+ /// <summary>
36
+ /// This is a sample doc comment
37
+ /// </summary>
38
+ `);
39
+ });
40
+
41
+ it("define code", () => {
42
+ expect(
43
+ <DocComment>
44
+ <DocCode>code sample</DocCode>
45
+ </DocComment>,
46
+ ).toRenderTo(`
47
+ /// <code>
48
+ /// code sample
49
+ /// </code>
50
+ `);
51
+ });
52
+
53
+ it("define c", () => {
54
+ expect(
55
+ <DocComment>
56
+ <DocC>inline code</DocC>
57
+ </DocComment>,
58
+ ).toRenderTo(`
59
+ /// <c>
60
+ /// inline code
61
+ /// </c>
62
+ `);
63
+ });
64
+
65
+ it("define example", () => {
66
+ expect(
67
+ <DocComment>
68
+ <DocExample>example usage</DocExample>
69
+ </DocComment>,
70
+ ).toRenderTo(`
71
+ /// <example>
72
+ /// example usage
73
+ /// </example>
74
+ `);
75
+ });
76
+
77
+ it("define exception", () => {
78
+ expect(
79
+ <DocComment>
80
+ <DocException>exception info</DocException>
81
+ </DocComment>,
82
+ ).toRenderTo(`
83
+ /// <exception>
84
+ /// exception info
85
+ /// </exception>
86
+ `);
87
+ });
88
+
89
+ it("define include", () => {
90
+ expect(
91
+ <DocComment>
92
+ <>{DocInclude({ file: "external.xml", path: "/doc/summary" })}</>
93
+ </DocComment>,
94
+ ).toRenderTo(`
95
+ /// <include file="external.xml" path="/doc/summary" />
96
+ `);
97
+ });
98
+
99
+ it("define param", () => {
100
+ expect(
101
+ <DocComment>
102
+ <DocParam name="x">parameter x</DocParam>
103
+ </DocComment>,
104
+ ).toRenderTo(`
105
+ /// <param name="x">parameter x</param>
106
+ `);
107
+ });
108
+
109
+ it("define typeparam", () => {
110
+ expect(
111
+ <DocComment>
112
+ <DocTypeParam name="T">type parameter T</DocTypeParam>
113
+ </DocComment>,
114
+ ).toRenderTo(`
115
+ /// <typeparam name="T">type parameter T</typeparam>
116
+ `);
117
+ });
118
+
119
+ it("define returns", () => {
120
+ expect(
121
+ <DocComment>
122
+ <DocReturns>return value</DocReturns>
123
+ </DocComment>,
124
+ ).toRenderTo(`
125
+ /// <returns>
126
+ /// return value
127
+ /// </returns>
128
+ `);
129
+ });
130
+
131
+ it("define remarks", () => {
132
+ expect(
133
+ <DocComment>
134
+ <DocRemarks>remarks here</DocRemarks>
135
+ </DocComment>,
136
+ ).toRenderTo(`
137
+ /// <remarks>
138
+ /// remarks here
139
+ /// </remarks>
140
+ `);
141
+ });
142
+
143
+ it("define value", () => {
144
+ expect(
145
+ <DocComment>
146
+ <DocValue>property value</DocValue>
147
+ </DocComment>,
148
+ ).toRenderTo(`
149
+ /// <value>
150
+ /// property value
151
+ /// </value>
152
+ `);
153
+ });
154
+
155
+ it("define permission", () => {
156
+ expect(
157
+ <DocComment>
158
+ <DocPermission>permission info</DocPermission>
159
+ </DocComment>,
160
+ ).toRenderTo(`
161
+ /// <permission>
162
+ /// permission info
163
+ /// </permission>
164
+ `);
165
+ });
166
+
167
+ it("define response", () => {
168
+ expect(
169
+ <DocComment>
170
+ <DocResponse>response info</DocResponse>
171
+ </DocComment>,
172
+ ).toRenderTo(`
173
+ /// <response>
174
+ /// response info
175
+ /// </response>
176
+ `);
177
+ });
178
+
179
+ it("define completionlist", () => {
180
+ expect(
181
+ <DocComment>
182
+ <DocCompletionList>completion list</DocCompletionList>
183
+ </DocComment>,
184
+ ).toRenderTo(`
185
+ /// <completionlist>
186
+ /// completion list
187
+ /// </completionlist>
188
+ `);
189
+ });
190
+
191
+ it("define list", () => {
192
+ expect(
193
+ <DocComment>
194
+ <DocList>list content</DocList>
195
+ </DocComment>,
196
+ ).toRenderTo(`
197
+ /// <list>
198
+ /// list content
199
+ /// </list>
200
+ `);
201
+ });
202
+
203
+ it("define item", () => {
204
+ expect(
205
+ <DocComment>
206
+ <DocItem>item content</DocItem>
207
+ </DocComment>,
208
+ ).toRenderTo(`
209
+ /// <item>
210
+ /// item content
211
+ /// </item>
212
+ `);
213
+ });
214
+
215
+ it("define term", () => {
216
+ expect(
217
+ <DocComment>
218
+ <DocTerm>term content</DocTerm>
219
+ </DocComment>,
220
+ ).toRenderTo(`
221
+ /// <term>
222
+ /// term content
223
+ /// </term>
224
+ `);
225
+ });
226
+
227
+ it("define description", () => {
228
+ expect(
229
+ <DocComment>
230
+ <DocDescription>description content</DocDescription>
231
+ </DocComment>,
232
+ ).toRenderTo(`
233
+ /// <description>
234
+ /// description content
235
+ /// </description>
236
+ `);
237
+ });
238
+
239
+ it("define para", () => {
240
+ expect(
241
+ <DocComment>
242
+ <DocPara>paragraph content</DocPara>
243
+ </DocComment>,
244
+ ).toRenderTo(`
245
+ /// <para>
246
+ /// paragraph content
247
+ /// </para>
248
+ `);
249
+ });
250
+
251
+ it("define see", () => {
252
+ expect(
253
+ <DocComment>
254
+ <>{DocSee({ cref: "T:MyType" })}</>
255
+ </DocComment>,
256
+ ).toRenderTo(`
257
+ /// <see cref="T:MyType" />
258
+ `);
259
+ });
260
+
261
+ it("define seealso", () => {
262
+ expect(
263
+ <DocComment>
264
+ <>{DocSeeAlso({ cref: "T:OtherType" })}</>
265
+ </DocComment>,
266
+ ).toRenderTo(`
267
+ /// <seealso cref="T:OtherType" />
268
+ `);
269
+ });
270
+
271
+ it("define paramref", () => {
272
+ expect(
273
+ <DocComment>
274
+ <>{DocParamRef({ name: "x" })}</>
275
+ </DocComment>,
276
+ ).toRenderTo(`
277
+ /// <paramref name="x" />
278
+ `);
279
+ });
280
+
281
+ it("define typeparamref", () => {
282
+ expect(
283
+ <DocComment>
284
+ <>{DocTypeParamRef({ name: "T" })}</>
285
+ </DocComment>,
286
+ ).toRenderTo(`
287
+ /// <typeparamref name="T" />
288
+ `);
289
+ });
290
+
291
+ it("wrap long summary", () => {
292
+ expect(
293
+ <DocComment>
294
+ <DocSummary>
295
+ This is a very long sample doc comment that exceeds the typical line
296
+ length limit and should be wrapped appropriately in the generated
297
+ documentation.
298
+ </DocSummary>
299
+ </DocComment>,
300
+ ).toRenderTo(`
301
+ /// <summary>
302
+ /// This is a very long sample doc comment that exceeds the typical line length limit
303
+ /// and should be wrapped appropriately in the generated documentation.
304
+ /// </summary>
305
+ `);
306
+ });
307
+
308
+ it("combine multiple tags", () => {
309
+ expect(
310
+ <DocComment>
311
+ <DocSummary>
312
+ This operator determines whether two Points have the same location.
313
+ </DocSummary>
314
+ <DocParam name="p1">The first Point to be compared.</DocParam>
315
+ <DocParam name="p2">The second Point to be compared.</DocParam>
316
+ <DocReturns>
317
+ True if the Points do not have the same location and the exact same
318
+ type; otherwise, false.
319
+ </DocReturns>
320
+ <DocSeeAlso cref="Equals" />
321
+ <DocSeeAlso cref="operator==" />
322
+ </DocComment>,
323
+ ).toRenderTo(`
324
+ /// <summary>
325
+ /// This operator determines whether two Points have the same location.
326
+ /// </summary>
327
+ /// <param name="p1">The first Point to be compared.</param>
328
+ /// <param name="p2">The second Point to be compared.</param>
329
+ /// <returns>
330
+ /// True if the Points do not have the same location and the exact same type; otherwise,
331
+ /// false.
332
+ /// </returns>
333
+ /// <seealso cref="Equals" />
334
+ /// <seealso cref="operator==" />
335
+ `);
336
+ });
@@ -0,0 +1,122 @@
1
+ import { Children, code, List, Prose, Show } from "@alloy-js/core";
2
+
3
+ export interface DocCommentProps {
4
+ children: Children;
5
+ }
6
+
7
+ export function DocComment(props: DocCommentProps) {
8
+ return (
9
+ <>
10
+ {"/// "}
11
+ <align string="/// ">
12
+ <List>{props.children}</List>
13
+ </align>
14
+ </>
15
+ );
16
+ }
17
+
18
+ export interface DocWhenProps {
19
+ doc: Children | undefined;
20
+ }
21
+
22
+ /** Conditionally render the given doc in a <DocComment /> component and tail with a line */
23
+ export function DocWhen(props: DocWhenProps) {
24
+ return (
25
+ <Show when={Boolean(props.doc)}>
26
+ <DocComment children={props.doc} />
27
+ <hbr />
28
+ </Show>
29
+ );
30
+ }
31
+
32
+ export interface DocCommentTagProps {
33
+ children: Children;
34
+ }
35
+
36
+ export function makeDocCommentTag(name: string) {
37
+ return function DocCommentTag(props: DocCommentProps) {
38
+ return (
39
+ <Prose>
40
+ {code`
41
+ <${name}>
42
+ ${props.children}
43
+ </${name}>`}
44
+ </Prose>
45
+ );
46
+ };
47
+ }
48
+ export function makeInlineDocCommentTag(name: string) {
49
+ return function DocCommentTag(props: DocCommentProps) {
50
+ return `<${name}>${props.children}</${name}>`;
51
+ };
52
+ }
53
+
54
+ export const DocSummary = makeDocCommentTag("summary");
55
+ export const DocCode = makeDocCommentTag("code");
56
+ export const DocC = makeDocCommentTag("c");
57
+ export const DocExample = makeDocCommentTag("example");
58
+ export const DocException = makeDocCommentTag("exception");
59
+
60
+ export interface DocIncludeProps {
61
+ /** is the file name of an external XML file. The file name is interpreted relative to the file that contains the include tag. */
62
+ file: string;
63
+ /** is an XPath expression that selects some of the XML in the external XML file. */
64
+ path?: string;
65
+ }
66
+ export const DocInclude = (props: DocIncludeProps) => {
67
+ return `<include file="${props.file}" path="${props.path}" />`;
68
+ };
69
+
70
+ export interface DocParamProps {
71
+ name: string;
72
+ children: Children;
73
+ }
74
+ export const DocParam = (props: DocParamProps) =>
75
+ code`<param name="${props.name}">${props.children}</param>`;
76
+
77
+ export interface DocTypeParamProps {
78
+ name: string;
79
+ children: Children;
80
+ }
81
+ export const DocTypeParam = (props: DocTypeParamProps) =>
82
+ code`<typeparam name="${props.name}">${props.children}</typeparam>`;
83
+
84
+ export const DocReturns = makeDocCommentTag("returns");
85
+ export const DocRemarks = makeDocCommentTag("remarks");
86
+ export const DocValue = makeDocCommentTag("value");
87
+ export const DocPermission = makeDocCommentTag("permission");
88
+ export const DocResponse = makeDocCommentTag("response");
89
+ export const DocCompletionList = makeDocCommentTag("completionlist");
90
+ export const DocList = makeDocCommentTag("list");
91
+ export const DocItem = makeDocCommentTag("item");
92
+ export const DocTerm = makeDocCommentTag("term");
93
+ export const DocDescription = makeDocCommentTag("description");
94
+ export const DocPara = makeDocCommentTag("para");
95
+
96
+ export interface DocSeeProps {
97
+ cref: string;
98
+ langword?: string;
99
+ children?: Children;
100
+ }
101
+ export const DocSee = (props: DocSeeProps) =>
102
+ `<see cref="${props.cref}"${props.langword ? ` langword="${props.langword}"` : ""}${props.children ? `>${props.children}</see>` : " />"}`;
103
+
104
+ export interface DocSeeAlsoProps {
105
+ cref: string;
106
+ langword?: string;
107
+ children?: Children;
108
+ }
109
+ export const DocSeeAlso = (props: DocSeeAlsoProps) =>
110
+ `<seealso cref="${props.cref}"${props.langword ? ` langword="${props.langword}"` : ""}${props.children ? `>${props.children}</seealso>` : " />"}`;
111
+
112
+ export interface DocParamRefProps {
113
+ name: string;
114
+ }
115
+ export const DocParamRef = (props: DocParamRefProps) =>
116
+ `<paramref name="${props.name}" />`;
117
+
118
+ export interface DocTypeParamRefProps {
119
+ name: string;
120
+ }
121
+ export const DocTypeParamRef = (props: DocTypeParamRefProps) =>
122
+ `<typeparamref name="${props.name}" />`;
@@ -1,7 +1,9 @@
1
1
  export * from "./ClassDeclaration.jsx";
2
- export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
2
+ export * from "./ClassMethod.jsx";
3
3
  export * from "./Declaration.js";
4
4
  export * from "./EnumDeclaration.jsx";
5
+ export * from "./interface/declaration.js";
6
+ export * from "./interface/method.js";
5
7
  export * from "./Name.js";
6
8
  export * from "./Namespace.js";
7
9
  export * from "./Parameters.js";
@@ -0,0 +1,56 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TestNamespace } from "../../../test/utils.jsx";
3
+ import { InterfaceDeclaration } from "./declaration.jsx";
4
+
5
+ it("declares class with no members", () => {
6
+ expect(
7
+ <TestNamespace>
8
+ <InterfaceDeclaration name="TestInterface" />
9
+ </TestNamespace>,
10
+ ).toRenderTo(`
11
+ interface TestInterface;
12
+ `);
13
+ });
14
+
15
+ describe("modifiers", () => {
16
+ it.each(["public", "private", "internal"])("%s", (mod) => {
17
+ expect(
18
+ <TestNamespace>
19
+ <InterfaceDeclaration {...{ [mod]: true }} name="TestInterface" />
20
+ </TestNamespace>,
21
+ ).toRenderTo(`
22
+ ${mod} interface TestInterface;
23
+ `);
24
+ });
25
+
26
+ it.each(["partial"])("%s", (mod) => {
27
+ expect(
28
+ <TestNamespace>
29
+ <InterfaceDeclaration {...{ [mod]: true }} name="TestInterface" />
30
+ </TestNamespace>,
31
+ ).toRenderTo(`
32
+ ${mod} interface TestInterface;
33
+ `);
34
+ });
35
+
36
+ it("combines modifiers", () => {
37
+ expect(
38
+ <TestNamespace>
39
+ <InterfaceDeclaration public partial name="TestInterface" />
40
+ </TestNamespace>,
41
+ ).toRenderTo(`
42
+ public partial interface TestInterface;
43
+ `);
44
+ });
45
+ });
46
+
47
+ it("specify doc comment", () => {
48
+ expect(
49
+ <TestNamespace>
50
+ <InterfaceDeclaration name="TestInterface" doc="This is a test" />
51
+ </TestNamespace>,
52
+ ).toRenderTo(`
53
+ /// This is a test
54
+ interface TestInterface;
55
+ `);
56
+ });
@@ -0,0 +1,109 @@
1
+ import * as core from "@alloy-js/core";
2
+ import {
3
+ AccessModifiers,
4
+ computeModifiersPrefix,
5
+ getAccessModifier,
6
+ makeModifiers,
7
+ } from "../../modifiers.js";
8
+ import { useCSharpNamePolicy } from "../../name-policy.js";
9
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
10
+ import { CSharpMemberScope } from "../../symbols/scopes.js";
11
+ import { DocWhen } from "../doc/comment.jsx";
12
+ import { Name } from "../Name.jsx";
13
+
14
+ export interface InterfaceModifiers {
15
+ readonly partial?: boolean;
16
+ }
17
+
18
+ const getInterfaceModifiers = makeModifiers<InterfaceModifiers>(["partial"]);
19
+
20
+ // properties for creating a class
21
+ export interface InterfaceDeclarationProps
22
+ extends Omit<core.DeclarationProps, "nameKind">,
23
+ AccessModifiers,
24
+ InterfaceModifiers {
25
+ name: string;
26
+
27
+ /** Doc comment */
28
+ doc?: core.Children;
29
+ refkey?: core.Refkey;
30
+ typeParameters?: Record<string, core.Refkey>;
31
+ }
32
+
33
+ /**
34
+ * CSharp interface declaration.
35
+ * @example
36
+ * ```tsx
37
+ * <InterfaceDeclaration public name="IMyInterface">
38
+ * <InterfaceMember public name="MyProperty" type="int" />
39
+ * <InterfaceMethod public name="MyMethod" returnType="void">
40
+ * <Parameter name="value" type="int" />
41
+ * </InterfaceMethod>
42
+ * </InterfaceDeclaration>
43
+ * ```
44
+ * This will produce:
45
+ * ```csharp
46
+ * public interface MyIface
47
+ * {
48
+ * public int MyProperty { get; set; }
49
+ * public void MyMethod(int value);
50
+ * }
51
+ * ```
52
+ */
53
+ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
54
+ const name = useCSharpNamePolicy().getName(props.name!, "interface");
55
+
56
+ const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
57
+ refkeys: props.refkey,
58
+ });
59
+
60
+ // this creates a new scope for the interface definition.
61
+ // members will automatically "inherit" this scope so
62
+ // that refkeys to them will produce the fully-qualified
63
+ // name e.g. Foo.Bar.
64
+ const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
65
+ owner: thisInterfaceSymbol,
66
+ });
67
+
68
+ let typeParams: core.Children;
69
+ if (props.typeParameters) {
70
+ const typeParamNames = new Array<string>();
71
+ for (const entry of Object.entries(props.typeParameters)) {
72
+ typeParamNames.push(
73
+ useCSharpNamePolicy().getName(entry[0], "type-parameter"),
74
+ );
75
+ // create a symbol for each type param so its
76
+ // refkey resolves to the type param's name
77
+ new CSharpOutputSymbol(entry[0], {
78
+ scope: thisInterfaceScope,
79
+ refkeys: entry[1],
80
+ });
81
+ }
82
+ typeParams = (
83
+ <group>
84
+ {"<"}
85
+ <core.For each={typeParamNames} comma line>
86
+ {(name) => name}
87
+ </core.For>
88
+ {">"}
89
+ </group>
90
+ );
91
+ }
92
+
93
+ const modifiers = computeModifiersPrefix([
94
+ getAccessModifier(props),
95
+ getInterfaceModifiers(props),
96
+ ]);
97
+ return (
98
+ <core.Declaration symbol={thisInterfaceSymbol}>
99
+ <DocWhen doc={props.doc} />
100
+ {modifiers}interface <Name />
101
+ {typeParams}
102
+ {props.children ?
103
+ <core.Block newline>
104
+ <core.Scope value={thisInterfaceScope}>{props.children}</core.Scope>
105
+ </core.Block>
106
+ : ";"}
107
+ </core.Declaration>
108
+ );
109
+ }