Pass in an enum as a method parameter

前端 未结 4 1681
北海茫月
北海茫月 2020-12-30 18:52

I have declared an enum:

public enum SupportedPermissions
{
    basic,
    repository,
    both
}

I also have a POCO like this:

<         


        
4条回答
  •  攒了一身酷
    2020-12-30 19:30

    Change the signature of the CreateFile method to expect a SupportedPermissions value instead of plain Enum.

    public string CreateFile(string id, string name, string description, SupportedPermissions supportedPermissions)
    {
        file = new File
        {  
            Name = name,
            Id = id,
            Description = description,
            SupportedPermissions = supportedPermissions
        };
    
        return file.Id;
    }
    

    Then when you call your method you pass the SupportedPermissions value to your method

      var basicFile = CreateFile(myId, myName, myDescription, SupportedPermissions.basic);
    

提交回复
热议问题