Hi
I've trying to create a shorter way to write - to save time :-
using wl = Debug.WriteLine;
I've declared this at the top of the project but I get a compile error. Can anyone tell me how to set the alias properly :-
Debug.WriteLine("");I've like to be able to write such commands like this if possible:-
wl("");
Thanks
Matt
VulpesPosted Nov 14, 2012, 12:05 PM
Muhammad ImranPosted Nov 14, 2012, 12:00 PM
using System.Collections.Generic;
public static void ToDebug
{
System.Diagnostics.Debug.WriteLine(obj.ToString());
}
you may call it as:
string s="This is a text";
s.ToDebug();
etc..
VulpesPosted Nov 13, 2012, 9:24 AM
Matt HigginsPosted Nov 13, 2012, 4:15 AM
This command looks good but it doesn't compile :-
Action
I get a compile error:-
Error 1 Cannot create delegate with 'System.Diagnostics.Debug.WriteLine(string)' because it has a Conditional attribute
Any idea why this error appears
Thanks
Matt
Muhammad ImranPosted Nov 12, 2012, 1:48 PM
Action
then use anywhere in that class...
wl("Your text here");
VulpesPosted Nov 12, 2012, 9:01 AM
using D = System.Diagnostics.Debug;
unfortunately, there's no way to create a file-wide alias for a method in C#.
You can effectively do it at type level e.g.
class MyClass
{
static void wl(string s)
{
Debug.WriteLine(s);
}
public void SomeOtherMethod(string s)
{
wl(s);
// ....
}
// ...
}
but it's tedious to do this in more than a couple of classes.