@alloy-js/csharp 0.18.0-dev.2 → 0.18.0-dev.21
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} +64 -38
- package/dist/src/components/ClassMethod.d.ts +26 -5
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +27 -9
- 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/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 +13 -4
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +14 -5
- 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 +68 -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 +279 -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/parameters/parameters.d.ts +19 -0
- package/dist/src/components/parameters/parameters.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.js +43 -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/ClassDeclaration.tsx +213 -0
- package/src/components/ClassMethod.tsx +54 -15
- package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
- 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 +13 -4
- package/src/components/interface/declaration.test.tsx +143 -0
- package/src/components/interface/declaration.tsx +105 -0
- package/src/components/interface/method.test.tsx +278 -0
- package/src/components/interface/method.tsx +102 -0
- package/src/components/interface/property.test.tsx +144 -0
- package/src/components/interface/property.tsx +107 -0
- package/src/components/parameters/parameters.tsx +74 -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 +5228 -686
- 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/src/components/Parameters.d.ts +0 -13
- package/dist/src/components/Parameters.d.ts.map +0 -1
- package/dist/src/components/Parameters.js +0 -34
- 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/src/components/Class.tsx +0 -149
- package/src/components/Parameters.tsx +0 -51
- package/test/class.test.tsx +0 -292
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { join } from "@alloy-js/core";
|
|
3
|
+
import {
|
|
4
|
+
AccessModifiers,
|
|
5
|
+
computeModifiersPrefix,
|
|
6
|
+
getAccessModifier,
|
|
7
|
+
makeModifiers,
|
|
8
|
+
} from "../modifiers.js";
|
|
9
|
+
import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
|
|
10
|
+
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
11
|
+
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
12
|
+
import { DocWhen } from "./doc/comment.jsx";
|
|
13
|
+
import { Name } from "./Name.jsx";
|
|
14
|
+
import { ParameterProps, Parameters } from "./parameters/parameters.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
|
+
]);
|
|
32
|
+
|
|
33
|
+
// properties for creating a class
|
|
34
|
+
export interface ClassDeclarationProps
|
|
35
|
+
extends Omit<core.DeclarationProps, "nameKind">,
|
|
36
|
+
AccessModifiers,
|
|
37
|
+
ClassModifiers {
|
|
38
|
+
name: string;
|
|
39
|
+
/** Doc comment */
|
|
40
|
+
doc?: core.Children;
|
|
41
|
+
refkey?: 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[];
|
|
62
|
+
}
|
|
63
|
+
|
|
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) {
|
|
89
|
+
const name = useCSharpNamePolicy().getName(props.name!, "class");
|
|
90
|
+
|
|
91
|
+
const thisClassSymbol = new CSharpOutputSymbol(name, {
|
|
92
|
+
refkeys: props.refkey,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// this creates a new scope for the class definition.
|
|
96
|
+
// members will automatically "inherit" this scope so
|
|
97
|
+
// that refkeys to them will produce the fully-qualified
|
|
98
|
+
// name e.g. Foo.Bar.
|
|
99
|
+
const thisClassScope = new CSharpMemberScope("class-decl", {
|
|
100
|
+
owner: thisClassSymbol,
|
|
101
|
+
});
|
|
102
|
+
|
|
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
|
+
]);
|
|
113
|
+
return (
|
|
114
|
+
<core.Declaration symbol={thisClassSymbol}>
|
|
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
|
+
)}
|
|
124
|
+
{!props.children && ";"}
|
|
125
|
+
{props.children && (
|
|
126
|
+
<core.Block newline>
|
|
127
|
+
<core.Scope value={thisClassScope}>{props.children}</core.Scope>
|
|
128
|
+
</core.Block>
|
|
129
|
+
)}
|
|
130
|
+
</core.Declaration>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ClassConstructorProps extends AccessModifiers {
|
|
135
|
+
parameters?: Array<ParameterProps>;
|
|
136
|
+
refkey?: core.Refkey;
|
|
137
|
+
symbol?: core.OutputSymbol;
|
|
138
|
+
children?: core.Children;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// a C# class constructor
|
|
142
|
+
export function ClassConstructor(props: ClassConstructorProps) {
|
|
143
|
+
const scope = useCSharpScope();
|
|
144
|
+
if (scope.kind !== "member" || scope.name !== "class-decl") {
|
|
145
|
+
throw new Error(
|
|
146
|
+
"can't define a class constructor outside of a class-decl scope",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// fetch the class name from the scope
|
|
151
|
+
const name = useCSharpNamePolicy().getName(scope.owner!.name, "class-method");
|
|
152
|
+
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
153
|
+
scope,
|
|
154
|
+
refkeys: props.refkey ?? core.refkey(name),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// scope for ctor declaration
|
|
158
|
+
const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
|
|
159
|
+
owner: ctorSymbol,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
163
|
+
|
|
164
|
+
// note that scope wraps the ctor decl so that the params get the correct scope
|
|
165
|
+
return (
|
|
166
|
+
<core.Declaration symbol={ctorSymbol}>
|
|
167
|
+
<core.Scope value={ctorDeclScope}>
|
|
168
|
+
{modifiers}
|
|
169
|
+
<Name />
|
|
170
|
+
<Parameters parameters={props.parameters} />
|
|
171
|
+
<core.Block newline>{props.children}</core.Block>
|
|
172
|
+
</core.Scope>
|
|
173
|
+
</core.Declaration>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// properties for creating a class member
|
|
178
|
+
export interface ClassMemberProps extends AccessModifiers {
|
|
179
|
+
name: string;
|
|
180
|
+
type: core.Children;
|
|
181
|
+
refkey?: core.Refkey;
|
|
182
|
+
/** Doc comment */
|
|
183
|
+
doc?: core.Children;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// a C# class member (i.e. a field within a class like "private int count")
|
|
187
|
+
export function ClassMember(props: ClassMemberProps) {
|
|
188
|
+
let nameElement: CSharpElements = "class-member-private";
|
|
189
|
+
if (props.public) {
|
|
190
|
+
nameElement = "class-member-public";
|
|
191
|
+
}
|
|
192
|
+
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
193
|
+
const scope = useCSharpScope();
|
|
194
|
+
if (scope.kind !== "member" || scope.name !== "class-decl") {
|
|
195
|
+
throw new Error(
|
|
196
|
+
"can't define a class member outside of a class-decl scope",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
201
|
+
scope,
|
|
202
|
+
refkeys: props.refkey ?? core.refkey(props.name),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
206
|
+
return (
|
|
207
|
+
<core.Declaration symbol={memberSymbol}>
|
|
208
|
+
<DocWhen doc={props.doc} />
|
|
209
|
+
{modifiers}
|
|
210
|
+
{props.type} <Name />
|
|
211
|
+
</core.Declaration>
|
|
212
|
+
);
|
|
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
|
-
import {
|
|
19
|
+
import { DocWhen } from "./doc/comment.jsx";
|
|
20
|
+
import { ParameterProps, Parameters } from "./parameters/parameters.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
|
|
@@ -53,24 +88,28 @@ export function ClassMethod(props: ClassMethodProps) {
|
|
|
53
88
|
owner: methodSymbol,
|
|
54
89
|
});
|
|
55
90
|
|
|
56
|
-
const params =
|
|
57
|
-
props.parameters ? <Parameters parameters={props.parameters} /> : "";
|
|
58
91
|
const returns = props.returns ?? (props.async ? "Task" : "void");
|
|
59
92
|
|
|
60
93
|
const modifiers = computeModifiersPrefix([
|
|
61
|
-
getAccessModifier(props
|
|
62
|
-
getMethodModifier(props
|
|
94
|
+
getAccessModifier(props),
|
|
95
|
+
getMethodModifier(props),
|
|
63
96
|
getAsyncModifier(props.async),
|
|
64
97
|
]);
|
|
65
98
|
// note that scope wraps the method decl so that the params get the correct scope
|
|
66
99
|
return (
|
|
67
100
|
<MemberDeclaration symbol={methodSymbol}>
|
|
68
101
|
<Scope value={methodScope}>
|
|
102
|
+
<DocWhen doc={props.doc} />
|
|
69
103
|
{modifiers}
|
|
70
|
-
{returns} {name}
|
|
71
|
-
{props.
|
|
72
|
-
|
|
73
|
-
|
|
104
|
+
{returns} {name}
|
|
105
|
+
{props.typeParameters && (
|
|
106
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
107
|
+
)}
|
|
108
|
+
<Parameters parameters={props.parameters} />
|
|
109
|
+
{props.typeParameters && (
|
|
110
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
111
|
+
)}
|
|
112
|
+
{props.abstract ? ";" : <Block newline>{props.children}</Block>}
|
|
74
113
|
</Scope>
|
|
75
114
|
</MemberDeclaration>
|
|
76
115
|
);
|
|
@@ -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}>
|