@alloy-js/csharp 0.18.0-dev.10 → 0.18.0-dev.12

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.
@@ -13,6 +13,10 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
13
13
  doc?: core.Children;
14
14
  refkey?: core.Refkey;
15
15
  typeParameters?: Record<string, core.Refkey>;
16
+ /** Base class that this class extends */
17
+ baseType?: core.Children;
18
+ /** Interfaces this class implements */
19
+ interfaceTypes?: core.Children[];
16
20
  }
17
21
  /**
18
22
  * CSharp class declaration.
@@ -1 +1 @@
1
- {"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAUD,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,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,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7C,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IAEzB,uCAAuC;IACvC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBAgE5D;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBAkC5D;AAGD,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CACrB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,iBA0BlD"}
@@ -1,5 +1,6 @@
1
1
  import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
+ import { join } from "@alloy-js/core";
3
4
  import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
4
5
  import { useCSharpNamePolicy } from "../name-policy.js";
5
6
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
@@ -71,6 +72,10 @@ export function ClassDeclaration(props) {
71
72
  }
72
73
  });
73
74
  }
75
+ const bases = [...(props.baseType ? [props.baseType] : []), ...(props.interfaceTypes || [])];
76
+ const base = bases.length > 0 ? [" : ", _$memo(() => join(bases, {
77
+ joiner: ", "
78
+ }))] : null;
74
79
  const modifiers = computeModifiersPrefix([getAccessModifier(props), getClassModifiers(props)]);
75
80
  return _$createComponent(core.Declaration, {
76
81
  symbol: thisClassSymbol,
@@ -79,7 +84,7 @@ export function ClassDeclaration(props) {
79
84
  get doc() {
80
85
  return props.doc;
81
86
  }
82
- }), modifiers, "class ", _$createComponent(Name, {}), typeParams, _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Block, {
87
+ }), modifiers, "class ", _$createComponent(Name, {}), typeParams, base, _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Block, {
83
88
  newline: true,
84
89
  get children() {
85
90
  return _$createComponent(core.Scope, {
@@ -0,0 +1,55 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ /** Method modifiers. Can only be one. */
4
+ export interface ClassPropertyModifiers {
5
+ readonly new?: boolean;
6
+ readonly static?: boolean;
7
+ readonly virtual?: boolean;
8
+ readonly sealed?: boolean;
9
+ readonly override?: boolean;
10
+ readonly abstract?: boolean;
11
+ readonly extern?: boolean;
12
+ readonly readonly?: boolean;
13
+ }
14
+ /** Properties for {@link ClassProperty} component */
15
+ export interface ClassPropertyProps extends AccessModifiers, ClassPropertyModifiers {
16
+ name: string;
17
+ refkey?: Refkey;
18
+ /** Property type */
19
+ type: Children;
20
+ /** If property should have a getter */
21
+ get?: boolean;
22
+ /** If property should have a setter */
23
+ set?: boolean;
24
+ /** Doc comment */
25
+ doc?: Children;
26
+ /**
27
+ * Property initializer
28
+ * @example `<ClassProperty name="My" get set nullable />`
29
+ *
30
+ * ```cs
31
+ * int? My { get; set; };
32
+ * ```
33
+ */
34
+ nullable?: boolean;
35
+ /**
36
+ * Property initializer
37
+ * @example `<ClassProperty name="My" get set init={42} />`
38
+ *
39
+ * ```cs
40
+ * int My { get; set; } = 42;
41
+ * ```
42
+ */
43
+ init?: Children;
44
+ }
45
+ /**
46
+ * Render a C# class property.
47
+ *
48
+ * @example `<ClassProperty public name="My" get set />`
49
+ *
50
+ * ```cs
51
+ * public int My { get; set; };
52
+ * ```
53
+ */
54
+ export declare function ClassProperty(props: ClassPropertyProps): Children;
55
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/class/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,yCAAyC;AACzC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAaD,qDAAqD;AACrD,MAAM,WAAW,kBACf,SAAQ,eAAe,EACrB,sBAAsB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAyCtD"}
@@ -0,0 +1,67 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { Block, code, List, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
3
+ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
4
+ import { useCSharpNamePolicy } from "../../name-policy.js";
5
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
+ import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
7
+ import { DocWhen } from "../doc/comment.js";
8
+
9
+ /** Method modifiers. Can only be one. */
10
+
11
+ const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly"]);
12
+
13
+ /** Properties for {@link ClassProperty} component */
14
+
15
+ /**
16
+ * Render a C# class property.
17
+ *
18
+ * @example `<ClassProperty public name="My" get set />`
19
+ *
20
+ * ```cs
21
+ * public int My { get; set; };
22
+ * ```
23
+ */
24
+ export function ClassProperty(props) {
25
+ const name = useCSharpNamePolicy().getName(props.name, "class-property");
26
+ const scope = useCSharpScope();
27
+ if (scope.kind !== "member" || scope.name !== "class-decl") {
28
+ throw new Error("can't define an interface method outside of an interface scope");
29
+ }
30
+ const propertySymbol = new CSharpOutputSymbol(name, {
31
+ scope,
32
+ refkeys: props.refkey ?? refkey(props.name)
33
+ });
34
+
35
+ // scope for property declaration
36
+ const propertyScope = new CSharpMemberScope("property-decl", {
37
+ owner: propertySymbol
38
+ });
39
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
40
+ // note that scope wraps the method decl so that the params get the correct scope
41
+ return _$createComponent(MemberDeclaration, {
42
+ symbol: propertySymbol,
43
+ get children() {
44
+ return _$createComponent(Scope, {
45
+ value: propertyScope,
46
+ get children() {
47
+ return [_$createComponent(DocWhen, {
48
+ get doc() {
49
+ return props.doc;
50
+ }
51
+ }), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
52
+ newline: true,
53
+ inline: true,
54
+ get children() {
55
+ return _$createComponent(List, {
56
+ joiner: " ",
57
+ get children() {
58
+ return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
59
+ }
60
+ });
61
+ }
62
+ }), _$memo(() => props.init && code` = ${props.init};`)];
63
+ }
64
+ });
65
+ }
66
+ });
67
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=property.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/class/property.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,201 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { ClassDeclaration } from "../ClassDeclaration.js";
5
+ import { ClassProperty } from "./property.js";
6
+ const Wrapper = props => _$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(ClassDeclaration, {
9
+ "public": true,
10
+ name: "TestClass",
11
+ get children() {
12
+ return props.children;
13
+ }
14
+ });
15
+ }
16
+ });
17
+ describe("modifiers", () => {
18
+ describe("access modifiers", () => {
19
+ it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
20
+ expect(_$createComponent(Wrapper, {
21
+ get children() {
22
+ return _$createComponent(ClassProperty, _$mergeProps({
23
+ [accessModifier]: true
24
+ }, {
25
+ name: "TestProp",
26
+ type: "string",
27
+ get: true
28
+ }));
29
+ }
30
+ })).toRenderTo(`
31
+ public class TestClass
32
+ {
33
+ ${accessModifier} string TestProp { get; }
34
+ }
35
+ `);
36
+ });
37
+ });
38
+ describe("property modifiers", () => {
39
+ it.each(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly"])("%s", methodModifier => {
40
+ expect(_$createComponent(Wrapper, {
41
+ get children() {
42
+ return _$createComponent(ClassProperty, _$mergeProps({
43
+ [methodModifier]: true
44
+ }, {
45
+ name: "TestProp",
46
+ type: "string",
47
+ get: true
48
+ }));
49
+ }
50
+ })).toRenderTo(`
51
+ public class TestClass
52
+ {
53
+ ${methodModifier} string TestProp { get; }
54
+ }
55
+ `);
56
+ });
57
+ });
58
+ it("combine modifiers", () => {
59
+ expect(_$createComponent(Wrapper, {
60
+ get children() {
61
+ return _$createComponent(ClassProperty, {
62
+ "public": true,
63
+ "new": true,
64
+ name: "TestProp",
65
+ type: "string",
66
+ get: true
67
+ });
68
+ }
69
+ })).toRenderTo(`
70
+ public class TestClass
71
+ {
72
+ public new string TestProp { get; }
73
+ }
74
+ `);
75
+ });
76
+ });
77
+ it("applies PascalCase naming policy", () => {
78
+ expect(_$createComponent(Wrapper, {
79
+ get children() {
80
+ return _$createComponent(ClassProperty, {
81
+ name: "test_prop",
82
+ type: "string",
83
+ get: true
84
+ });
85
+ }
86
+ })).toRenderTo(`
87
+ public class TestClass
88
+ {
89
+ string TestProp { get; }
90
+ }
91
+ `);
92
+ });
93
+ it("has getter only", () => {
94
+ expect(_$createComponent(Wrapper, {
95
+ get children() {
96
+ return _$createComponent(ClassProperty, {
97
+ name: "TestProp",
98
+ type: "string",
99
+ get: true
100
+ });
101
+ }
102
+ })).toRenderTo(`
103
+ public class TestClass
104
+ {
105
+ string TestProp { get; }
106
+ }
107
+ `);
108
+ });
109
+ it("has setter only", () => {
110
+ expect(_$createComponent(Wrapper, {
111
+ get children() {
112
+ return _$createComponent(ClassProperty, {
113
+ name: "TestProp",
114
+ type: "string",
115
+ set: true
116
+ });
117
+ }
118
+ })).toRenderTo(`
119
+ public class TestClass
120
+ {
121
+ string TestProp { set; }
122
+ }
123
+ `);
124
+ });
125
+ it("has getter and setter", () => {
126
+ expect(_$createComponent(Wrapper, {
127
+ get children() {
128
+ return _$createComponent(ClassProperty, {
129
+ name: "TestProp",
130
+ type: "string",
131
+ get: true,
132
+ set: true
133
+ });
134
+ }
135
+ })).toRenderTo(`
136
+ public class TestClass
137
+ {
138
+ string TestProp { get; set; }
139
+ }
140
+ `);
141
+ });
142
+ it("specify doc comment", () => {
143
+ expect(_$createComponent(TestNamespace, {
144
+ get children() {
145
+ return _$createComponent(ClassDeclaration, {
146
+ name: "Test",
147
+ get children() {
148
+ return _$createComponent(ClassProperty, {
149
+ name: "Method",
150
+ type: "string",
151
+ get: true,
152
+ set: true,
153
+ doc: "This is a test"
154
+ });
155
+ }
156
+ });
157
+ }
158
+ })).toRenderTo(`
159
+ class Test
160
+ {
161
+ /// This is a test
162
+ string Method { get; set; }
163
+ }
164
+ `);
165
+ });
166
+ it("specify nullable property", () => {
167
+ expect(_$createComponent(Wrapper, {
168
+ get children() {
169
+ return _$createComponent(ClassProperty, {
170
+ name: "TestProp",
171
+ type: "string",
172
+ nullable: true,
173
+ get: true,
174
+ set: true
175
+ });
176
+ }
177
+ })).toRenderTo(`
178
+ public class TestClass
179
+ {
180
+ string? TestProp { get; set; }
181
+ }
182
+ `);
183
+ });
184
+ it("specify initializer", () => {
185
+ expect(_$createComponent(Wrapper, {
186
+ get children() {
187
+ return _$createComponent(ClassProperty, {
188
+ name: "TestProp",
189
+ type: "string",
190
+ get: true,
191
+ set: true,
192
+ init: `"abc"`
193
+ });
194
+ }
195
+ })).toRenderTo(`
196
+ public class TestClass
197
+ {
198
+ string TestProp { get; set; } = "abc";
199
+ }
200
+ `);
201
+ });
@@ -1,3 +1,4 @@
1
+ export * from "./class/property.js";
1
2
  export * from "./ClassDeclaration.jsx";
