---
title: "Change Ugly code in our project"
author: "lua"
date: "2009-11-23T17:48:19Z"
tags: []
slug: "change-ugly-code-in-our-project"
draft: false
lastmod: "2009-11-23T17:49:13Z"
id: 523814
url: "https://lua.iteye.com/blog/523814"
---

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;