Skip to content

API Reference

This is a quick reference for the core types and classes related to ObservablePortGenerator. For detailed descriptions of each type, refer to the corresponding Part in the main tutorial.


An abstract class based on the Template Method pattern for incremental source generators.

Namespace: Functorium.SourceGenerators.Generators

Constructor ParameterTypeDescription
registerSourceProviderFunc<IncrementalGeneratorInitializationContext, IncrementalValuesProvider<TValue>>Source provider registration (Step 1)
generateAction<SourceProductionContext, ImmutableArray<TValue>>Code generation (Step 2)
AttachDebuggerbool (default: false)Whether to attach debugger in DEBUG builds

A record struct that holds target class information extracted by the source generator.

Namespace: Functorium.SourceGenerators.Generators.ObservablePortGenerator

PropertyTypeDescription
NamespacestringNamespace of the class
ClassNamestringClass name
MethodsList<MethodInfo>List of methods
BaseConstructorParametersList<ParameterInfo>Base class constructor parameters
LocationLocation?Source code location (for diagnostics)

The static field ObservableClassInfo.None represents an empty instance.


A class that holds method signature information.

PropertyTypeDescription
NamestringMethod name
ParametersList<ParameterInfo>List of parameters
ReturnTypestringReturn type string

A class that holds parameter information.

PropertyTypeDescription
NamestringParameter name
TypestringType string
RefKindRefKindReference kind (in, out, ref, etc.)
IsCollectionboolWhether it is a collection type

A utility that extracts the second type parameter from FinT<IO, T>.

MethodDescription
ExtractSecondTypeParameter(string returnType)Extracts the second parameter from a generic type

Input/Output examples:

InputOutput
FinT<IO, User>User
FinT<IO, List<User>>List<User>
FinT<IO, Dictionary<string, int>>Dictionary<string, int>
FinT<IO, (int Id, string Name)>(int Id, string Name)
FinT<IO, string[]>string[]

A utility for determining collection types and generating Count/Length expressions.

MethodDescription
IsCollectionType(string typeFullName)Whether the type is a collection (excluding tuples)
IsTupleType(string typeFullName)Whether the type is a tuple
GetCountExpression(string variableName, string typeFullName)Generates a .Count or .Length expression
GetRequestFieldName(string parameterName)Generates a request.params.{name} field name
GetResponseFieldName()Returns the response.result field name
GetResponseCountFieldName()Returns the response.result.count field name

Recognized collection types: List<T>, IList<T>, ICollection<T>, IEnumerable<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, HashSet<T>, Dictionary<K,V>, IDictionary<K,V>, IReadOnlyDictionary<K,V>, Queue<T>, Stack<T>, arrays (T[])


A utility that extracts constructor parameters from the target class.

MethodDescription
ExtractParameters(INamedTypeSymbol classSymbol)Extracts constructor parameters

Priority rules:

  1. If a Primary Constructor exists, its parameters are used
  2. If there are multiple constructors, the one with the most parameters is selected
  3. If there are no parameters, an empty list is returned

A utility that resolves parameter name conflicts in the generated Observable class constructor.

MethodDescription
ResolveName(string parameterName)Converts a single parameter name
ResolveNames(List<ParameterInfo> parameters)Batch parameter name conversion

Conversion examples:

OriginalConverted ResultReason
loggerbaseLoggerConflicts with the Observable class’s logger
_loggerbaseLoggerUnderscore prefix removed, then base prefix added
activitySourcebaseActivitySourceConflicts with reserved parameters of the Observable class
connectionStringconnectionStringNo conflict — no conversion

Display formats for deterministic type string generation.

FieldDescription
GlobalQualifiedFormatA format that always includes the global:: prefix

FullyQualifiedFormat output may vary depending on using statements, but GlobalQualifiedFormat always outputs in the form global::System.Collections.Generic.List<T>, ensuring deterministic code generation.


A marker interface that identifies target classes for the source generator.

Namespace: Functorium.Abstractions.Observabilities

public interface IObservablePort
{
string RequestCategory { get; }
}

RequestCategory is used to distinguish the request category in observability tags.


A utility class for testing source generators.

Namespace: Functorium.Testing.Actions.SourceGenerators

MethodDescription
Generate<TGenerator>(this TGenerator, string sourceCode)Runs the generator and returns generated code (fails on diagnostic errors)
GenerateWithDiagnostics<TGenerator>(this TGenerator, string sourceCode)Returns generated code along with Diagnostics

Both methods are extension methods on IIncrementalGenerator and internally use CSharpCompilation and CSharpGeneratorDriver to run the generator in an isolated compilation environment.