Change Ugly code in our project

following code happens many times in our project:

 

                        xxxxxxx;


#if defined _ETHERNET
                        tmp1String = deviceKey.GetAddressAsString();
#else
                        tmp1String = deviceKey.GetNodeAsString();
#endif
                        yyyyyyy;

 

 

It should be changed like:

 

CString GetAddrString(DeviceKey& deviceKey)

{

        CString tmp1String;

#if defined _ETHERNET
                        tmp1String = deviceKey.GetAddressAsString();
#else
                        tmp1String = deviceKey.GetNodeAsString();
#endif

        return tmp1String;

}

 

then we could use the function like:

 

     xxxxxxx;

     tmp1String = GetAddrString(deviceKey);
     yyyyyyy;

 

 

你可能感兴趣的:(project)