Safe proxies are null-safe proxies of a subject interface. A safe proxy will pass-through the results of a valid object or safely return a default value (including another safe proxy) instead of returning null
. If a wrapped object returns a null value, a safe proxy will be created in its place.
A safe proxy is created with the following static method call:
using ProxyFoo;
object obj = null;
var result = Safe.Wrap<ISample>(obj);
or when using object extensions:
using ProxyFoo.ExtensionsApi;
object obj = null;
var result = obj.Safe<ISample>();
A call to a method of result will always return a value even if obj==null
. Return values will be the default value for the type (unless overridden by attribute on the subject interface).