You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/library/JsonProvider.fsx
+28-2Lines changed: 28 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -462,8 +462,26 @@ access the sample JSON. This works fine when the sample is specified inline, but
462
462
the sample is specified as a local file (unless you distribute the samples with your library).
463
463
464
464
For this reason, the JSON provider lets you specify samples as embedded resources using the
465
-
static parameter `EmbeddedResource` (don't forget then to [include the file](https://docs.microsoft.com/en-us/visualstudio/ide/build-actions) as EmbeddedResource in the
466
-
project file). If you are building a library `MyLib.dll`, you can write:
465
+
static parameter `EmbeddedResource`. When this parameter is set, the type provider at design time
466
+
reads the sample from the local path, but at runtime (when the library is loaded by a consumer)
467
+
it reads the sample from the embedded resource in the compiled assembly.
468
+
469
+
### Step-by-step guide
470
+
471
+
**Step 1**: Mark your sample file as an embedded resource in the `.fsproj` file:
472
+
473
+
```xml
474
+
<ItemGroup>
475
+
<EmbeddedResourceInclude="data/worldbank.json" />
476
+
</ItemGroup>
477
+
```
478
+
479
+
**Step 2**: Use the `EmbeddedResource` static parameter. The value must be
// The erased row type will be a tuple of all the field types (without the units of measure). If there is a single column then it is just the column type.
"""<summary>Typed representation of a CSV file.</summary>
@@ -264,7 +266,8 @@ type public CsvProvider(cfg: TypeProviderConfig) as this =
264
266
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
265
267
(e.g. 'MyCompany.MyAssembly, resource_name.csv'). This is useful when exposing types generated by the type provider.</param>
266
268
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>
267
-
<param name='StrictBooleans'>When true, only <c>true</c> and <c>false</c> (case-insensitive) are inferred as boolean. Values such as <c>0</c>, <c>1</c>, <c>yes</c>, and <c>no</c> are treated as integers or strings respectively. Defaults to false.</param>"""
269
+
<param name='StrictBooleans'>When true, only <c>true</c> and <c>false</c> (case-insensitive) are inferred as boolean. Values such as <c>0</c>, <c>1</c>, <c>yes</c>, and <c>no</c> are treated as integers or strings respectively. Defaults to false.</param>
270
+
<param name='UseOriginalNames'>When true, CSV column header names are used as-is for generated property names instead of being normalized (e.g. capitalizing the first letter). Defaults to false.</param>"""
268
271
269
272
do csvProvTy.AddXmlDoc helpText
270
273
do csvProvTy.DefineStaticParameters(parameters, buildTypes)
"""<summary>Typed representation of a JSON document.</summary>
@@ -188,7 +191,8 @@ type public JsonProvider(cfg: TypeProviderConfig) as this =
188
191
| ValuesAndInlineSchemasOverrides -> Same as ValuesAndInlineSchemasHints, but value inferred types are ignored when an inline schema is present.
189
192
</param>
190
193
<param name='Schema'>Location of a JSON Schema file or a string containing a JSON Schema document. When specified, Sample and SampleIsList must not be used.</param>
191
-
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings (e.g. "2023-01-15") are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>"""
194
+
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings (e.g. "2023-01-15") are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>
195
+
<param name='UseOriginalNames'>When true, JSON property names are used as-is for generated property names instead of being normalized to PascalCase. Defaults to false.</param>"""
192
196
193
197
do jsonProvTy.AddXmlDoc helpText
194
198
do jsonProvTy.DefineStaticParameters(parameters, buildTypes)
0 commit comments