Runnable samples and verification
Per-sample build and verification details collect the individual commands, prerequisites and implementation boundaries.
These commands describe the current compiler implementation. They are separate from the language tour, learning guide and language reference. From the repository checkout, use the working paths shown below. Current compiler limits are listed in the implementation guide.
Compile and run Customer
With the .NET 8 SDK installed, open the repository's compiler/ directory and run:
dotnet run --project DirectSharp.Compiler -- run ../samples/CustomerApplication/Customer.ds ../samples/CustomerApplication/CustomerValidator.ds ../samples/CustomerApplication/CustomerService.ds ../samples/CustomerApplication/Program.ds --entry Program.Run
The four source files contain the model, contract validator, in-memory registration service and application.
The application's source and explanation belong to the language tour.
Expected output:
Ana Petrova: 1 customer
All business logic in this example is compiled from DirectSharp. The service uses ordinary .NET List<Customer> storage, and lookup uses DirectSharp's case-insensitive String equality. Its validator currently uses fail-fast native contracts. An executable FluentValidation variant uses ordinary library rules against the same model; its README lists the explicit source files and assembly reference. The async report sample demonstrates explicit await, cancellation, value-form using and an ordinary DirectSharp class with authored async disposal. The channel-processing sample adds an authored async iterator, sequential stream consumption, a waiting worker, cancellation and early consumer exit through ordinary .NET Channels APIs.
--entry Program.Run selects an ordinary public static action; Run has no special language meaning. To inspect generated C#, replace run with transpile and replace the --entry option with -o CustomerApplication.cs. build with -o CustomerApplication.dll emits a CLR library assembly. Run dotnet run --project DirectSharp.Compiler.Tests to compile and test the application, including its failure cases.
The sample model also implements an ordinary ICustomerDetails interface. Its getter-only properties provide a live view of the customer, and the compiler checks each explicit property mapping against the interface contract. The service's TotalCreditLimit action uses an ordinary LINQ Sum selector, compiled from DirectSharp. Its executable Program.ImportText entry also demonstrates a two-line Customer import with resource-valued arguments and validation before storage. Program.ImportRecord adds an ID line and uses a resource-valued constructor assignment, disposing its reader before the readonly ID is stored. A separate Customer record import demonstrates readonly construction through try/catch, native parse-error translation and resource cleanup. Program.ReplaceCustomer validates and replaces a stored customer through ordinary .NET List indexing. Select --entry Program.SummarizeCustomers to run guarded credit increases and dictionary grouping with ??= initialization and += counting; it prints Portfolio: 2 customers, 1 active, 1 inactive.
For a small readonly object, run dotnet run --project DirectSharp.Compiler -- run ../samples/CustomerApplication/CustomerImportSettings.ds --entry CustomerImportSettingsExample.Run from compiler/. The settings constructor uses try_get to parse an optional port, defaults failed acquisition to 443 and validates the resulting range before construction succeeds. It prints Customer import settings: port 443.
For required remote settings, CustomerPortSettings demonstrates a constructor that retries native provider timeouts up to an explicit maximum, then validates and publishes readonly state. From compiler/, run dotnet run --project DirectSharp.Compiler -- run ../samples/CustomerApplication/CustomerPortSettings.ds --entry CustomerPortSettingsExample.Run; it prints Customer port: 8080 after 1 attempt.
For a streaming example with nested error policies, run dotnet run --project DirectSharp.Compiler -- run ../compiler/fixtures/samples/CustomerCreditImport/*.ds --entry Program.GuardedRun from compiler/. The credit importer continues after malformed values and stops at a negative credit, preserving rows already yielded.
To try authored property validation, run dotnet run --project DirectSharp.Compiler -- run ../samples/CustomerApplication/CustomerContact.ds --entry CustomerContactExample.Run from compiler/. The contact class normalizes names in its setter and exposes computed getters; it prints Ana Petrova | ANA PETROVA | 2.
For another executable .NET example, try report directory selection. It uses Environment.SpecialFolder, a .NET enum declared inside another type, in a readonly property and constructor parameter. The two .ds files call ordinary framework APIs and print the selected path without creating directories or writing files.
The Customer delivery schedule builds readonly preferences from an ordinary .NET enum and Customer references. Native parsing happens before readonly storage; invalid or absent text selects the application's Monday fallback. From the repository root, run dotnet run --project compiler/DirectSharp.Compiler -- run compiler/fixtures/samples/CustomerDeliverySchedule/Program.ds --entry CustomerDelivery.Program.Run; it prints Saturday:True:True and Monday:False:False. Its README explains reference identity, comparison failure boundaries and generated-C# inspection.
The stock reservation uses a checked block to calculate a readonly stock balance and rejects both count overflow and insufficient stock. From the repository root, run dotnet run --project compiler/DirectSharp.Compiler -- run samples/StockReservation/Program.ds --entry Inventory.Program.Run; it prints Remaining stock: 12 and Rejected stock count overflow. The sample works with either project overflow setting and includes generated-C# inspection commands.
The same sample's Inventory.Program.ImportPreview entry prints Imported stock: 12. Its ReserveFromText action uses a checked expression containing an owned text reader, so parsing, stock-count arithmetic and disposal complete before the imported value is published.
The Customer credit policy derives readonly credit limits in a subclass, delegates to its base constructor and applies an ordinary credit-decision contract. Its runnable entry prints Approved and Manual review; the sample includes the exact build commands and current initializer support.
The report progress sample parses elapsed seconds before initializing readonly results. It combines ordinary .NET parsing, floating remainder, a whole-period quotient and an invalid-text fallback; its runnable entry prints both paths.
The customer import batch summary parses a row count and initializes readonly batch totals with integer div and mod. Its exact source runs with either overflow setting, including maximum-count and invalid-input checks; the sample includes run and generated-C# inspection commands. Its import-distribution example uses a bounded worker-count expression with div and mod to calculate readonly shares and a round-robin position.
The order line total parses a Byte quantity and UInt16 unit price, then initializes a readonly Integer total using checked multiplication. Its runnable entry shows valid and invalid text; tests also cover maximum inputs, a contract failure and native parse overflow. The same sample includes a runnable shipment quote with a packing-inclusive total and item-only refund, both calculated using nested checked expressions.
The customer pricing sample also includes a credit-allocation entry point: it parses Decimal credit, validates it and initializes readonly per-account shares using a bounded account-count expression. Its README provides commands and the expected output.
The executable Customer roster shows synchronous and asynchronous streaming, owned readers and a row-count postcondition after cleanup. It also demonstrates a one-row preview and validates a complete replacement before changing stored data.
The executable Customer credit import parses ordinary decimal input, yields rejected rows from typed exception handlers and resumes with later rows. It shows readonly result objects, absent invalid amounts, per-row exception handling and a preview that closes its reader after one item.
The credit import also has a strict streaming variant: a while loop inside try reports the first invalid amount with its line number and original .NET exception. Its replacement example finishes validation before changing stored data. A semicolon-delimited variant uses for_each over an ordinary String.Split array, yielding rows inside try and preserving a failing field's position and framework exception. The sample README includes working run and generated-C# inspection commands.
For explicit asynchronous retries, the Customer lookup sample uses ordinary HttpClient, a typed HTTP 503 filter and LastAttempt.Number to enforce its caller's attempt ceiling. Native transport fixtures execute this compiled DirectSharp policy without network access, including cancellation between attempts. The core Customer Program remains the command-line starting point above.
The optional import configuration supplies another small runnable entry: CustomerImportOptionsExample.Run prints Customer import port: 443. It demonstrates try_get with an outside fallback; the same source also reads an optional configuration file through an owned reader in multiline try_get. Its sample README gives the exact command.
The Customer note reader demonstrates handlers-first try layout: the missing-file policy precedes protected reading, and the owned reader closes before return. CustomerNoteReaderExample.Run creates and removes its own temporary example directory and prints Customer note: Call Ana before delivery.; the sample README gives its command.
For ordinary NuGet dependencies, the external validation sample includes an SDK dependency context. From compiler/, run dotnet run --no-build --project DirectSharp.Compiler -- run ../compiler/fixtures/samples/ExternalValidation/Program.ds --project ../compiler/fixtures/samples/ExternalValidation/Dependencies.csproj --entry ExternalValidation.Run. The .NET SDK restores the pinned FluentValidation package; DirectSharp compiles the listed source and prints Email: Email is required. The same context works with the executable Customer FluentValidation variant. This portable net8.0 bootstrap keeps source inputs explicit; the sample lists its project/deployment limits.
For a compiled model and service in separate namespaces, try the namespaced Customer application. It uses a project root, shared imports, native contracts and ordinary .NET collection calls. Its entry is CustomerPortal.Program.Run.
To share imports across application files, try the project-wide Customer summary. From compiler/, run dotnet run --no-build --project DirectSharp.Compiler -- run ../compiler/fixtures/samples/ProjectImports/*.ds --entry ProjectImportsExample.Run. A separate Project.ds imports ordinary .NET namespaces for the formatter and its caller; the compiled application prints Ana, Boris. Include all three source files explicitly when your shell does not expand the wildcard.
For a runnable overload example, try the Customer pricing application. Its Calculate action accepts either a Decimal subtotal or a PriceRequest object. The source implements the preferred-customer rule and contracts; run dotnet run --project compiler/DirectSharp.Compiler -- run compiler/fixtures/samples/CustomerPricing/Program.ds --entry CustomerPricing.Program.Run from the repository root to print 100.00/90.00.
For generic application code, the Customer and supplier draft factory constructs two ordinary classes through one constrained action. Run dotnet run --project compiler/DirectSharp.Compiler -- run compiler/fixtures/samples/CustomerDrafts/Program.ds --entry CustomerDrafts.Program.Run to print Ada:12/Acme:13. Its .ds source contains the generic factory, input guards and result checks; generated C# retains an ordinary CLR generic method.
You can now create a runnable starter with dotnet run --project compiler/DirectSharp.Compiler -- new console /tmp/MyDirectSharpApp, then run its Program.ds with --entry Program.Run. The compiler command guide gives check, format and build commands. For a larger typed example, the generic customer store prints Ada/Ada/7 using source generic classes, a constructed interface and a projection callback.
Native reference verification
From the repository root with the .NET 8 SDK and package access:
dotnet run --project verification/dotnet/DirectSharp.ApplicationExamples.csproj
This runs native C# application/reference checks, including the Customer showcase cases. It is not a DirectSharp compilation command and does not establish language conformance or compatibility with other framework versions.