wagnerandrade / Phantom
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
Phantom /
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
Phantom.Tests/ | ||
| |
Phantom.sln | ||
| |
Phantom/ | ||
| |
Readme.html | ||
| |
Readme.textile |
Readme.textile
Phantom: Easy reflection in .NET
Phantom is a helper for use relfection in Microsoft.NET.
How to use it?
For begin to use Phantom just put this in your class:
using Phantom;
Simple! This causes appear some extension methods in all objects.
Ok, but what can I do?
Get and set properties, invoke methods, get all properties values and more in objects that you don’t know the Type. Yes, this is cool!
Getting a property value
object person = new Person { Name = "Arthur", Age = 4 };
person.Get("Name");
>> Arthur
Setting a property value
person.Set("Name", "Francine");
Getting all properties values
var properties = person.Values();
foreach(var property in properties)
{
Console.WriteLine(property.Key + " = " + property.Value);
}
>> Name = Arthur
>> Age = 4
Good to use with Anonymous Objects
public void PrintName(object target)
{
Console.WriteLine(target.Get("Name"));
}
PrintName(new { Name = "Wagner" });
>> Wagner
Importing values of another object
object animal = new Animal { Age = 20 };
person.Import(animal);
person.Get("Name");
person.Get("Age");
>> Arthur
>> 20
Invoke a method
object name = "Francine";
name.Invoke("ToUpper");
>> FRANCINE
There are other utilities.
That’s All Folks… for now!

