@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.
- package/LICENSE +7 -0
- package/dist/src/components/ClassDeclaration.d.ts +74 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Class.js → ClassDeclaration.js} +59 -32
- package/dist/src/components/ClassMethod.d.ts +25 -4
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +22 -3
- package/dist/src/components/EnumDeclaration.d.ts +34 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Enum.js → EnumDeclaration.js} +25 -5
- package/dist/src/components/Parameters.d.ts +6 -1
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +3 -2
- package/dist/src/components/doc/comment.d.ts +70 -0
- package/dist/src/components/doc/comment.d.ts.map +1 -0
- package/dist/src/components/doc/comment.js +88 -0
- package/dist/src/components/doc/comment.test.d.ts +2 -0
- package/dist/src/components/doc/comment.test.d.ts.map +1 -0
- package/dist/src/components/doc/comment.test.js +348 -0
- package/dist/src/components/doc/from-markdown.d.ts +6 -0
- package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.js +58 -0
- package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
- package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.test.js +83 -0
- package/dist/src/components/index.d.ts +12 -3
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +13 -4
- package/dist/src/components/interface/declaration.d.ts +47 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.js +77 -0
- package/dist/src/components/interface/declaration.test.d.ts +2 -0
- package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.test.js +153 -0
- package/dist/src/components/interface/method.d.ts +32 -0
- package/dist/src/components/interface/method.d.ts.map +1 -0
- package/dist/src/components/interface/method.js +69 -0
- package/dist/src/components/interface/method.test.d.ts +2 -0
- package/dist/src/components/interface/method.test.d.ts.map +1 -0
- package/dist/src/components/interface/method.test.js +254 -0
- package/dist/src/components/interface/property.d.ts +38 -0
- package/dist/src/components/interface/property.d.ts.map +1 -0
- package/dist/src/components/interface/property.js +67 -0
- package/dist/src/components/interface/property.test.d.ts +2 -0
- package/dist/src/components/interface/property.test.d.ts.map +1 -0
- package/dist/src/components/interface/property.test.js +165 -0
- package/dist/src/components/property/property.d.ts +57 -0
- package/dist/src/components/property/property.d.ts.map +1 -0
- package/dist/src/components/property/property.js +70 -0
- package/dist/src/components/property/property.test.d.ts +2 -0
- package/dist/src/components/property/property.test.d.ts.map +1 -0
- package/dist/src/components/property/property.test.js +218 -0
- package/dist/src/components/record/declaration.d.ts +35 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -0
- package/dist/src/components/record/declaration.js +90 -0
- package/dist/src/components/record/declaration.test.d.ts +2 -0
- package/dist/src/components/record/declaration.test.d.ts.map +1 -0
- package/dist/src/components/record/declaration.test.js +94 -0
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter.js +22 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.js +54 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
- package/dist/src/components/var/declaration.d.ts +35 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -0
- package/dist/src/components/var/declaration.js +40 -0
- package/dist/src/components/var/declaration.test.d.ts +2 -0
- package/dist/src/components/var/declaration.test.d.ts.map +1 -0
- package/dist/src/components/var/declaration.test.js +73 -0
- package/dist/src/modifiers.d.ts +10 -4
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +9 -32
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +2 -0
- package/dist/test/class-declaration.test.d.ts +2 -0
- package/dist/test/class-declaration.test.d.ts.map +1 -0
- package/dist/test/class-declaration.test.js +463 -0
- package/dist/test/class-method.test.js +37 -14
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/project-directory.test.d.ts +2 -0
- package/dist/test/project-directory.test.d.ts.map +1 -0
- package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/components/{Class.tsx → ClassDeclaration.tsx} +108 -43
- package/src/components/ClassMethod.tsx +53 -12
- package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
- package/src/components/Parameters.tsx +10 -3
- package/src/components/doc/comment.test.tsx +337 -0
- package/src/components/doc/comment.tsx +152 -0
- package/src/components/doc/from-markdown.test.tsx +103 -0
- package/src/components/doc/from-markdown.tsx +58 -0
- package/src/components/index.ts +12 -3
- package/src/components/interface/declaration.test.tsx +143 -0
- package/src/components/interface/declaration.tsx +105 -0
- package/src/components/interface/method.test.tsx +250 -0
- package/src/components/interface/method.tsx +105 -0
- package/src/components/interface/property.test.tsx +144 -0
- package/src/components/interface/property.tsx +107 -0
- package/src/components/property/property.test.tsx +187 -0
- package/src/components/property/property.tsx +146 -0
- package/src/components/record/declaration.test.tsx +73 -0
- package/src/components/record/declaration.tsx +109 -0
- package/src/components/stc/index.ts +2 -2
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
- package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
- package/src/components/type-parameters/type-parameter.tsx +35 -0
- package/src/components/type-parameters/type-parameters.test.tsx +46 -0
- package/src/components/type-parameters/type-parameters.tsx +63 -0
- package/src/components/var/declaration.test.tsx +59 -0
- package/src/components/var/declaration.tsx +47 -0
- package/src/modifiers.ts +25 -42
- package/src/name-policy.ts +5 -0
- package/temp/api.json +5227 -685
- package/test/class-declaration.test.tsx +418 -0
- package/test/class-method.test.tsx +24 -14
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/test/vitest.setup.ts +1 -0
- package/vitest.config.ts +3 -0
- package/dist/src/components/Class.d.ts +0 -26
- package/dist/src/components/Class.d.ts.map +0 -1
- package/dist/src/components/Enum.d.ts +0 -15
- package/dist/src/components/Enum.d.ts.map +0 -1
- package/dist/test/class.test.d.ts +0 -2
- package/dist/test/class.test.d.ts.map +0 -1
- package/dist/test/class.test.js +0 -298
- package/dist/test/projectdirectory.test.d.ts +0 -2
- package/dist/test/projectdirectory.test.d.ts.map +0 -1
- package/test/class.test.tsx +0 -292
|
@@ -1,21 +1,91 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import {
|
|
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.
|
|
7
|
-
import { ParameterProps, Parameters } from "./Parameters.
|
|
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
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
{
|
|
61
|
-
{
|
|
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
|
|
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
|
-
{
|
|
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.
|
|
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
|
-
{
|
|
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
|
-
|
|
10
|
+
AccessModifiers,
|
|
11
11
|
computeModifiersPrefix,
|
|
12
12
|
getAccessModifier,
|
|
13
13
|
getAsyncModifier,
|
|
14
|
-
|
|
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
|
|
62
|
-
getMethodModifier(props
|
|
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}
|
|
71
|
-
{props.
|
|
72
|
-
|
|
73
|
-
|
|
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 {
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
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}
|
|
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:
|
|
48
|
+
parameters: ParameterProps[];
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
// a collection of parameters
|