2
3
  export * from "./ClassMethod.jsx";
3
4
  export * from "./Declaration.js";
@@ -6,6 +7,7 @@ export * from "./doc/from-markdown.jsx";
6
7
  export * from "./EnumDeclaration.jsx";
7
8
  export * from "./interface/declaration.js";
8
9
  export * from "./interface/method.js";
10
+ export * from "./interface/property.js";
9
11
  export * from "./Name.js";
10
12
  export * from "./Namespace.js";
11
13
  export * from "./Parameters.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from "./class/property.js";
1
2
  export * from "./ClassDeclaration.js";
2
3
  export * from "./ClassMethod.js";
3
4
  export * from "./Declaration.js";
@@ -6,6 +7,7 @@ export * from "./doc/from-markdown.js";
6
7
  export * from "./EnumDeclaration.js";
7
8
  export * from "./interface/declaration.js";
8
9
  export * from "./interface/method.js";
10
+ export * from "./interface/property.js";
9
11
  export * from "./Name.js";
10
12
  export * from "./Namespace.js";
11
13
  export * from "./Parameters.js";
@@ -4,7 +4,6 @@ import { AccessModifiers } from "../../modifiers.js";
4
4
  export interface InterfacePropertyModifiers {
5
5
  readonly new?: boolean;
6
6
  }
