Thursday, June 13, 2013

c# Get numeric value of Enum

I have an Enum as follows:

public enum ApprovalStatus
{
    ReviewRequired = 657070000,
    Approved = 657070001,
    Rejected = 657070002

}

I have an function that passes in the literal value of this enum:

public void AddBillHeader(string org, ApprovalStatus approvalStatus)
        {
            IOrganizationService svc = GetXrmService(org);
            Entity bh = new Entity("fcbt_billheader");

            bh["fcbt_approvalstatus"] = //NEED THE NUMERIC VALUE OF THE ENUM HERE

            svc.Create(bh);
        }
To do that, I have to convert the value to an Int - simple as that:
(int)approvalStatus;



No comments:

Post a Comment