How to write cross platfrom conditional compile work for system timer implementation?

I am porting a project from ios/android, which use system timer for Socket IO operation.
I do some dirty work and try to make it just compile. I use macro to seperate code from wp8 and ios/android like following.

public class dummy : MonoBehaviour {
	#if NETFX_CORE   
	System.Windows.Threading.DispatcherTimer timer = null;
	#else
	private System.Timers.Timer timer = null;	
	#endif
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

The code look fine in editor and after you build the code, it show error:
Error building Player: Exception: Error: type System.Timers.Timer doesn’t exist in target framework. It is referenced from Assembly-CSharp.dll at dummy.

I should use NETFX_CORE or something else to make the project built?

NETFX_CORE trick works only for Windows Store Apps. It won’t work for Windows Phone 8 - you’ll have to implement it in a separate DLL, rather than in your script.

Well thats just sad. WP8 is much bigger platform, why was this not done there as the namespace exists for WP8 as well…

Use:

#if UNITY_WP8 && !UNITY_EDITOR

that should get you through the editor compile issue. It will compile your original version for editor and then will compile the new version for wp8 using the SDK.

No that will not work as you can’t target the NETFX_CORE namespaces on WP8… only Win8 thus making it basically pointless as you normally use the same code for both. But its fine as I have a working solution that modifies the C# project file and adds in the correct post build cs files.

Ahh, yeah that would be an issue unless you’re targeting 8.1 or building a universal app.