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 - MahApps/ExposedObject

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

49 Commits
49 Commits

Folders and files

NameName
Last commit message
Last commit date
ExposedObject
ExposedObject
 
 
TestSubjects
TestSubjects
 
 
Tests
Tests
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
Directory.Build.props
Directory.Build.props
 
 
ExposedObject.sln
ExposedObject.sln
 
 
README.md
README.md
 
 

Repository files navigation

ExposedObject

Build Status

Fast dynamic wrapper for accessing hidden methods and fields of .Net objects. Uses 4.0 dynamic feature to allow seamless access to non-public object members. Facilitates white-box unit testing, exposes APIs that should be public and allows construction of elaborate hacks. Should not kill your cat provided you are careful. Available on NuGet.

Usage examples

Handling private instance methods, fields and properties on a visible type:

// create an Exposed instance from a ClassWithHiddenMethods instance
dynamic exposed = Exposed.From(new ClassWithHiddenMethods());
// calling a private method
string password = exposed.GeneratePassword(8);
// reading a private field
int privateFieldValue = exposed.internalCount;
// setting a private field
exposed.internalCount = privateFieldValue * 2;
// reading a protected property
char protectedPropertyValue = exposed.InternalData;

Accessing private field on a hidden type:

// get the Type via reflection
Type hiddenClass = Type.GetType("TestSubjects.HiddenClass, TestSubjects");
// call the parameterless constructor of a hidden type
dynamic exposed = Exposed.New(hiddenClass);
string password = exposed.password;

Accessing internal static method from type:

dynamic exposed = Exposed.From(typeof(ClassWithInternalStaticMethod));
decimal convertValue = exposed.ConvertValue(8);

TODO:

  • performance assessment (binding restrictions vs caching, compare with CreateDelegate solution)
  • generic methods (there are tests for them, some suggested solutions on StackOverflow )
  • constructors (currently Exposed.New() delegates to Activator.CreateInstance() )

Ideas borrowed from:

  • Bug squash: Testing private methods with C# 4.0 - starting idea
  • Igor Ostrovsky: Use C# dynamic typing to conveniently access internals of an object - convenient API
  • Miguel de Icaza: C# 4's Dynamic in Mono - performant dynamic object implementation using GetMetaObject()

About

No description, website, or topics provided.

Resources

Readme
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — 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.