Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:17:36+00:00 2026-05-25T14:17:36+00:00

I’m working with an XSD -> C# class parser which generates classes for our

  • 0

I’m working with an XSD -> C# class parser which generates classes for our data model, which is to be shared between a WPF client and a Silverlight web-based portion.

We are trying to augment the generated classes with [DataContract] attributes that should only be used when the SILVERLIGHT symbol is not defined, i.e.:

#if !SILVERLIGHT
[DataContract]
#endif
public class Class1 { /* ... */ }

How can I add this #if / #endif block to the CodeTypeDefinition of the Class1, or to the CodeAttributeDeclaration of DataContract?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:17:36+00:00Added an answer on May 25, 2026 at 2:17 pm

    What I’ve actually decided to do is add the #if / #endif tags through a Python script, after the code file is generated. Robert’s reply is functionally valid, but I just didn’t feel right using two separate classes when one should be just fine.

    Although it introduces another language into the data model generation, this seems like the cleanest way to get exactly what I want. The script we are using is below. It only needs to check for NonSerializable attributes (specifically, on PropertyChanged events) now because of a new way we structured the data contract.

    #!/usr/bin/env python
    
    import sys
    from optparse import OptionParser
    import shutil
    
    # Use OptionParser to parse script arguments.
    parser = OptionParser()
    
    # Filename argument.
    parser.add_option("-f", "--file", action="store", type="string", dest="filename", help="C# class file to parse", metavar="FILE.cs")
    
    # Parse the arguments to the script.
    (options, args) = parser.parse_args()
    
    # The two files to be used: the original and a backup copy.
    filename = options.filename
    
    # Read the contents of the file.
    f = open( filename, 'r' )
    csFile = f.read()
    f.close()
    
    # Add #if tags to the NonSerialized attributes.
    csFile = csFile.replace('        [field: NonSerialized()]',
                        '        #if !SILVERLIGHT\r\n        [field: NonSerialized()]\r\n        #endif')
    
    # Rewrite the file contents.
    f = open( filename, 'r' )
    f.write(csFile)
    f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.