Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to cast system.obj...
Finance forum

How to cast system.object to enum type?

(0) ShareShare
ReportReport
Posted on by 920

Hi,

I create method in c# class that contains enum type as paramter:

createPrivilege(string _role, EUKSecurityLevel _securityLevel)

  EUKSecurityLevel is enum

then I call this method in x class :

securityLevel=EUKSecurityLevel ::Read;

eukAddElement.createPrivilege("test", securityLevel); 

But I get error  that createPrivilege(System.string,systme.object) is not found in the c# class

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to cast system.object to enum type?

    thanks Khushhal Garg :)

  • Verified answer
    Khushhal Garg Profile Picture
    Khushhal Garg 1,514 on at
    RE: How to cast system.object to enum type?

    x++ class should use enum2str function

    eukAddElement.createPrivilege("test", enum2str(securityLevel));

    or use this

    System.String securityLevelStr = enum2str(securityLevel);

    eukAddElement.createPrivilege("test", securityLevelStr);

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to cast system.object to enum type?

    Hi, thankf for reply

    I modified the method in c# class :

    createPrivilege(string _role, String _securityLevel)

    then I modified the x class:

    eukAddElement.createPrivilege("test", securityLevel.ToString());

    But I get the same error .

    Have you any example to explain more

  • Suggested answer
    Khushhal Garg Profile Picture
    Khushhal Garg 1,514 on at
    RE: How to cast system.object to enum type?

    Pass int from x++ to C# and then cast int to enum in C# code. it should work.

  • Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    RE: How to cast system.object to enum type?

    What is the namespace of EUKSecurityLevel that you use as the parameter of createPrivilege()?

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,735 Super User 2024 Season 2 on at
    RE: How to cast system.object to enum type?

    Hi Basma,

    C# is not aware of the enumerations used in Dynamics 365. So, "EUKSecurityLevel" is considered as a system object. Instead, you can use an integer or string type in your c# class. (integer might be different for each value is your enumeration is setup to be extensible).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans