Back to building DLLs: Determining if a class is abstract or public

 

In the world of VS 2008 and VS 2010, as well as all of the older development tools from Microsoft, the creation of DLLs is fully supportedimage.  But just how do we utilize the DLLs?  First for the concept of DLLs to make sense, we need to understand classes, so I am going over the concept of classes step by step, but in my usual random manner, I have to ask that you stick with it. 

 

 

 

 

 

In XNA, the SpriteBatch, for example, is it a public class or an abstract class.  I was able to determine this using this kind of flunky process, but it works and it is quick:

First I wanted to examine if SpriteBatch was an abstract class so I used the following code, using the basic XNA Template (File-New-C#-XNA Game Studio X.X – Windows Game) using the default name:

       protected override void Draw(GameTime gameTime)
        {
            //GraphicsDevice.Clear(Color.CornflowerBlue);

            var x = typeof(SpriteBatch);

            if (x.IsAbstract)
                GraphicsDevice.Clear(Color.Red);
            else
                GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here          

 

 

Just cut and paste the code starting at the protected override void Draw(GameTime gameTime).  Press the F5 key, your “game” should should show a black gameboard, indicating that SpriteBatch is not an abstract class.

  • Replace: x.IsAbstract
  • With: x.IsPublic
  • The code should look like:                

if (x.IsPublic)
      GraphicsDevice.Clear(Color.Red);
else
      GraphicsDevice.Clear(Color.Black);

In this case the gameboard becomes black, indicating that the SpriteBatch is a public class.

Which is kind of a dumb way to do the analysis, but I just wanted to do something that was quick and dirty. 

Although this code will work in .NET Frameworks 2.0, 3.0, 3.5, and 4.0, be a sport and install the latest version of XNA Game Studio 3.1, you will need to uninstall the earlier versions of XNA Game Studio for the XNA Game Studio 3.1 to install. 

In this Blog we experimented with how to determine if a class is abstract or not, and we used some crude instrumentation to do our test.  In a future blog, sometime in the future, I will cover how to use interfaces and why, these are like abstract classes but with important differences.