web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Cast generic Object to class

(0) ShareShare
ReportReport
Posted on by

I am currently trying to cast a generic object to a specific class, with no luck yet.

Here is the scenario. I am receiving a generic object, and need to convert it to a specific type of a class. I tried the below, but none is working. Any ideas on how to make this work would be greatly appreciated.

class speicificClass()
{
str parm1, parm2;

public str parm1(str _parm1 = parm1)
{
parm1 = _parm1
return parm1
}

public str parm2(str _parm2 = parm2)
{
parm2 = _parm2
return parm2
}
}

Object genericClass;

SpecificClass specificClass;


//method 1 - cast generic to specific
specificClass = genericClass as SpecificClass();

//method 2
specificClass = genericClass;


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    SaverioT Profile Picture
    330 on at

    Try:

    specificClass = genericClass as SpecificClass;

    without parentesis ().

  • Matthew C Profile Picture
    on at

    Tried it but getting a null value on the specific class.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    What's the actual type of object that you have in genericClass variable? It seems that it's not compatible with SpecificClass, therefore the cast is invalid.

  • SaverioT Profile Picture
    330 on at

    SpecificClass must extend generic class.

    This declaration is missing in the sample file that you given.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans