.

create a comma seperated lists

The following code will create a comma seperated list for you

public List<string> RolesAllowedToView { get; set; }

int RolesAllowedCount = RolesAllowedToView.Count;
if (RolesAllowedCount > 0)
    {
    int loopctr = RolesAllowedCount;
        var rolesLine = "";
        foreach (var r in RolesAllowedToView)
            rolesLine += "\"" + r + "\""+((loopctr-- > 1)?  ", " : "");
        Console.WriteLine("[Authorize(Roles = "+rolesLine+")]");
    }

 

renders the following:

[Authorize(Roles = "one")]

[Authorize(Roles = "one", "two", "three")]

What's your thoughts on this?

*

Protected by WP Anti Spam