Beispiel #1
0
 /// <summary>
 /// Creates a new proxy object arround the current object using an interface type for duck typing
 /// </summary>
 /// <param name="obj">Real object instance</param>
 /// <param name="interfaceType">Interface type to proxy</param>
 /// <returns>Proxy object instance</returns>
 public static DuckTypeProxy GetDuckTypeProxy(this object obj, Type interfaceType)
 {
     if (obj is DuckTypeProxy proxy)
     {
         return(proxy);
     }
     return(DuckTypeProxy.Create(interfaceType, obj));
 }
Beispiel #2
0
 /// <summary>
 /// Creates a new proxy object arround the current object using an interface type for duck typing
 /// </summary>
 /// <typeparam name="T">Interface type to proxy</typeparam>
 /// <param name="obj">Real object instance</param>
 /// <returns>Proxy object instance</returns>
 public static T ActAs <T>(this object obj) where T : class
 {
     if (obj is T && obj is DuckTypeProxy)
     {
         return(obj as T);
     }
     return(DuckTypeProxy.Create <T>(obj));
 }