7
- export declare const getMethodModifier: (data: InterfacePropertyModifiers) => string;
8
7
  export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
9
8
  name: string;
10
9
  refkey?: Refkey;
@@ -16,6 +15,24 @@ export interface InterfacePropertyProps extends AccessModifiers, InterfaceProper
16
15
  set?: boolean;
17
16
  /** Doc comment */
18
17
  doc?: Children;
18
+ /**
19
+ * Property initializer
20
+ * @example `<ClassProperty name="My" get set nullable />`
21
+ *
22
+ * ```cs
23
+ * int? My { get; set; };
24
+ * ```
25
+ */
26
+ nullable?: boolean;
19
27
  }
28
+ /**
29
+ * Render a C# interface property.
30
+ *
31
+ * @example `<InterfaceProperty public name="My" get set />`
32
+ *
33
+ * ```cs
34
+ * public int My { get; set; };
35
+ * ```
36
+ */
20
37
  export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
21
38
  //# sourceMappingURL=property.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OA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ED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAwC9D"}
@@ -8,11 +8,19 @@ import { DocWhen } from "../doc/comment.js";
8
8
 
9
9
  /** Method modifiers. Can only be one. */
10
10
 
11
- export const getMethodModifier = makeModifiers(["new"]);
11
+ const getModifiers = makeModifiers(["new"]);
12
12
 
