fsharp-csharp-bridge

Convert F# Result, Option, Discriminated Union, and Record types for C# integration.

1|Updated Jun 27, 2025
One-click install
npx skills add https://github.com/d-kishi/ubiquitous-lang-mng --skill fsharp-csharp-bridge
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fsharp-csharp-bridge
Source: https://github.com/d-kishi/ubiquitous-lang-mng/tree/main/.claude/skills/fsharp-csharp-bridge
Command: npx skills add https://github.com/d-kishi/ubiquitous-lang-mng --skill fsharp-csharp-bridge

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solves? Bridging F# functional types (Result, Option, Discriminated Union, Record) with C# imperative code often leads to type conversion errors, null references, and complex boilerplate. This Skill automates the application of proven conversion patterns, ensuring type safety and reducing development time.

Core Features & Use Cases

  • F# Result ↔ C# Integration: Safely handle F# Result types in C# with IsOk/ResultValue patterns, preventing runtime exceptions.
  • F# Option ↔ C# Integration: Convert F# Option types to and from C# nullables, eliminating null reference exceptions and improving code robustness.
  • F# Discriminated Union ↔ C# Integration: Use C# switch expressions for robust pattern matching on F# DUs, avoiding Enum misinterpretations and ensuring correct logic.
  • F# Record ↔ C# Integration: Correctly initialize immutable F# Record types from C# using constructor-based patterns, bypassing read-only property errors.
  • Use Case: When integrating a new F# domain service into a C# Blazor UI, use this Skill to automatically generate the correct type conversion logic for commands, queries, and results, ensuring a smooth and error-free data flow across language boundaries.

Quick Start

Generate the C# code to convert an F# Result<Project, ProjectError> type into a C# ProjectDto or display the ProjectError message.

Frequently Asked Questions about fsharp-csharp-bridge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert F# Result types to C# without runtime exceptions?

F# Result types convert to C# using IsOk/ResultValue patterns. Check the IsOk property to determine success, then access ResultValue safely, eliminating null reference exceptions and ensuring type safety across language boundaries.

What's the best way to handle F# Option types in C# code?

F# Option types map to C# nullables through Some/None conversion patterns. This approach eliminates null reference exceptions by explicitly representing absent values, ensuring robust code when integrating F# functional libraries with C# applications.

Can I use C# switch expressions to pattern match F# discriminated unions?

Yes. F# discriminated unions convert to C# via switch-based mapping patterns. This avoids enum misinterpretation and ensures correct logic flow, enabling safe cross-language pattern matching with compile-time verification.

How do I initialize immutable F# records from C# without read-only property errors?

F# records initialize through constructor-based patterns from C#. This bypasses read-only property assignment errors and maintains immutability, ensuring correct data shape when consuming F# domain services in C# applications.

Does type conversion between F# and C# impact runtime performance?

The canonical conversion patterns—Result, Option, Discriminated Union, and Record—enforce high-performance, compile-time type safety. Boundary conversions are optimized to avoid boxing penalties and runtime overhead while maintaining null-safety guarantees.

When should I use F#–C# type conversion in a Blazor or service integration workflow?

Apply F#–C# conversion when integrating F# domain services, commands, queries, or results into C# UI frameworks or APIs. Use it during boundary code implementation and type-conversion error remediation to ensure smooth, error-free data flow across language boundaries.