Last active
January 7, 2017 18:27
-
-
Save neikeq/db685eda63e558d207abf12dececa51b to your computer and use it in GitHub Desktop.
Y U GIVE ME AN ABSOLUTE PATH :(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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