@alloy-js/csharp 0.18.0-dev.2 → 0.18.0-dev.20

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 (153) hide show
  1. package/LICENSE +7 -0
  2. package/dist/src/components/ClassDeclaration.d.ts +74 -0
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  4. package/dist/src/components/{Class.js → ClassDeclaration.js} +59 -32
  5. package/dist/src/components/ClassMethod.d.ts +25 -4
  6. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  7. package/dist/src/components/ClassMethod.js +22 -3
  8. package/dist/src/components/EnumDeclaration.d.ts +34 -0
  9. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  10. package/dist/src/components/{Enum.js → EnumDeclaration.js} +25 -5
  11. package/dist/src/components/Parameters.d.ts +6 -1
  12. package/dist/src/components/Parameters.d.ts.map +1 -1
  13. package/dist/src/components/Parameters.js +3 -2
  14. package/dist/src/components/doc/comment.d.ts +70 -0
  15. package/dist/src/components/doc/comment.d.ts.map +1 -0
  16. package/dist/src/components/doc/comment.js +88 -0
  17. package/dist/src/components/doc/comment.test.d.ts +2 -0
  18. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  19. package/dist/src/components/doc/comment.test.js +348 -0
  20. package/dist/src/components/doc/from-markdown.d.ts +6 -0
  21. package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
  22. package/dist/src/components/doc/from-markdown.js +58 -0
  23. package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
  24. package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
  25. package/dist/src/components/doc/from-markdown.test.js +83 -0
  26. package/dist/src/components/index.d.ts +12 -3
  27. package/dist/src/components/index.d.ts.map +1 -1
  28. package/dist/src/components/index.js +13 -4
  29. package/dist/src/components/interface/declaration.d.ts +47 -0
  30. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  31. package/dist/src/components/interface/declaration.js +77 -0
  32. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  33. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  34. package/dist/src/components/interface/declaration.test.js +153 -0
  35. package/dist/src/components/interface/method.d.ts +32 -0
  36. package/dist/src/components/interface/method.d.ts.map +1 -0
  37. package/dist/src/components/interface/method.js +69 -0
  38. package/dist/src/components/interface/method.test.d.ts +2 -0
  39. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  40. package/dist/src/components/interface/method.test.js +254 -0
  41. package/dist/src/components/interface/property.d.ts +38 -0
  42. package/dist/src/components/interface/property.d.ts.map +1 -0
  43. package/dist/src/components/interface/property.js +67 -0
  44. package/dist/src/components/interface/property.test.d.ts +2 -0
  45. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  46. package/dist/src/components/interface/property.test.js +165 -0
  47. package/dist/src/components/property/property.d.ts +57 -0
  48. package/dist/src/components/property/property.d.ts.map +1 -0
  49. package/dist/src/components/property/property.js +70 -0
  50. package/dist/src/components/property/property.test.d.ts +2 -0
  51. package/dist/src/components/property/property.test.d.ts.map +1 -0
  52. package/dist/src/components/property/property.test.js +218 -0
  53. package/dist/src/components/record/declaration.d.ts +35 -0
  54. package/dist/src/components/record/declaration.d.ts.map +1 -0
  55. package/dist/src/components/record/declaration.js +90 -0
  56. package/dist/src/components/record/declaration.test.d.ts +2 -0
  57. package/dist/src/components/record/declaration.test.d.ts.map +1 -0
  58. package/dist/src/components/record/declaration.test.js +94 -0
  59. package/dist/src/components/stc/index.d.ts +2 -2
  60. package/dist/src/components/stc/index.d.ts.map +1 -1
  61. package/dist/src/components/stc/index.js +2 -2
  62. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  63. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  64. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  65. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  66. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  67. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  68. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  69. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  70. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  71. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  72. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  73. package/dist/src/components/type-parameters/type-parameters.js +54 -0
  74. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  75. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  76. package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
  77. package/dist/src/components/var/declaration.d.ts +35 -0
  78. package/dist/src/components/var/declaration.d.ts.map +1 -0
  79. package/dist/src/components/var/declaration.js +40 -0
  80. package/dist/src/components/var/declaration.test.d.ts +2 -0
  81. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  82. package/dist/src/components/var/declaration.test.js +73 -0
  83. package/dist/src/modifiers.d.ts +10 -4
  84. package/dist/src/modifiers.d.ts.map +1 -1
  85. package/dist/src/modifiers.js +9 -32
  86. package/dist/src/name-policy.d.ts +1 -1
  87. package/dist/src/name-policy.d.ts.map +1 -1
  88. package/dist/src/name-policy.js +2 -0
  89. package/dist/test/class-declaration.test.d.ts +2 -0
  90. package/dist/test/class-declaration.test.d.ts.map +1 -0
  91. package/dist/test/class-declaration.test.js +463 -0
  92. package/dist/test/class-method.test.js +37 -14
  93. package/dist/test/enum.test.js +12 -12
  94. package/dist/test/namespace.test.js +8 -8
  95. package/dist/test/project-directory.test.d.ts +2 -0
  96. package/dist/test/project-directory.test.d.ts.map +1 -0
  97. package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
  98. package/dist/test/sourcefile.test.js +4 -4
  99. package/dist/test/using.test.js +9 -9
  100. package/dist/test/vitest.setup.d.ts +2 -0
  101. package/dist/test/vitest.setup.d.ts.map +1 -0
  102. package/dist/test/vitest.setup.js +1 -0
  103. package/dist/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +21 -21
  105. package/src/components/{Class.tsx → ClassDeclaration.tsx} +108 -43
  106. package/src/components/ClassMethod.tsx +53 -12
  107. package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
  108. package/src/components/Parameters.tsx +10 -3
  109. package/src/components/doc/comment.test.tsx +337 -0
  110. package/src/components/doc/comment.tsx +152 -0
  111. package/src/components/doc/from-markdown.test.tsx +103 -0
  112. package/src/components/doc/from-markdown.tsx +58 -0
  113. package/src/components/index.ts +12 -3
  114. package/src/components/interface/declaration.test.tsx +143 -0
  115. package/src/components/interface/declaration.tsx +105 -0
  116. package/src/components/interface/method.test.tsx +250 -0
  117. package/src/components/interface/method.tsx +105 -0
  118. package/src/components/interface/property.test.tsx +144 -0
  119. package/src/components/interface/property.tsx +107 -0
  120. package/src/components/property/property.test.tsx +187 -0
  121. package/src/components/property/property.tsx +146 -0
  122. package/src/components/record/declaration.test.tsx +73 -0
  123. package/src/components/record/declaration.tsx +109 -0
  124. package/src/components/stc/index.ts +2 -2
  125. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  126. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  127. package/src/components/type-parameters/type-parameter.tsx +35 -0
  128. package/src/components/type-parameters/type-parameters.test.tsx +46 -0
  129. package/src/components/type-parameters/type-parameters.tsx +63 -0
  130. package/src/components/var/declaration.test.tsx +59 -0
  131. package/src/components/var/declaration.tsx +47 -0
  132. package/src/modifiers.ts +25 -42
  133. package/src/name-policy.ts +5 -0
  134. package/temp/api.json +5227 -685
  135. package/test/class-declaration.test.tsx +418 -0
  136. package/test/class-method.test.tsx +24 -14
  137. package/test/enum.test.tsx +11 -11
  138. package/test/namespace.test.tsx +4 -4
  139. package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
  140. package/test/sourcefile.test.tsx +2 -2
  141. package/test/using.test.tsx +9 -9
  142. package/test/vitest.setup.ts +1 -0
  143. package/vitest.config.ts +3 -0
  144. package/dist/src/components/Class.d.ts +0 -26
  145. package/dist/src/components/Class.d.ts.map +0 -1
  146. package/dist/src/components/Enum.d.ts +0 -15
  147. package/dist/src/components/Enum.d.ts.map +0 -1
  148. package/dist/test/class.test.d.ts +0 -2
  149. package/dist/test/class.test.d.ts.map +0 -1
  150. package/dist/test/class.test.js +0 -298
  151. package/dist/test/projectdirectory.test.d.ts +0 -2
  152. package/dist/test/projectdirectory.test.d.ts.map +0 -1
  153. package/test/class.test.tsx +0 -292
