Ivan's Brain Dump




read

Yesterday I created a few macros to generate some C# code for me in my editor of choice SlickEdit . I have decided to start a page on my SlickEdit “hackings” , where you can download the C# helper macros and possibly more in the future.

For a given class:

public class Test
{
    public void SomeMethod (Type variableName)
    {
    }
}

cs_generate_property (_str access=”public”)

Generates a property from the variable under cursor. The property is placed just below the method body in which the variable is. This command also generates a class field just below the class signature. The command defaults to public properties, but the access could be set as an optional parameter.

public class Test
{
    private Type _variableName;

    public void SomeMethod (Type variableName)
    {
    }

    public Type VariableName {
        get { return _variableName; }
        set { _variableName = value; }
    }
}

cs_generate_argument_null_check ()

Generates a null check and ArgumentNullException throw for the method parameter under cursor in the beginning of the method body.

public class Test
{
    public void SomeMethod (Type variableName)
    {
        if (variableName == null)
            throw new ArgumentNullException ("variableName");
    }
}

cs_generate_field_from_local ()

Generates a class field from the variable under cursor just after the class signature in the form of “_variableName”

public class Test
{
    private Type _variableName;

    public void SomeMethod (Type variableName)
    {
    }
}
Blog Logo

Ivan Zlatev


Published

Image

Ivan's Brain Dump

Back to Overview