@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.4

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 (166) hide show
  1. package/dist/src/components/Class.d.ts +23 -0
  2. package/dist/src/components/Class.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → Class.js} +37 -67
  4. package/dist/src/components/ClassMethod.d.ts +3 -44
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +8 -32
  7. package/dist/src/components/Enum.d.ts +14 -0
  8. package/dist/src/components/Enum.d.ts.map +1 -0
  9. package/dist/src/components/{EnumDeclaration.js → Enum.js} +2 -21
  10. package/dist/src/components/Parameters.d.ts +13 -0
  11. package/dist/src/components/Parameters.d.ts.map +1 -0
  12. package/dist/src/components/Parameters.js +34 -0
  13. package/dist/src/components/SourceFile.d.ts.map +1 -1
  14. package/dist/src/components/SourceFile.js +0 -1
  15. package/dist/src/components/index.d.ts +4 -14
  16. package/dist/src/components/index.d.ts.map +1 -1
  17. package/dist/src/components/index.js +5 -15
  18. package/dist/src/components/stc/index.d.ts +2 -2
  19. package/dist/src/components/stc/index.d.ts.map +1 -1
  20. package/dist/src/components/stc/index.js +2 -2
  21. package/dist/src/modifiers.d.ts +9 -2
  22. package/dist/src/modifiers.d.ts.map +1 -1
  23. package/dist/src/modifiers.js +9 -6
  24. package/dist/src/name-policy.d.ts +1 -1
  25. package/dist/src/name-policy.d.ts.map +1 -1
  26. package/dist/src/name-policy.js +0 -2
  27. package/dist/test/class-method.test.js +2 -23
  28. package/dist/test/class.test.d.ts +2 -0
  29. package/dist/test/class.test.d.ts.map +1 -0
  30. package/dist/test/{class-declaration.test.js → class.test.js} +51 -234
  31. package/dist/test/enum.test.js +6 -6
  32. package/dist/test/namespace.test.js +4 -4
  33. package/dist/test/projectdirectory.test.d.ts +2 -0
  34. package/dist/test/projectdirectory.test.d.ts.map +1 -0
  35. package/dist/test/{project-directory.test.js → projectdirectory.test.js} +4 -4
  36. package/dist/test/sourcefile.test.js +2 -2
  37. package/dist/test/using.test.js +4 -4
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +3 -4
  40. package/src/components/{ClassDeclaration.tsx → Class.tsx} +38 -116
  41. package/src/components/ClassMethod.tsx +7 -70
  42. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +3 -22
  43. package/src/components/Parameters.tsx +51 -0
  44. package/src/components/SourceFile.tsx +0 -1
  45. package/src/components/index.ts +4 -14
  46. package/src/components/stc/index.ts +2 -2
  47. package/src/modifiers.ts +30 -16
  48. package/src/name-policy.ts +0 -5
  49. package/temp/api.json +1194 -6218
  50. package/test/class-method.test.tsx +3 -19
  51. package/test/class.test.tsx +257 -0
  52. package/test/enum.test.tsx +11 -13
  53. package/test/namespace.test.tsx +4 -4
  54. package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
  55. package/test/sourcefile.test.tsx +2 -2
  56. package/test/using.test.tsx +6 -14
  57. package/vitest.config.ts +0 -3
  58. package/dist/src/components/ClassDeclaration.d.ts +0 -92
  59. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  60. package/dist/src/components/EnumDeclaration.d.ts +0 -34
  61. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  62. package/dist/src/components/attributes/attributes.d.ts +0 -39
  63. package/dist/src/components/attributes/attributes.d.ts.map +0 -1
  64. package/dist/src/components/attributes/attributes.js +0 -62
  65. package/dist/src/components/attributes/attributes.test.d.ts +0 -2
  66. package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
  67. package/dist/src/components/attributes/attributes.test.js +0 -75
  68. package/dist/src/components/doc/comment.d.ts +0 -70
  69. package/dist/src/components/doc/comment.d.ts.map +0 -1
  70. package/dist/src/components/doc/comment.js +0 -88
  71. package/dist/src/components/doc/comment.test.d.ts +0 -2
  72. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  73. package/dist/src/components/doc/comment.test.js +0 -348
  74. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  75. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  76. package/dist/src/components/doc/from-markdown.js +0 -58
  77. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  78. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  79. package/dist/src/components/doc/from-markdown.test.js +0 -83
  80. package/dist/src/components/interface/declaration.d.ts +0 -65
  81. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  82. package/dist/src/components/interface/declaration.js +0 -83
  83. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  84. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  85. package/dist/src/components/interface/declaration.test.js +0 -171
  86. package/dist/src/components/interface/method.d.ts +0 -50
  87. package/dist/src/components/interface/method.d.ts.map +0 -1
  88. package/dist/src/components/interface/method.js +0 -74
  89. package/dist/src/components/interface/method.test.d.ts +0 -2
  90. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  91. package/dist/src/components/interface/method.test.js +0 -300
  92. package/dist/src/components/interface/property.d.ts +0 -56
  93. package/dist/src/components/interface/property.d.ts.map +0 -1
  94. package/dist/src/components/interface/property.js +0 -73
  95. package/dist/src/components/interface/property.test.d.ts +0 -2
  96. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  97. package/dist/src/components/interface/property.test.js +0 -189
  98. package/dist/src/components/parameters/parameters.d.ts +0 -19
  99. package/dist/src/components/parameters/parameters.d.ts.map +0 -1
  100. package/dist/src/components/parameters/parameters.js +0 -43
  101. package/dist/src/components/property/property.d.ts +0 -80
  102. package/dist/src/components/property/property.d.ts.map +0 -1
  103. package/dist/src/components/property/property.js +0 -76
  104. package/dist/src/components/property/property.test.d.ts +0 -2
  105. package/dist/src/components/property/property.test.d.ts.map +0 -1
  106. package/dist/src/components/property/property.test.js +0 -242
  107. package/dist/src/components/record/declaration.d.ts +0 -35
  108. package/dist/src/components/record/declaration.d.ts.map +0 -1
  109. package/dist/src/components/record/declaration.js +0 -90
  110. package/dist/src/components/record/declaration.test.d.ts +0 -2
  111. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  112. package/dist/src/components/record/declaration.test.js +0 -94
  113. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  114. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  115. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  116. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  117. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  118. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  119. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  120. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  121. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  122. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  123. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  124. package/dist/src/components/type-parameters/type-parameters.js +0 -54
  125. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  126. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  127. package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
  128. package/dist/src/components/var/declaration.d.ts +0 -35
  129. package/dist/src/components/var/declaration.d.ts.map +0 -1
  130. package/dist/src/components/var/declaration.js +0 -40
  131. package/dist/src/components/var/declaration.test.d.ts +0 -2
  132. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  133. package/dist/src/components/var/declaration.test.js +0 -73
  134. package/dist/test/class-declaration.test.d.ts +0 -2
  135. package/dist/test/class-declaration.test.d.ts.map +0 -1
  136. package/dist/test/project-directory.test.d.ts +0 -2
  137. package/dist/test/project-directory.test.d.ts.map +0 -1
  138. package/dist/test/vitest.setup.d.ts +0 -2
  139. package/dist/test/vitest.setup.d.ts.map +0 -1
  140. package/dist/test/vitest.setup.js +0 -1
  141. package/src/components/attributes/attributes.test.tsx +0 -61
  142. package/src/components/attributes/attributes.tsx +0 -100
  143. package/src/components/doc/comment.test.tsx +0 -337
  144. package/src/components/doc/comment.tsx +0 -152
  145. package/src/components/doc/from-markdown.test.tsx +0 -103
  146. package/src/components/doc/from-markdown.tsx +0 -58
  147. package/src/components/interface/declaration.test.tsx +0 -158
  148. package/src/components/interface/declaration.tsx +0 -125
  149. package/src/components/interface/method.test.tsx +0 -293
  150. package/src/components/interface/method.tsx +0 -122
  151. package/src/components/interface/property.test.tsx +0 -165
  152. package/src/components/interface/property.tsx +0 -127
  153. package/src/components/parameters/parameters.tsx +0 -74
  154. package/src/components/property/property.test.tsx +0 -209
  155. package/src/components/property/property.tsx +0 -172
  156. package/src/components/record/declaration.test.tsx +0 -73
  157. package/src/components/record/declaration.tsx +0 -109
  158. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  159. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  160. package/src/components/type-parameters/type-parameter.tsx +0 -35
  161. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  162. package/src/components/type-parameters/type-parameters.tsx +0 -63
  163. package/src/components/var/declaration.test.tsx +0 -59
  164. package/src/components/var/declaration.tsx +0 -47
  165. package/test/class-declaration.test.tsx +0 -430
  166. package/test/vitest.setup.ts +0 -1
