简体   繁体   中英

using #if to determine if code is running on WP8

I have a class defined in a Portable Class Library. In that class I have an int that I only want to be have the [DataMember] attribute if the code is running on WP8, how to achieve this?

There should be a way to use #IF but I'm not sure of the syntax and the conditionals, something like this(pseudo-syntax):

#if (condition for WP8) then
include this line: [DataMember]
public int TrackingId { get; set; }

Also, how could I check for other environments than WP8?

try wrapping your [DataMember] attribute with

#if WINDOWS_PHONE8

#endif

like

public class SomeContract
{
#if WINDOWS_PHONE8
    [DataContract]
#endif
    public string MyProperty { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM