witchcraft 0.1.2
Extensions to runtime reflection in D.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
witchcraft
Extensions to runtime reflection in D.
Witchcraft provides enhanced runtime reflection facilities for D classes. It provides a means to interact with fields, functions, constructors, classes, and user-defined attributes at runtime (features D is sadly lacking). All of this happens through a simple and familiar API inspired by Java's java.reflect
package.
Mix in some Witchcraft
Start with a simple class, mix in some Witchcraft,
import witchcraft;
class User
{
mixin Witchcraft;
string username;
string password;
string email;
}
And now you have some amazing new runtime reflection powers to play with.
void main()
{
Class c = User.classof;
// ... or new User().getClass;
// Create a new user object,
User user = cast(User) c.create;
// Iterate over fields . . .
foreach(field; c.getFields)
{
// Get value on instance 'user'
field.get(user).writeln;
}
}
Caveats
- Every class that needs reflective capabilities must mixin
Witchcraft
. This includes children of classes that already do! - Witchcraft reflection completely ignores protection attributes. Private fields and functions are accessible from everywhere through reflection. (although this may be a benefit in some cases!)
License
MIT
- Registered by Mihail K
- 0.1.2 released 8 years ago
- mintyfresh/witchcraft
- MIT
- Copyright © 2016, Mihail K
- Authors:
- Dependencies:
- none
- Versions:
-
0.1.9 2016-Feb-27 0.1.8 2016-Feb-27 0.1.7 2016-Feb-27 0.1.6 2016-Feb-26 0.1.5 2016-Feb-25 - Download Stats:
-
-
0 downloads today
-
1 downloads this week
-
6 downloads this month
-
1629 downloads total
-
- Score:
- 1.9
- Short URL:
- witchcraft.dub.pm