@@ -1,165 +0,0 @@
1
- import { Children } from "@alloy-js/core/jsx-runtime";
2
- import { describe, expect, it } from "vitest";
3
- import { TestNamespace } from "../../../test/utils.jsx";
4
- import { Attribute } from "../attributes/attributes.jsx";
5
- import { InterfaceDeclaration } from "./declaration.jsx";
6
- import { InterfaceProperty } from "./property.jsx";
7
-
8
- const Wrapper = (props: { children: Children }) => (
9
- <TestNamespace>
10
- <InterfaceDeclaration public name="TestInterface">
11
- {props.children}
12
- </InterfaceDeclaration>
13
- </TestNamespace>
14
- );
15
-
16
- describe("modifiers", () => {
17
- describe("access modifiers", () => {
18
- it.each(["public", "private", "protected", "internal"] as const)(
19
- "%s",
20
- (accessModifier) => {
21
- expect(
22
- <Wrapper>
23
- <InterfaceProperty
24
- {...{ [accessModifier]: true }}
25
- name="TestProp"
26
- type="string"
27
- get
28
- />
29
- </Wrapper>,
30
- ).toRenderTo(`
31
- public interface TestInterface
32
- {
33
- ${accessModifier} string TestProp { get; }
34
- }
35
- `);
36
- },
37
- );
38
- });
39
-
40
- describe("method modifiers", () => {
41
- it.each(["new"] as const)("%s", (methodModifier) => {
42
- expect(
43
- <Wrapper>
44
- <InterfaceProperty
45
- {...{ [methodModifier]: true }}
46
- name="TestProp"
47
- type="string"
48
- get
49
- />
50
- </Wrapper>,
51
- ).toRenderTo(`
52
- public interface TestInterface
53
- {
54
- ${methodModifier} string TestProp { get; }
55
- }
56
- `);
57
- });
58
- });
59
-
60
- it("combine modifiers", () => {
61
- expect(
62
- <Wrapper>
63
- <InterfaceProperty public new name="TestProp" type="string" get />
64
- </Wrapper>,
65
- ).toRenderTo(`
66
- public interface TestInterface
67
- {
68
- public new string TestProp { get; }
69
- }
70
- `);
71
- });
72
- });
73
-
74
- it("applies PascalCase naming policy", () => {
75
- expect(
76
- <Wrapper>
77
- <InterfaceProperty name="test_prop" type="string" get />
78
- </Wrapper>,
79
- ).toRenderTo(`
80
- public interface TestInterface
81
- {
82
- string TestProp { get; }
83
- }
84
- `);
85
- });
86
-
87
- it("has getter only", () => {
88
- expect(
89
- <Wrapper>
90
- <InterfaceProperty name="TestProp" type="string" get />
91
- </Wrapper>,
92
- ).toRenderTo(`
93
- public interface TestInterface
94
- {
95
- string TestProp { get; }
96
- }
97
- `);
98
- });
99
-
100
- it("has setter only", () => {
101
- expect(
102
- <Wrapper>
103
- <InterfaceProperty name="TestProp" type="string" set />
104
- </Wrapper>,
105
- ).toRenderTo(`
106
- public interface TestInterface
107
- {
108
- string TestProp { set; }
109
- }
110
- `);
111
- });
112
- it("has getter and setter", () => {
113
- expect(
114
- <Wrapper>
115
- <InterfaceProperty name="TestProp" type="string" get set />
116
- </Wrapper>,
117
- ).toRenderTo(`
118
- public interface TestInterface
119
- {
120
- string TestProp { get; set; }
121
- }
122
- `);
123
- });
124
-
125
- it("specify doc comment", () => {
126
- expect(
127
- <TestNamespace>
128
- <InterfaceDeclaration name="Test">
129
- <InterfaceProperty
130
- name="Method"
131
- type="string"
132
- get
133
- set
134
- doc="This is a test"
135
- />
136
- </InterfaceDeclaration>
137
- </TestNamespace>,
138
- ).toRenderTo(`
139
- interface Test
140
- {
141
- /// This is a test
142
- string Method { get; set; }
143
- }
144
- `);
145
- });
146
-
147
- it("specify attributes", () => {
148
- expect(
149
- <Wrapper>
150
- <InterfaceProperty
151
- name="Test"
152
- type="int"
153
- attributes={[<Attribute name="Test" />]}
154
- get
155
- set
156
- />
157
- </Wrapper>,
158
- ).toRenderTo(`
159
- public interface TestInterface
160
- {
161
- [Test]
162
- int Test { get; set; }
163
- }
164
- `);
165
- });
@@ -1,127 +0,0 @@
1
- import {
2
- Block,
3
- Children,
4
- List,
5
- MemberDeclaration,
6
- refkey,
7
- Refkey,
8
- Scope,
9
- } from "@alloy-js/core";
10
- import {
11
- AccessModifiers,
12
- computeModifiersPrefix,
13
- getAccessModifier,
14
- makeModifiers,
15
- } from "../../modifiers.js";
16
- import { useCSharpNamePolicy } from "../../name-policy.js";
17
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
18
- import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
19
- import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
20
- import { DocWhen } from "../doc/comment.jsx";
21
-
22
- /** Method modifiers. Can only be one. */
23
- export interface InterfacePropertyModifiers {
24
- readonly new?: boolean;
25
- }
26
-
27
- const getModifiers = makeModifiers<InterfacePropertyModifiers>(["new"]);
28
-
29
- // properties for creating a method
30
- export interface InterfacePropertyProps
31
- extends AccessModifiers,
32
- InterfacePropertyModifiers {
33
- name: string;
34
- refkey?: Refkey;
35
-
36
- /** Property type */
37
- type: Children;
38
-
39
- /** If property should have a getter */
40
- get?: boolean;
41
-
42
- /** If property should have a setter */
43
- set?: boolean;
44
-
45
- /** Doc comment */
46
- doc?: Children;
47
-
48
- /**
49
- * Property initializer
50
- * @example `<ClassProperty name="My" get set nullable />`
51
- *
52
- * ```cs
53
- * int? My { get; set; };
54
- * ```
55
- */
56
- nullable?: boolean;
57
-
58
- /**
59
- * Define attributes to attach
60
- * @example
61
- * ```tsx
62
- * <InterfaceProperty name="MyProp" attributes={[
63
- * <Attribute name="Test" />
64
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
65
- * ]} />
66
- * ```
67
- * This will produce:
68
- * ```csharp
69
- * [Test]
70
- * [Test2("arg1", "arg2")]
71
- * int MyProp { get; set; }
72
- * ```
73
- */
74
- attributes?: AttributesProp;
75
- }
76
-
77
- /**
78
- * Render a C# interface property.
79
- *
80
- * @example `<InterfaceProperty public name="My" get set />`
81
- *
82
- * ```cs
83
- * public int My { get; set; };
84
- * ```
85
- */
86
- export function InterfaceProperty(props: InterfacePropertyProps) {
87
- const name = useCSharpNamePolicy().getName(props.name, "class-property");
88
- const scope = useCSharpScope();
89
- if (scope.kind !== "member" || scope.name !== "interface-decl") {
90
- throw new Error(
91
- "can't define an interface method outside of an interface scope",
92
- );
93
- }
94
-
95
- const propertySymbol = new CSharpOutputSymbol(name, {
96
- scope,
97
- refkeys: props.refkey ?? refkey(props.name),
98
- });
99
-
100
- // scope for property declaration
101
- const propertyScope = new CSharpMemberScope("property-decl", {
102
- owner: propertySymbol,
103
- });
104
-
105
- const modifiers = computeModifiersPrefix([
106
- getAccessModifier(props),
107
- getModifiers(props),
108
- ]);
109
- // note that scope wraps the method decl so that the params get the correct scope
110
- return (
111
- <MemberDeclaration symbol={propertySymbol}>
112
- <Scope value={propertyScope}>
113
- <DocWhen doc={props.doc} />
114
- <AttributeList attributes={props.attributes} endline />
115
- {modifiers}
116
- {props.type}
117
- {props.nullable && "?"} {name}{" "}
118
- <Block newline inline>
119
- <List joiner=" ">
120
- {props.get && "get;"}
121
- {props.set && "set;"}
122
- </List>
123
- </Block>
124
- </Scope>
125
- </MemberDeclaration>
126
- );
127
- }
@@ -1,74 +0,0 @@
1
- import {
2
- Children,
3
- code,
4
- Declaration,
5
- For,
6
- Indent,
7
- OutputSymbol,
8
- refkey,
9
- Refkey,
10
- } from "@alloy-js/core";
11
- import { useCSharpNamePolicy } from "../../name-policy.js";
12
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
13
- import { useCSharpScope } from "../../symbols/scopes.js";
14
- import { Name } from "../Name.jsx";
15
-
16
- export interface ParameterProps {
17
- name: string;
18
- type: Children;
19
- /** If the parmaeter is optional(without default value) */
20
- optional?: boolean;
21
- /** Default value for the parameter */
22
- default?: Children;
23
- refkey?: Refkey;
24
- symbol?: OutputSymbol;
25
- }
26
-
27
- /** Define a parameter to be used in class or interface method. */
28
- export function Parameter(props: ParameterProps) {
29
- const name = useCSharpNamePolicy().getName(props.name, "parameter");
30
- const scope = useCSharpScope();
31
- if (
32
- scope.kind !== "member" ||
33
- (scope.name !== "constructor-decl" && scope.name !== "method-decl")
34
- ) {
35
- throw new Error(
36
- "can't define a parameter outside of a constructor-decl or method-decl scope",
37
- );
38
- }
39
-
40
- const memberSymbol = new CSharpOutputSymbol(name, {
41
- scope,
42
- refkeys: props.refkey ?? refkey(props.name),
43
- });
44
-
45
- return (
46
- <Declaration symbol={memberSymbol}>
47
- {props.type}
48
- {props.optional ? "?" : ""} <Name />
49
- {props.default ? code` = ${props.default}` : ""}
50
- </Declaration>
51
- );
52
- }
53
-
54
- export interface ParametersProps {
55
- parameters: ParameterProps[] | undefined;
56
- }
57
-
58
- /** Render a collection of parameters */
59
- export function Parameters(props: ParametersProps) {
60
- return (
61
- <group>
62
- {"("}
63
- {props.parameters && (
64
- <Indent softline>
65
- <For each={props.parameters} joiner={", "}>
66
- {(param) => <Parameter {...param} />}
67
- </For>
68
- </Indent>
69
- )}
70
- <softline />
71
- {")"}
72
- </group>
73
- );
74
- }
@@ -1,209 +0,0 @@
1
- import { Children } from "@alloy-js/core/jsx-runtime";
2
- import { describe, expect, it } from "vitest";
3
- import { TestNamespace } from "../../../test/utils.jsx";
4
- import { Attribute } from "../attributes/attributes.jsx";
5
- import { ClassDeclaration } from "../ClassDeclaration.jsx";
6
- import { Property } from "./property.jsx";
7
-
8
- const Wrapper = (props: { children: Children }) => (
9
- <TestNamespace>
10
- <ClassDeclaration public name="TestClass">
11
- {props.children}
12
- </ClassDeclaration>
13
- </TestNamespace>
14
- );
15
-
16
- describe("modifiers", () => {
17
- describe("access modifiers", () => {
18
- it.each(["public", "private", "protected", "internal"] as const)(
19
- "%s",
20
- (accessModifier) => {
21
- expect(
22
- <Wrapper>
23
- <Property
24
- {...{ [accessModifier]: true }}
25
- name="TestProp"
26
- type="string"
27
- get
28
- />
29
- </Wrapper>,
30
- ).toRenderTo(`
31
- public class TestClass
32
- {
33
- ${accessModifier} string TestProp { get; }
34
- }
35
- `);
36
- },
37
- );
38
- });
39
-
40
- describe("property modifiers", () => {
41
- it.each([
42
- "new",
43
- "static",
44
- "virtual",
45
- "sealed",
46
- "override",
47
- "abstract",
48
- "extern",
49
- "readonly",
50
- "required",
51
- ] as const)("%s", (methodModifier) => {
52
- expect(
53
- <Wrapper>
54
- <Property
55
- {...{ [methodModifier]: true }}
56
- name="TestProp"
57
- type="string"
58
- get
59
- />
60
- </Wrapper>,
61
- ).toRenderTo(`
62
- public class TestClass
63
- {
64
- ${methodModifier} string TestProp { get; }
65
- }
66
- `);
67
- });
68
- });
69
-
70
- it("combine modifiers", () => {
71
- expect(
72
- <Wrapper>
73
- <Property public new name="TestProp" type="string" get />
74
- </Wrapper>,
75
- ).toRenderTo(`
76
- public class TestClass
77
- {
78
- public new string TestProp { get; }
79
- }
80
- `);
81
- });
82
- });
83
-
84
- it("applies PascalCase naming policy", () => {
85
- expect(
86
- <Wrapper>
87
- <Property name="test_prop" type="string" get />
88
- </Wrapper>,
89
- ).toRenderTo(`
90
- public class TestClass
91
- {
92
- string TestProp { get; }
93
- }
94
- `);
95
- });
96
-
97
- it("has getter only", () => {
98
- expect(
99
- <Wrapper>
100
- <Property name="TestProp" type="string" get />
101
- </Wrapper>,
102
- ).toRenderTo(`
103
- public class TestClass
104
- {
105
- string TestProp { get; }
106
- }
107
- `);
108
- });
109
-
110
- it("has setter only", () => {
111
- expect(
112
- <Wrapper>
113
- <Property name="TestProp" type="string" set />
114
- </Wrapper>,
115
- ).toRenderTo(`
116
- public class TestClass
117
- {
118
- string TestProp { set; }
119
- }
120
- `);
121
- });
122
-
123
- it("has getter and setter", () => {
124
- expect(
125
- <Wrapper>
126
- <Property name="TestProp" type="string" get set />
127
- </Wrapper>,
128
- ).toRenderTo(`
129
- public class TestClass
130
- {
131
- string TestProp { get; set; }
132
- }
133
- `);
134
- });
135
-
136
- it("has getter and init", () => {
137
- expect(
138
- <Wrapper>
139
- <Property name="TestProp" type="string" get init />
140
- </Wrapper>,
141
- ).toRenderTo(`
142
- public class TestClass
143
- {
144
- string TestProp { get; init; }
145
- }
146
- `);
147
- });
148
-
149
- it("specify doc comment", () => {
150
- expect(
151
- <TestNamespace>
152
- <ClassDeclaration name="Test">
153
- <Property name="Method" type="string" get set doc="This is a test" />
154
- </ClassDeclaration>
155
- </TestNamespace>,
156
- ).toRenderTo(`
157
- class Test
158
- {
159
- /// This is a test
160
- string Method { get; set; }
161
- }
162
- `);
163
- });
164
-
165
- it("specify nullable property", () => {
166
- expect(
167
- <Wrapper>
168
- <Property name="TestProp" type="string" nullable get set />
169
- </Wrapper>,
170
- ).toRenderTo(`
171
- public class TestClass
172
- {
173
- string? TestProp { get; set; }
174
- }
175
- `);
176
- });
177
-
178
- it("specify initializer", () => {
179
- expect(
180
- <Wrapper>
181
- <Property name="TestProp" type="string" get set initializer={`"abc"`} />
182
- </Wrapper>,
183
- ).toRenderTo(`
184
- public class TestClass
185
- {
186
- string TestProp { get; set; } = "abc";
187
- }
188
- `);
189
- });
190
-
191
- it("specify attributes", () => {
192
- expect(
193
- <Wrapper>
194
- <Property
195
- name="Test"
196
- type="int"
197
- attributes={[<Attribute name="Test" />]}
198
- get
199
- set
200
- />
201
- </Wrapper>,
202
- ).toRenderTo(`
203
- public class TestClass
204
- {
205
- [Test]
206
- int Test { get; set; }
207
- }
208
- `);
209
- });