-
Notifications
You must be signed in to change notification settings - Fork 0
Meta
Get various meta information.
Getting meta information in C# can be tricky. Some helper method can come in handy.
This method gets information about whatever called your code. It walks the stack which might be expensive.
void MyFirstMethod(){
MySecondMethod();
}
void MySecondMethod(){
var callingMethod = CompulsoryCow.ReflectionUtilities.GetCallingMethod();
// callingMethod.Name is now "MyFirstMethod".
}
This method returns the System.Type of the class in the parameter. If nothing is found an System.ArgumentException exception is thrown.
This method retuns the System.Type of the class in the parameter. If nothing is found null is returned.
This method retuns the System.Type of the class in the parameter. If nothing is found an System.ArgumentException exception is thrown.
This method retrieves a class by its Assembly, Namespace and Class name. If nothing is found an System.ArgumentException exception is thrown. See https://msdn.microsoft.com/en-us/library/w3f99sx1.aspx for how to write more complex class names like nested and generic. Hint: Nested classes are denoted with a + character like "Customer+Address".
This method gets information about the property you are in.
class MyClass{
public string Title{
get{
// Just call with this.GetProperty.
Log( "The user just called the property" + this.GetProperty().Name );
return _title;
}
}
}
GetPrivateField, GetPrivateStaticField, GetPrivateProperty GetPrivateStaticProperty, GetPrivateMethod, GetPrivateStaticMethod
var method = Meta.GetPrivateMethod(anObject, "GetCustomer");
method.Invoke(anObject, new[]{42});
Warning: These methods might be deprecated in the future in favour of ReachIn.
This method returns PropertyInfo for all public properties for a type.
Use recurse for telling it to, recursively, dive into properties.
Note: Types can be complex so make sure it can follow yor properties' types,
them being classes or enumerations or arrays or whatnot.
Use it like so:
var ps = GetPublicProperties(typeof(T), true);
A method retrieving information about the calling method. Warning: This method might be deprecated as it only works properly in debug compile and doesn't behave as expected as it contains the historical where-you've-been but rather where it will go when it returns.