Class Formatter
- Namespace
- Cuemon.Runtime.Serialization.Formatters
- Assembly
- Cuemon.Core.dll
Provides a set of static methods that complements serialization and deserialization of an object.
public static class Formatter
- Inheritance
-
Formatter
Examples
The following example shows how to resolve .NET types from qualified type-name strings using the Formatter class. It demonstrates both a direct resolution and a safe TryGetType call that avoids exceptions.
using System;
using Cuemon.Runtime.Serialization.Formatters;
namespace Cuemon.Runtime.Serialization.Formatters;
public class FormatterExample
{
public void Demonstrate()
{
var type = Formatter.GetType("System.DateTime, mscorlib");
Console.WriteLine($"Resolved type: {type}");
if (Formatter.TryGetType("Cuemon.GuidStringOptions, Cuemon.Core", out var optionsType))
{
Console.WriteLine($"Found type: {optionsType}");
}
}
}
Methods
GetType(string)
Gets the Type with the specified typeName, performing a case-sensitive search.
public static Type GetType(string typeName)
Parameters
typeNamestringThe assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, it is sufficient to supply the type name qualified by its namespace.
Returns
- Type
The type with the specified
typeName. If the type is not found, null is returned.
TryGetType(string, out Type)
Attempts to get the Type with the specified typeName, performing a case-sensitive search.
public static bool TryGetType(string typeName, out Type type)
Parameters
typeNamestringThe assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, it is sufficient to supply the type name qualified by its namespace.
typeTypeThe type with the specified
typeName. If the type is not found, null is returned.