Skip to content

Instantly share code, notes, and snippets.

@neikeq
Last active January 7, 2017 18:27
Show Gist options
  • Select an option

  • Save neikeq/db685eda63e558d207abf12dececa51b to your computer and use it in GitHub Desktop.

Select an option

Save neikeq/db685eda63e558d207abf12dececa51b to your computer and use it in GitHub Desktop.
Y U GIVE ME AN ABSOLUTE PATH :(
[System.AttributeUsage(System.AttributeTargets.Class)]
public class ScriptClass : System.Attribute
{
public string filePath;
public ScriptClass ([System.Runtime.CompilerServices.CallerFilePath] string path = "")
{
filePath = path;
}
}
[ScriptClass]
class MainClass
{
public static void Main (string[] args)
{
new MainClass();
}
public MainClass()
{
ScriptClass MyAttribute = (ScriptClass)Attribute.GetCustomAttribute(this.GetType(), typeof(ScriptClass));
if (MyAttribute == null)
{
Console.WriteLine("The attribute was not found.");
}
else
{
Console.WriteLine("The Class Path is: {0}." , MyAttribute.filePath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment