Class TypeUtils
Namespace: Momentum.Extensions.EventMarkdownGenerator.Services
Assembly: Momentum.Extensions.EventMarkdownGenerator.dll
Shared utility methods for type checking and name formatting. Consolidates type-related logic from multiple service classes.
public static class TypeUtilsInheritance
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Fields
FullNameComparer
Compares types by rather than reference/runtime-handle identity. The generator loads each assembly path into its own isolated AssemblyLoadContext (see GenerateCommand.LoadAssemblyWithDependencyResolution), so the same source type compiled into multiple scanned assemblies (e.g. a model referenced from both a project's own assembly and a downstream assembly that copies it to its output) surfaces as multiple distinct
would treat as different — producing duplicate schema files and duplicate sidebar entries. Use this comparer wherever complex types are deduplicated across events/assemblies.
public static readonly IEqualityComparer<Type> FullNameComparerField Value
Methods
CollectComplexTypesFromProperties(IEnumerable<EventPropertyMetadata>)
Collects all complex types from a collection of event properties.
public static HashSet<Type> CollectComplexTypesFromProperties(IEnumerable<EventPropertyMetadata> properties)Parameters
properties IEnumerable<EventPropertyMetadata>
Returns
CollectNestedComplexTypes(Type, HashSet<Type>)
Collects all nested complex types from a parent type recursively.
public static void CollectNestedComplexTypes(Type parentType, HashSet<Type> schemaTypes)Parameters
parentType Type
FindAttributeByName(IEnumerable<Attribute>, string)
Finds a custom attribute by name (or name prefix) so discovery works across assembly load contexts and for any attribute type matching a configured convention, not just a hardcoded compiled type.
public static Attribute? FindAttributeByName(IEnumerable<Attribute> attributes, string attributeNamePrefix)Parameters
attributes IEnumerable<Attribute>
attributeNamePrefix string
Returns
GetCleanTypeName(Type)
Gets the full namespace + type name without assembly qualification. This is useful for creating clean filenames and identifiers while preserving full type identification.
public static string GetCleanTypeName(Type type)Parameters
type Type
The type to get the clean name for
Returns
Full namespace + type name without assembly info (e.g., "System.Collections.Generic.Dictionary<System.String, System.Object>")
GetElementType(Type)
Gets the element type from a collection type (arrays or generic collections). For dictionaries, returns the value type (second generic argument).
public static Type? GetElementType(Type type)Parameters
type Type
Returns
Type?
GetElementTypeName(Type)
Gets the element type name from a collection type.
public static string? GetElementTypeName(Type type)Parameters
type Type
Returns
GetFriendlyTypeName(Type)
Gets a friendly display name for a type (e.g., "string" instead of "String"). Handles nullable types and generics appropriately.
public static string GetFriendlyTypeName(Type type)Parameters
type Type
Returns
GetPropertyValue<T>(Type, object, string)
Gets a property value from an object using reflection with safe null handling.
public static T? GetPropertyValue<T>(Type type, object instance, string propertyName)Parameters
type Type
instance object
propertyName string
Returns
T?
Type Parameters
T
IsCollectionType(Type)
Determines if a type is a collection type (arrays, lists, dictionaries, sets, etc.).
public static bool IsCollectionType(Type type)Parameters
type Type
Returns
IsComplexType(Type)
Determines if a type is complex (not a simple type, enum, or common framework type). Uses cycle detection to handle recursive type references.
public static bool IsComplexType(Type type)Parameters
type Type
Returns
IsPrimitiveType(Type)
Determines if a type is a simple value type (primitives, enums, common framework types).
public static bool IsPrimitiveType(Type type)Parameters
type Type
Returns
IsRequiredProperty(PropertyInfo)
Determines if a property is required based on RequiredAttribute or nullability context.
public static bool IsRequiredProperty(PropertyInfo property)Parameters
property PropertyInfo
The property to check.
Returns
True if the property is required; otherwise, false.
MapConstructorParametersToProperties(Type, ParameterInfo[])
Maps constructor parameters to same-named properties (case-insensitive), so attributes applied to a record's positional parameters can be found via their corresponding property.
public static Dictionary<string, ParameterInfo> MapConstructorParametersToProperties(Type type, ParameterInfo[] constructorParameters)Parameters
type Type
constructorParameters ParameterInfo[]