GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - skyguy94/dynamic-wrapper: A utility to automatically generate the wrapper class and return to you the wrapped object that implements your interface.

BranchesTags
Open more actions menu

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
DynamicWrapper
DynamicWrapper
 
 
DynamicWrapperTests
DynamicWrapperTests
 
 
.gitignore
.gitignore
 
 
DynamicWrapper.sln
DynamicWrapper.sln
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
appveyor.yml
appveyor.yml
 
 

Repository files navigation

Stop writing wrapper classes, and do something more productive with your time.

This is a transport of a project originally hosted on on CodePlex, written by Brian Genisio.

Build status Gitter NuGet version

This utility will automatically generate the wrapper class and return to you the wrapped object that implements your interface.

Simply copy DynamicWrapper.cs from the Downloads tab into your solution and use it. There are two extension methods available to you:

Interface wrapper = myObject.As<Interface>();
myObject = wrapper.AsReal<MyObjectType>();

Examples

Lets assume you have a class without an interface. This is often the case with .Net framework classes. Your code relies on this framework object, but you want to abstract it in order to substitute it under test. Typically, you would write a wrapper class that acts as a proxy for the real object, but implements an interface. This utility creates that wrapper for you on the fly.

public class ClassWithoutInterface
{
    public void DoSomething()
    {
        // Do something
    }
}

public interface IDoSomething
{
    void DoSomething();
}

In C#, you cannot write the following because ClassWithoutInterface does not implement IDoSomething:

IDoSomething actor = objectWithoutInterface as IDoSomething; // will resolve as null 

With this utility, you can do this:

IDoSomething actor = objectWithoutInterface.As<IDoSomething>(); // succeeds 

The important thing to know is that this is a wrapped object. Unlike casting, the actor object is not the same as the real object -- it is a proxy to the real object. You can get the real object back out:

ClassWithoutInterface realObject = actor.AsReal<ClassWithoutInterface>(); 

That is all there is to this utility. Stop writing wrapper classes and do something more productive with your time.

About

A utility to automatically generate the wrapper class and return to you the wrapped object that implements your interface.

Resources

Readme
MIT license
Activity

Stars

4 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.