---
title: GenericExtensions
summary: API reference for GenericExtensions.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
---

# GenericExtensions

Generic-object helpers: throw-if-null with a custom exception type, a reference/value-aware null test, and JSON/XML string conversion shortcuts. ([BR-058](<../../business-rules.md#br-058-json-serialization-uses-javascriptserializer-(system.web.extensions)-and-xml-serialization-uses-xmlserializer%3B-serializable-targets-must-be-reference-types-(where-t-%3A-class)-except-for-savetojson%3Ct%3E%2C-which-is-unconstrained>))

## Purpose
- Generic-object helpers: throw-if-null with a custom exception type, a reference/value-aware null test, and JSON/XML string conversion shortcuts. ([BR-058](<../../business-rules.md#br-058-json-serialization-uses-javascriptserializer-(system.web.extensions)-and-xml-serialization-uses-xmlserializer%3B-serializable-targets-must-be-reference-types-(where-t-%3A-class)-except-for-savetojson%3Ct%3E%2C-which-is-unconstrained>))

## Context
- Namespace: `SAIF.Common.Extensions`
- Assembly/package: `SAIF.Framework.Common`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| IfNullThrow<T,TException>(this T value) | `public static T IfNullThrow<T,TException>(this T value) where TException : Exception, new()` | Throws a new `TException` when `value` is null; otherwise returns `value` unchanged. |
| IsNull<T>(this T value) | `public static bool IsNull<T>(this T value)` | Null test that works correctly for both reference types and nullable value types. |
| ToJsonString<T>(this T value) | `public static string ToJsonString<T>(this T value)` | Serializes any object to a JSON string via the library's `Serializer`. ([BR-058](<../../business-rules.md#br-058-json-serialization-uses-javascriptserializer-(system.web.extensions)-and-xml-serialization-uses-xmlserializer%3B-serializable-targets-must-be-reference-types-(where-t-%3A-class)-except-for-savetojson%3Ct%3E%2C-which-is-unconstrained>)) |
| ToXmlString<T>(this T value) | `public static string ToXmlString<T>(this T value)` | Serializes any object to an XML string via the library's `Serializer`. ([BR-058](<../../business-rules.md#br-058-json-serialization-uses-javascriptserializer-(system.web.extensions)-and-xml-serialization-uses-xmlserializer%3B-serializable-targets-must-be-reference-types-(where-t-%3A-class)-except-for-savetojson%3Ct%3E%2C-which-is-unconstrained>)) |


## Sources
- `Common/SAIF.Common/Extensions/GenericExtensions.cs`