@@ -1,21 +1,91 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { AccessModifier, getAccessModifier } from "../modifiers.js";
2
+ import { join } from "@alloy-js/core";
3
+ import {
4
+ AccessModifiers,
5
+ computeModifiersPrefix,
6
+ getAccessModifier,
7
+ makeModifiers,
8
+ } from "../modifiers.js";
3
9
  import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
4
10
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
5
11
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
6
- import { Name } from "./Name.js";
7
- import { ParameterProps, Parameters } from "./Parameters.js";
12
+ import { Name } from "./Name.jsx";
13
+ import { ParameterProps, Parameters } from "./Parameters.jsx";
14
+ import { DocWhen } from "./doc/comment.jsx";
15
+ import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
16
+ import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
17
+ import { TypeParameters } from "./type-parameters/type-parameters.jsx";
18
+
19
+ export interface ClassModifiers {
20
+ readonly abstract?: boolean;
21
+ readonly partial?: boolean;
22
+ readonly sealed?: boolean;
23
+ readonly static?: boolean;
24
+ }
25
+
26
+ const getClassModifiers = makeModifiers<ClassModifiers>([
27
+ "abstract",
28
+ "partial",
29
+ "sealed",
30
+ "static",
31
+ ]);
8
32
 
9
33
  // properties for creating a class
