KevinDarty.NET

Programming on the Edge... of something

Posts tagged DotNet

0 notes &

Downloading and Installing IronRuby

Have you been wanting to try out IronRuby but haven’t yet taken the plunge? Mohammad Azam aka AzamSharp takes you step by step through setting up Msysgit on Windows to downloading and configuring IronRuby.

Along with this ScreenCast is a corresponding First Look at IronRuby article on his HighOnCoding Site for those that might prefer having it all in writing as a guide to help you get started.

Mohammad has a lot of great Articles, PodCasts and ScreenCasts on his site so make sure to check out HighOnCoding

Direct Link To The YouTube Version of this video here.

Viewing Tip: Make sure to click the “HD” icon to watch the ScreenCast in full quality.

Filed under Ruby DotNet IronRuby

Notes &

iPhone App Development for .NET Developers

Have you been dying to get into iPhone Application Development but scoffed at the learning curve of Objective-C and the Cocoa Touch Framework? It’s true, there is a lot to learn and I am sure as a .NET Developer, specifically a C# Developer you have probably been wishing there was a way to use the language you have grown to love to program for the iPhone.

Unfortunately, the iPhone doesn’t allow JIT Applications to run. This means that no 3rd Party runtimes such as .NET or Java are allowed on the iPhone.

So how can you run a .NET Application on the iPhone?

For a while now Unity3D via Mono was an option but an expensive one.

While Unity3d is a great option for Game Development Companies, it might be a little hefty on the pocketbook for the average Hobbyist Developer or Home Based Startups.

MonoTouch sets to change this by providing first class iPhone Application Development using C# and .NET via XCode or their own MonoDevelop IDE.

Keep in mind that there are limitations to programming for the iPhone using C# and .NET using MonoTouch such as:

  • No Dynamic Code Generation including:
    • Reflection
    • Remoting
  • No COM Bindings
  • Limitations to Reverse Callbacks

As you can tell by clicking around through the MonoTouch web pages, there isn’t much there quite yet. MonoTouch is new and still under development but should prove to be a great way for .NET Developers to take advantage of their existing C# and .NET Skills to Develop for the iPhone and iPod Touch Platform.

Miguel de Icaza has a little tease for us on his blog “Hello from MonoTouch”.

For an iPhone Development Platform that hasn’t even been released yet, MonoTouch has sure set the Development world ablaze today with the promise of things to come.

I for one am looking forward to this 8)

Discuss on FriendFeedhttp://ff.im/4B4Ws

Filed under iPhone DotNet CSharp Mono

Notes &

Looping through Constants and other Fields

In a project I inherited I noticed that the previous Developer made heavy use of Constants and tended to do some rather laborious if/then conditional checks related to these Constants.

Here is the pattern of code used:

  1. if (MethodToCheckIfNeeded(Class.Constant))
  2. return (MethodToDoAction(Class.Constant);
* This source code was highlighted with Source Code Highlighter.

NOTE: You would replace “Class” with the defining class/type and “Constant” to the specific Constant value you are inspecting

The idea is that the IF condition runs a “check” based on the value of the Constant to determine if action is needed. If action is indeed necessary then the code runs the associated “action” method sending in the same Constant value as the parameter.

This is not only laborious but it means that for every new Constant of the “type” being checked you have to go add corresponding if/then checks everywhere to handle this new data.

The really bad part is that this same conditional check is done several times based on the same Constant values. The previous Developer just kept doing that over and over again. You would have thought he would have seen a “pattern” there.

This Developer also tended to prefix Constant Variables with a “type” such as PARAM, FLD or TBL. With this in mind, we can easily loop through the “fields” of the class to either make a list or initiate an action on a given Constant.

Here is a solution that can easily be re-used:

  1. // Define the Constant Values to be used
  2. public const string PARAM_ONE = ”This”;
  3. public const string PARAM_TWO = ”is”;
  4. public const string PARAM_THREE = ”a”;
  5. public const string PARAM_FOUR = ”better”;
  6. public const string PARAM_FIVE = ”solution”;
  7. FieldInfo[] fieldInfo = this.GetType().GetFields();
  8. string constantValues = string.Empty;
  9. foreach (FieldInfo fi in fieldInfo)
  10. {
  11. // We are only looking for Constants
  12. if (fi.IsLiteral)
  13. {
  14. if (fi.Name.Substring(0, 6) == ”PARAM_”)
  15. constantValues += fi.GetValue(fi) + ” “;
  16. }
  17. }
  18. if (constantValues != string.Empty)
  19. MessageBox.Show(constantValues);
* This source code was highlighted with Source Code Highlighter.



Notice in the sample above that I am checking only for Constants that have a prefix of “PARAM_”.

Also notice that I am limiting my check down to “literals” which means they are values that are defined at runtime and not changed (i.e. Constants).

There are other checks you can do there as well.

Another thing to note is that the GetFields() method also provides for further filtering using BindingFlags such as Public, Static, etc. In this case my Constants are Public and that is the default for GetFields().

Just to illustrate the technique, I am concatenating the values of the “PARAM” Constants into a single String and Displaying the “message” via a MessageBox.

In the case of the problem I am trying to solve, in the loop I could call the “IsNeeded” method using the Constant’s Value and in the “then” part of the condition I could call the “Action” method with that same value.

You could further create a List of these values that could be re-used in other methods so that you don’t have to re-run this code again to retrieve the values but either way you still have to do a loop to get the job done.

Clean, simple and I don’t have to keep adding new if/then code every time I add new Constants of a given “type”.

I like it :D

I’m sure there are other solutions so if anyone would care to share please do.

Filed under DotNet CSharp