13
13
  // properties for creating a method
14
14
 
15
- // a C# interface property
15
+ /**
16
+ * Render a C# interface property.
17
+ *
18
+ * @example `<InterfaceProperty public name="My" get set />`
19
+ *
20
+ * ```cs
21
+ * public int My { get; set; };
22
+ * ```
23
+ */
16
24
  export function InterfaceProperty(props) {
17
25
  const name = useCSharpNamePolicy().getName(props.name, "class-property");
18
26
  const scope = useCSharpScope();
@@ -28,7 +36,7 @@ export function InterfaceProperty(props) {
28
36
  const propertyScope = new CSharpMemberScope("property-decl", {
29
37
  owner: propertySymbol
30
38
  });
31
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
39
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
32
40
  // note that scope wraps the method decl so that the params get the correct scope
33
41
  return _$createComponent(MemberDeclaration, {
34
42
  symbol: propertySymbol,
@@ -40,7 +48,7 @@ export function InterfaceProperty(props) {
40
48
  get doc() {
41
49
  return props.doc;
42
50
  }
43
- }), modifiers, _$memo(() => props.type), " ", name, " ", _$createComponent(Block, {
51
+ }), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
44
52
  newline: true,
45
53
  inline: true,
46
54
  get children() {
@@ -58,6 +58,45 @@ describe("modifiers", () => {
58
58
  `);
59
59
  });
60
60
  });
61
+ describe("base", () => {
62
+ it("define base class", () => {
63
+ expect(_$createComponent(utils.TestNamespace, {
64
+ get children() {
65
+ return _$createComponent(csharp.ClassDeclaration, {
66
+ name: "TestClass",
67
+ baseType: "Foo"
68
+ });
69
+ }
70
+ })).toRenderTo(`
71
+ class TestClass : Foo;
72
+ `);
73
+ });
74
+ it("define multiple interface types", () => {
75
+ expect(_$createComponent(utils.TestNamespace, {
76
+ get children() {
77
+ return _$createComponent(csharp.ClassDeclaration, {
78
+ name: "TestClass",
79
+ interfaceTypes: ["Foo", "Bar"]
80
+ });
81
+ }
82
+ })).toRenderTo(`
83
+ class TestClass : Foo, Bar;
84
+ `);
85
+ });
86
+ it("define base class and multiple interface types", () => {
87
+ expect(_$createComponent(utils.TestNamespace, {
88
+ get children() {
89
+ return _$createComponent(csharp.ClassDeclaration, {
90
+ name: "TestClass",
91
+ baseType: "BaseClass",
92
+ interfaceTypes: ["Foo", "Bar"]
93
+ });
94
+ }
95
+ })).toRenderTo(`
96
+ class TestClass : BaseClass, Foo, Bar;
97
+ `);
98
+ });
99
+ });
61
100
  it("declares class with some members", () => {
62
101
  const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
63
102
  "public": true,