Advertisement

Tip Jar:

One-Time Donation

Recurring Monthly $2 Donation Appreciated

The tip jar is to help contribute to keeping this site going. If you like what you see... feel free to help out!

Text Link Ads

Optional parameters in C# and X++

Go directly to Source

In the upcoming 4.0 version of C# the language now supports optional parameters – just like X++. The following is a valid method declaration in both languages:


public void foo(int parameter1, int parameter2 = 0, int parameter3 = 100)
{
}

There are a few differences between the languages with regards to optional parameters:


Named parameters


In X++ you can only omit optional parameters starting from the last parameter. C# makes it possible to omit any optional parameter. For example:


foo(5, parameter3: 1000)

will call foo(5, 0, 1000).


prmIsDefault


C# doesn’t provide a way to determine, if a parameter was omitted by the caller, or the caller passed in a value identical to the default value. In X++ the prmIsDefault() method can be used to determine this. However, the use cases for this method are rare – and often fragile. For example, consider this X++ class:


class BaseClass
{
    int value;
    public void init(int _value = 0)
    {
        if (prmIsDefault(value))
        {
            value = /* some complex calculation */
        }
        else
        {
            value = _value;
        }
    }
}
Now someone comes along and extends the class:
class MyClass extends BaseClass
{
    str myStr;
    public void init(int _value = 0)
    {
        myStr = ‘foo’;
        super(_value);
    }
}
Can you see the problem? This following code will never call the complex calculation (which probably was the intention):
MyClass myClass = new MyClass();
To solve the problem MyClass needs to be implemented as:
class MyClass extends BaseClass
{
    str myStr;
    public void init(int _value = 0)
    {
        myStr = ‘foo’;
        if (prmIsDefault(_value))
            super();
        else
            super(_value);
    }
}

Which really is terrible, as the implementation of the derived class depends on the implementation of the base class. This is bound to break eventually. Add a few more optional parameters and a few more levels of depth in the class hierarchy, and you’ll have a real nightmare. My recommendation is to only use prmIsDefault() in private methods – as they can’t be overridden. In C# you can easy live without this method, as you can achieve the same in a more robust manner using method overloading:


class BaseClass
{
    int value;
    public void init()
    {
        int _value = /* some complex calculation */
        this.init(_value);
    }
    public void init(int _value)
    {
        value = _value;
    }
}
<humor>It is a good thing we solved the dangling semicolon issue – otherwise it would haunt the C# community in a not too distant future.</humor>
Make sure to visit the author of this post!

The Excitement is Building for Convergence 2010 Atlanta!

Go directly to Source
Hosting your customers at Convergence is a great way to strengthen customer relationships, drive revenue opportunities, network with peers and Microsoft product experts—and to see the latest and greatest products and technologies.
Make sure to visit the author of this post!

US Sales & Marketing Insights: January 29, 2010

Go directly to Source
This newsletter provides US Microsoft Dynamics Partners with all the latest sales and marketing opportunities designed to accelerate marketing efforts and generate revenue goals for both new and existing customers.
Make sure to visit the author of this post!

Microsoft Dynamics AX and NAV BREP Policy Change for North America

Go directly to Source
The Business Ready Enhancement Plan (BREP) is currently required for most Microsoft Dynamics products when customers make additional license purchases. This policy has not been in effect for Microsoft Dynamics AX or Microsoft Dynamics NAV customers. Beginning June 1, 2010, Microsoft Dynamics NAV and Microsoft Dynamics AX (Module Based Licensing and Business Ready Licensing) customers will need to be enrolled in the Business Ready Enhancement Plan in order to make additional license purchases, such as additional modules and users. This policy change drives consistency across our customer base, and will help us provide additional value to our customers through innovative upgrades and updates.
Make sure to visit the author of this post!

TVH’s MCC Advanced Distribution for Microsoft Dynamics AX 2009 To Be Sold in US Via New Partner Group

Go directly to Source

Microsoft Dynamics Partner I.B.I.S., Inc has formed a partnership with France’s TVH Consulting, acquiring exclusive rights to resell TVH’s MCC (Multi Channel Commerce) Advanced Distribution Solution for Distributors and Retailers software for Microsoft Dynamics AX 2009 in the US.

As part of the move, a new Microsoft Dynamics partner group was brokered and will include five other Microsoft Gold Certified Partners under the Advanced Distribution Partners moniker. Collins Computing, InterDyn AKA, InterDyn BMI, Merit Solutions, Inc.<…

read more

Make sure to visit the author of this post!

The Year of the Cloud: How Coming Microsoft Products Will Make Dynamics AX the Basis of New Solutions

Go directly to Source

People have been talking about The Cloud for years, and now
it’s arrived. 2010 for sure will be the year of the Cloud. And though it’s not
on any official calendar, those born under the year of the cloud are sure to be
free thinkers, operational vs. capital based, have abilities to get projects
going on their feet — and into the cloud quickly.

Seriously, the next release,  or wave of
Microsoft products, will enable more and more solutions to actually be true
Hyrbid clouds. This means Dynamics AX customers will need to understand what is
expected, as part of their solution design. 
The next wave is just the very first part of what is on the horizon.
Microsoft Dynamics AX is the bu…

read more

Make sure to visit the author of this post!

From the AX Blogs: Data Protection Manager 2010; Keyboard Shortcuts in AX 2009; Updating Multiple Records with Fill Utility

Go directly to Source

Disaster Recovery with Data Protection Manager (DPM) 2010: Brandon George touts the value of investing in DPM: "Alright, so one of the topics that everyone should have conversations about when implementing Dynamics AX, is DR, or disaster recovery. This is something, that I find sometimes, clients and customers do not pay enough attention to. This is a very critical point, and a customer needs to check and test their DR plans to make sure they actual do what they are suppose to do. Now enter System Center Data Protection Manager 2010… This is a true Data Protection …

read more

Make sure to visit the author of this post!

Make The Switch to PartnerSource North America

Go directly to Source
We heard you loud and clear! In usability studies and personal feedback, you’ve told us that the Global PartnerSource site didn’t quite suit your needs. It’s been a long time coming, but we finally launched the North American PartnerSource site, to serve our partners in Canada and the United States.
Make sure to visit the author of this post!

U.S. Partner Executive Program News for Microsoft Dynamics: January 2010

Go directly to Source
This newsletter delivers critical program updates for Microsoft Dynamics partners in the U.S., including activities surrounding the MBS Competency, Microsoft Dynamics partner training and readiness events, launch, partner program updates, resources, recognition opportunities, and much more.
Make sure to visit the author of this post!

Behind the Latest Microsoft Dynamics AX Statement of Direction: Insights Into Strategy, Support, and Commitment

Go directly to Source

In any ERP selection, apart from product functionality and technical capabilities customers need to be able to plan for the future development–thus, they need to know about the product strategy, support roadmap, environmental interoperability flexibilities and commitment from the product vendor. The latest Microsoft Dynamics AX Statement of Direction (SOD), which I originally discussed on my blog (http://bit.ly/5ZLkIX) earlier provides precise answers to these critical issues. The SOD also reaffirms Microsoft’s long-term schedule for release of future versions of Dynamics AX.

The Product Vision is organized according to thre…

read more

Make sure to visit the author of this post!

Next Page »

MCP Logos