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

  • SEARCH
  • Home
  • 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 6893005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:36:18+00:00 2026-05-27T06:36:18+00:00

I am working on a game project using Microsoft XNA framework, although this question

  • 0

I am working on a game project using Microsoft XNA framework, although this question is a generic one that involves decoupling of classes/systems.

Let’s say i have a class (simplified to suit this example) as shown here:

public class GameCell
{   
        public Color Color { get; set; }
}

I would like to reuse as much code as i can between multiple platforms that use C#.

The problem of directly referncing the Color struct is that this type is defined in the XNA assemblies, creating a strong coupling (or dependency) between my code and XNA.

The other framework i will be using may (or may not) have its own Color object, with its own set of properties and API.

I would like to have the same source file “know” to use either the XNA or other framework’s implementation automagically.

I know other types of decoupling methods such as IoC, but that would mean i would be plugging in different versions of a system/class, instead of reusing the same class in different contexts.

Is this even possible to do? how would u suggest to keep such a system portable?

I’ve seen some cases (in native C++ development) where you would define a set of classes that mirror the classes the framework you’re using has (for example here – define Color again), and so it is possible to “re-map” this later on to use different classes, upon need.

Another option is to mess around using #IFDEF to play with the using statements in the header of the class (switching from XNA to other platforms).
What is the best alternative in this case?

  • 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-27T06:36:18+00:00Added an answer on May 27, 2026 at 6:36 am

    Typically what you do is create your own Color structure and have it do the translation using conditional compilation switches. For example:

    #define USE_DOTNET
    //#define USE_SOMETHINGELSE
    
    #if USE_DOTNET
    using System.Drawing;
    #endif
    
    #if USE_SOMETHINGELSE
    using SomethingElse.Drawing;
    #endif
    
    public struct MyColor
    {
        #if USE_DOTNET
        Color TheColor;
        #endif
        #if USE_SOMETHINGELSE
        SomethingsColor TheColor;
        #endif
    
        public int R
        {
            get
            {
                #if USE_DOTNET
                    // code to return .NET Color.R value
                #endif
                #if USE_SOMETHINGELSE
                    // code to return SomethingColor.R value
                #endif
             }
        }
    }
    

    Another way is to have separate regions for the .NET and SomethingElse code. For example:

    #if USE_DOTNET
    public int R
    {
        get { return TheColor.R; }
    }
    // other properties and methods here
    #endif
    
    #if USE_SOMETHINGELSE
    // properties and methods for using SomethingElse
    #endif
    

    This can work well, but you have to be very careful when writing your code so that you don’t use the .NET Color structure anywhere but in these portability layers.

    We used this technique in C/C++ when developing games that had to run on Windows, the Mac, and several different game consoles. It’s a pain to set up the portability layers, but once they’re set up, it’s pretty easy to use.

    I would caution you, though, not to give your portability classes and structures the same names as classes or structures from the .NET libraries or the other libraries you’re using. If you do that, you’re going to confuse yourself, and you’re likely to write some non-portable code that you won’t discover until you start trying to port it. (Not that I’m speaking from experience or anything . . .)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a game project that involves a scripting language that I want to
I'm working on an XNA game and I am using ViewPort.Project and ViewPort.Unproject to
I am currently working on a game project in XNA 4.0 we currently read
I am working on a little pinball-game project for a hobby and am looking
I'm working on a class project to build a little Connect4 game in Java.
I am working on a debugger project for a game's scripting engine. I'm hoping
I'm working on a card game in C# for a project on my Intro
I am working on an artificial intelligence project which is a logic game and
I've been slowly working on a personnel project to run a webmud like game
I've been trying to get this Sudoku game working, and I am still failing

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.