UsageAdvanced

Jay Tuley edited this page Aug 19, 2017 · 2 revisions

Alternative Forms of ActLike

In additional to TInterface Impromptu.ActLike<TInterface>(this object target, params Type[] otherInterfaces) there are a few variations.

dynamic DynamicActLike(object originalDynamic, params Type[] otherInterfaces)

Dynamic act like doesn't offer the primary interface as generic parameter so you can use it in a completely late bound way.

IEnumerable<TInterface> AllActLike<TInterface>(this IEnumerable<object> originalDynamic, params Type[] otherInterfaces)

Convenience Method for wrapping an entire list of objects with an Interface.

dynamic ActLikeProperties(this object originalDynamic, IDictionary<string, Type>propertySpec)

This method is used for compatibility sake only, it allows you to make dynamic objects consumable to API's that are expecting to access properties based on reflection.

Sending Argument Names

If your target is a DynamicObject and you want to define a static interface f#or it, and this dynamic object you have designed has an implementation to take argument names into account, then you can make sure the interface sends it's argument names with a [UseNamedArgument] attribute.

Example

     public interface IBuilder{
              INest Nester(object props);
              INested Nester2(object props);

              //Putting the argument on the method use named argument for all arguments
              [UseNamedArgument]  
              INest Nester(string NameLevel1, INested Nested);

              //Putting the argument on the property use named argument for all arguments after that property
              INested Nester2([UseNamedArgument]string NameLevel2);  
     }
        
      public interface INest
    {
                String NameLevel1 {get;set;}
                INested Nested {get;set;}
    }

    public interface INested
    {
                string NameLevel2 {get;}
    }