RuntimeDefaults Class

Overview

The RuntimeDefaults class is a small helper in the PocoDataSet.Data assembly that provides a runtime equivalent of default(T) when you only have a System.Type instance.

It returns null for reference types and creates a default instance for value types (for example, 0 for int, false for bool, DateTime.MinValue for DateTime).

Namespace and Assembly

Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll

Declaration

public static class RuntimeDefaults
{
    public static object? GetDefault(Type t);
    public static object? ForType(Type t);
}

Methods

GetDefault(Type t)

Returns the runtime default value for the provided Type. This method is a small wrapper around ForType(Type).

ForType(Type t)

Same behavior as GetDefault(Type). It is kept for callers that already use the ForType naming.

Usage Example

// Example: obtain default values when only a System.Type is known at runtime
object? defaultInt = RuntimeDefaults.GetDefault(typeof(int));
object? defaultBool = RuntimeDefaults.GetDefault(typeof(bool));
object? defaultString = RuntimeDefaults.GetDefault(typeof(string));

// defaultInt is 0 (boxed)
// defaultBool is false (boxed)
// defaultString is null

Design Notes

 

Table of Content POCO DataSet PocoDataSet.Data

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.