XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

[SOLVED] System.ComponentModel (Xbox)

Last post 7/2/2009 4:12 PM by Avalon2006. 3 replies.
  • 7/2/2009 9:58 AM

    [SOLVED] System.ComponentModel (Xbox)

    I'm having a bit of bother with System.ComponentModel.

    My game engine targets both Windows and Xbox.  The Windows build has a custom debugger in it, where the game pauses and a form opens with a PropertyGrid, which displays information about my game content.

    In order to make the PropertyGrid readable, I've added various field attributes my properties, e.g.:

            [CategoryAttribute(pgID), DescriptionAttribute("Internal ID"), ReadOnlyAttribute(true)]  
            public string id { getset; } 

    However the Xbox360 version of System.ComponentModel doesn't contain definitions for these attributes, so it won't compile.  I can get around this using pre-processor symbols, e.g.:

    #if WINDOWS  
            [CategoryAttribute(pgID), DescriptionAttribute("Internal ID"), ReadOnlyAttribute(true)]
    #endif  
            public string id { getset; }  

    However, the code soon gets very ugly when dozens of properties are dealt with in the above way.  I've searched the forums and I'm surprised that nobody else seems to have encountered this problem, especially given how many people have made level editors etc.  Does anyone know of a more elegant way around this that I've overlooked?

    Thanks.

    XAGE - Xna Adventure Game Engine
  • 7/2/2009 2:00 PM In reply to

    Re: System.ComponentModel (Xbox)

    You could hide the code using #region.

    Maybe you could subclass the Attribute classes and make them empty shells for #if XBOX? Not sure if that would work.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 7/2/2009 3:12 PM In reply to
    • (2342)
    • premium membership MVP
    • Posts 1,226

    Re: System.ComponentModel (Xbox)

    What I do is I have a .cs file that's only compiled in the Xbox 360 project (you could also just use #if's as well) where I define "dummy" versions of the attributes I use that aren't available.  It's pretty easy to do...you just need to make sure you define any constructors you're using.  You don't need to define any of the properties or anything as long as your own code doesn't try to access them.  This lets me add attributes with reckless abandon, without having to put ugly #if's everywhere.
    Matt Pettineo | DirectX/XNA MVP


    Ride into The Danger Zone | PIX With XNA Tutorial
  • 7/2/2009 4:12 PM In reply to

    Re: System.ComponentModel (Xbox)

    Thanks guys!  Such a simple solution, I can't believe I didn't think of it.

    For anyone else who may come across the same problem, here are the stub classes I created for the Xbox project:

     

    using System;  
    namespace System.ComponentModel  
    {  
        // Dummy classes for Xbox so we can happily ignore the property attributes (for PropertyGrid)  
        public sealed class BrowsableAttribute : Attribute  
        {  
            public BrowsableAttribute(bool dummy) {}  
        }  
        public sealed class CategoryAttribute : Attribute  
        {  
            public CategoryAttribute(string dummy) { }  
        }  
        public sealed class DescriptionAttribute : Attribute  
        {  
            public DescriptionAttribute(string dummy) { }  
        }  
        public sealed class ReadOnlyAttribute : Attribute  
        {  
            public ReadOnlyAttribute(bool dummy) { }  
        }  
        public sealed class DisplayName : Attribute  
        {  
            public DisplayName(string dummy) { }  
        }  

     

    XAGE - Xna Adventure Game Engine
Page 1 of 1 (4 items) Previous Next