10
- export interface ClassProps extends Omit<core.DeclarationProps, "nameKind"> {
34
+ export interface ClassDeclarationProps
35
+ extends Omit<core.DeclarationProps, "nameKind">,
36
+ AccessModifiers,
37
+ ClassModifiers {
11
38
  name: string;
39
+ /** Doc comment */
40
+ doc?: core.Children;
12
41
  refkey?: core.Refkey;
13
- accessModifier?: AccessModifier;
14
- typeParameters?: Record<string, core.Refkey>;
42
+
43
+ /**
44
+ * Type parameters for the class
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * <ClassDeclaration name="MyClass" typeParameters={["T"]} />
49
+ * ```
50
+ * This will produce:
51
+ * ```csharp
52
+ * public class MyClass<T>
53
+ * ```
54
+ */
55
+ typeParameters?: (string | TypeParameterProps)[];
56
+
57
+ /** Base class that this class extends */
58
+ baseType?: core.Children;
59
+
60
+ /** Interfaces this class implements */
61
+ interfaceTypes?: core.Children[];
15
62
  }
16
63
 
17
- // a C# class declaration
18
- export function Class(props: ClassProps) {
64
+ /**
65
+ * CSharp class declaration.
66
+ * @example
67
+ * ```tsx
68
+ * <ClassDeclaration public name="MyClass">
69
+ * <ClassMember public name="MyField" type="int" />
70
+ * <ClassConstructor>
71
+ * <Parameter name="value" type="int" />
72
+ * this.MyField = value;
73
+ * </ClassConstructor>
74
+ * </ClassDeclaration>
75
+ * ```
76
+ * This will produce:
77
+ * ```csharp
78
+ * public class MyClass
79
+ * {
80
+ * public int MyField;
81
+ * public MyClass(int value)
82
+ * {
83
+ * this.MyField = value;
84
+ * }
85
+ * }
86
+ * ```
87
+ */
88
+ export function ClassDeclaration(props: ClassDeclarationProps) {
19
89
  const name = useCSharpNamePolicy().getName(props.name!, "class");
20
90
 
21
91
  const thisClassSymbol = new CSharpOutputSymbol(name, {
@@ -30,35 +100,27 @@ export function Class(props: ClassProps) {
30
100
  owner: thisClassSymbol,
31
101
  });
32
102
 
33
- let typeParams: core.Children;
34
- if (props.typeParameters) {
35
- const typeParamNames = new Array<string>();
36
- for (const entry of Object.entries(props.typeParameters)) {
37
- typeParamNames.push(
38
- useCSharpNamePolicy().getName(entry[0], "type-parameter"),
39
- );
40
- // create a symbol for each type param so its
41
- // refkey resolves to the type param's name
42
- new CSharpOutputSymbol(entry[0], {
43
- scope: thisClassScope,
44
- refkeys: entry[1],
45
- });
46
- }
47
- typeParams = (
48
- <group>
49
- {"<"}
50
- <core.For each={typeParamNames} comma line>
51
- {(name) => name}
52
- </core.For>
53
- {">"}
54
- </group>
55
- );
56
- }
57
-
103
+ const bases = [
104
+ ...(props.baseType ? [props.baseType] : []),
105
+ ...(props.interfaceTypes || []),
106
+ ];
107
+ const base =
108
+ bases.length > 0 ? <> : {join(bases, { joiner: ", " })}</> : null;
109
+ const modifiers = computeModifiersPrefix([
110
+ getAccessModifier(props),
111
+ getClassModifiers(props),
112
+ ]);
58
113
  return (
59
114
  <core.Declaration symbol={thisClassSymbol}>
60
- {getAccessModifier(props.accessModifier)}class <Name />
61
- {typeParams}
115
+ <DocWhen doc={props.doc} />
116
+ {modifiers}class <Name />
117
+ {props.typeParameters && (
118
+ <TypeParameters parameters={props.typeParameters} />
119
+ )}
120
+ {base}
121
+ {props.typeParameters && (
122
+ <TypeParameterConstraints parameters={props.typeParameters} />
123
+ )}
62
124
  {!props.children && ";"}
63
125
  {props.children && (
64
126
  <core.Block newline>
@@ -69,8 +131,7 @@ export function Class(props: ClassProps) {
69
131
  );
70
132
  }
71
133
 
72
- export interface ClassConstructorProps {
73
- accessModifier?: AccessModifier;
134
+ export interface ClassConstructorProps extends AccessModifiers {
74
135
  parameters?: Array<ParameterProps>;
75
136
  refkey?: core.Refkey;
76
137
  symbol?: core.OutputSymbol;
@@ -98,7 +159,8 @@ export function ClassConstructor(props: ClassConstructorProps) {
98
159
  owner: ctorSymbol,
99
160
  });
100
161
 
101
- const accessModifier = getAccessModifier(props.accessModifier);
162
+ const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
163
+
102
164
  const params =
103
165
  props.parameters ? <Parameters parameters={props.parameters} /> : "";
104
166
 
@@ -106,7 +168,7 @@ export function ClassConstructor(props: ClassConstructorProps) {
106
168
  return (
107
169
  <core.Declaration symbol={ctorSymbol}>
108
170
  <core.Scope value={ctorDeclScope}>
109
- {accessModifier}
171
+ {modifiers}
110
172
  <Name />({params})<core.Block newline>{props.children}</core.Block>
111
173
  </core.Scope>
112
174
  </core.Declaration>
@@ -114,17 +176,18 @@ export function ClassConstructor(props: ClassConstructorProps) {
114
176
  }
115
177
 
116
178
  // properties for creating a class member
117
- export interface ClassMemberProps {
179
+ export interface ClassMemberProps extends AccessModifiers {
118
180
  name: string;
119
181
  type: core.Children;
120
- accessModifier?: AccessModifier;
121
182
  refkey?: core.Refkey;
183
+ /** Doc comment */
184
+ doc?: core.Children;
122
185
  }
123
186
 
124
187
  // a C# class member (i.e. a field within a class like "private int count")
125
188
  export function ClassMember(props: ClassMemberProps) {
126
189
  let nameElement: CSharpElements = "class-member-private";
127
- if (props.accessModifier === "public") {
190
+ if (props.public) {
128
191
  nameElement = "class-member-public";
129
192
  }
130
193
  const name = useCSharpNamePolicy().getName(props.name, nameElement);
@@ -140,9 +203,11 @@ export function ClassMember(props: ClassMemberProps) {
140
203
  refkeys: props.refkey ?? core.refkey(props.name),
141
204
  });
142
205
 
206
+ const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
143
207
  return (
144
208
  <core.Declaration symbol={memberSymbol}>
145
- {getAccessModifier(props.accessModifier)}
209
+ <DocWhen doc={props.doc} />
210
+ {modifiers}
146
211
  {props.type} <Name />
147
212
  </core.Declaration>
148
213
  );
@@ -7,25 +7,43 @@ import {
7
7
  Scope,
8
8
  } from "@alloy-js/core";
9
9
  import {
10
- AccessModifier,
10
+ AccessModifiers,
11
11
  computeModifiersPrefix,
12
12
  getAccessModifier,
13
13
  getAsyncModifier,
14
- getMethodModifier,
15
- MethodModifier,
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
+ import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
22
+ import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
23
+ import { TypeParameters } from "./type-parameters/type-parameters.jsx";
24
+
25
+ /** Method modifiers. Can only be one. */
26
+ export interface ClassMethodModifiers {
27
+ readonly abstract?: boolean;
28
+ readonly sealed?: boolean;
29
+ readonly static?: boolean;
30
+ readonly virtual?: boolean;
31
+ }
32
+
33
+ const getMethodModifier = makeModifiers<ClassMethodModifiers>([
34
+ "abstract",
35
+ "sealed",
36
+ "static",
37
+ "virtual",
38
+ ]);
21
39
 
22
40
  // properties for creating a method
23
- export interface ClassMethodProps {
41
+ export interface ClassMethodProps
42
+ extends AccessModifiers,
43
+ ClassMethodModifiers {
24
44
  name: string;
25
45
  refkey?: Refkey;
26
46
  children?: Children;
27
- accessModifier?: AccessModifier;
28
- methodModifier?: MethodModifier;
29
47
  parameters?: Array<ParameterProps>;
30
48
  returns?: Children;
31
49
 
@@ -33,6 +51,23 @@ export interface ClassMethodProps {
33
51
  * If true, the method will be declared as an async method.
34
52
  */
35
53
  async?: boolean;
54
+
55
+ /** Doc comment */
56
+ doc?: Children;
57
+
58
+ /**
59
+ * Type parameters for the method
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * <InterfaceMethod name="Test" typeParameters={["T"]} />
64
+ * ```
65
+ * This will produce:
66
+ * ```csharp
67
+ * public void Test<T>()
68
+ * ```
69
+ */
70
+ typeParameters?: (TypeParameterProps | string)[];
36
71
  }
37
72
 
38
73
  // a C# class method
@@ -58,19 +93,25 @@ export function ClassMethod(props: ClassMethodProps) {
58
93
  const returns = props.returns ?? (props.async ? "Task" : "void");
59
94
 
60
95
  const modifiers = computeModifiersPrefix([
61
- getAccessModifier(props.accessModifier),
62
- getMethodModifier(props.methodModifier),
96
+ getAccessModifier(props),
97
+ getMethodModifier(props),
63
98
  getAsyncModifier(props.async),
64
99
  ]);
65
100
  // note that scope wraps the method decl so that the params get the correct scope
66
101
  return (
67
102
  <MemberDeclaration symbol={methodSymbol}>
68
103
  <Scope value={methodScope}>
104
+ <DocWhen doc={props.doc} />
69
105
  {modifiers}
70
- {returns} {name}({params})
71
- {props.methodModifier === "abstract" ?
72
- ";"
73
- : <Block newline>{props.children}</Block>}
106
+ {returns} {name}
107
+ {props.typeParameters && (
108
+ <TypeParameters parameters={props.typeParameters} />
109
+ )}
110
+ ({params})
111
+ {props.typeParameters && (
112
+ <TypeParameterConstraints parameters={props.typeParameters} />
113
+ )}
114
+ {props.abstract ? ";" : <Block newline>{props.children}</Block>}
74
115
  </Scope>
75
116
  </MemberDeclaration>
76
117
  );
@@ -1,20 +1,42 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { AccessModifier, getAccessModifier } from "../modifiers.js";
2
+ import {
3
+ AccessModifiers,
4
+ computeModifiersPrefix,
5
+ getAccessModifier,
6
+ } from "../modifiers.js";
3
7
  import { useCSharpNamePolicy } from "../name-policy.js";
4
8
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
5
9
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
6
10
  import { Name } from "./Name.jsx";
7
11
 
8
12
  // properties for creating an enum
9
- export interface EnumProps {
13
+ export interface EnumDeclarationProps extends AccessModifiers {
10
14
  name: string;
11
15
  refkey?: core.Refkey;
12
16
  children?: core.Children;
13
- accessModifier?: AccessModifier;
14
17
  }
15
18
 
16
- // a C# enum declaration
17
- export function Enum(props: EnumProps) {
19
+ /**
20
+ * A C# enum declaration
21
+ * @example
22
+ * ```tsx
23
+ * <EnumDeclaration public name="Color">
24
+ * <EnumMember name="Red" />
25
+ * <EnumMember name="Green" />
26
+ * <EnumMember name="Blue" />
27
+ * </EnumDeclaration>
28
+ * ```
29
+ * This will produce:
30
+ * ```csharp
31
+ * public enum Color
32
+ * {
33
+ * Red,
34
+ * Green,
35
+ * Blue
36
+ * }
37
+ * ```
38
+ */
39
+ export function EnumDeclaration(props: EnumDeclarationProps) {
18
40
  const name = useCSharpNamePolicy().getName(props.name!, "enum");
19
41
  const scope = useCSharpScope();
20
42
 
@@ -32,10 +54,12 @@ export function Enum(props: EnumProps) {
32
54
  owner: thisEnumSymbol,
33
55
  });
34
56
 
57
+ const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
58
+
35
59
  if (thisEnumScope.owner)
36
60
  return (
37
61
  <core.Declaration symbol={thisEnumSymbol}>
38
- {getAccessModifier(props.accessModifier)}enum <Name />
62
+ {modifiers}enum <Name />
39
63
  {!props.children && ";"}
40
64
  {props.children && (
41
65
  <core.Scope value={thisEnumScope}>
@@ -1,4 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
2
+ import { code } from "@alloy-js/core";
2
3
  import { useCSharpNamePolicy } from "../name-policy.js";
3
4
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
4
5
  import { useCSharpScope } from "../symbols/scopes.js";
@@ -7,11 +8,15 @@ import { Name } from "./Name.js";
7
8
  export interface ParameterProps {
8
9
  name: string;
9
10
  type: core.Children;
11
+ /** If the parmaeter is optional(without default value) */
12
+ optional?: boolean;
13
+ /** Default value for the parameter */
14
+ default?: core.Children;
10
15
  refkey?: core.Refkey;
11
16
  symbol?: core.OutputSymbol;
12
17
  }
13
18
 
14
- // a constructor/method parameter
19
+ /** Define a parameter to be used in class or interface method. */
15
20
  export function Parameter(props: ParameterProps) {
16
21
  const name = useCSharpNamePolicy().getName(props.name, "parameter");
17
22
  const scope = useCSharpScope();
@@ -31,14 +36,16 @@ export function Parameter(props: ParameterProps) {
31
36
 
32
37
  return (
33
38
  <core.Declaration symbol={memberSymbol}>
34
- {props.type} <Name />
39
+ {props.type}
40
+ {props.optional ? "?" : ""} <Name />
41
+ {props.default ? code` = ${props.default}` : ""}
35
42
  </core.Declaration>
36
43
  );
37
44
  }
38
45
 
39
46
  export interface ParametersProps {
40
47
  // param name and type
41
- parameters: Array<ParameterProps>;
48
+ parameters: ParameterProps[];
42
49
  }
43
50
 
44
51
  // a collection of parameters