Monotouch and Lion

July 29, 2011

I have been like many developers following the progress of mono. Mono is the open source implementation of Microsoft’s proprietary .NET Framework.  There has been a lot of buzz on a recent development name Monotouch. Monotouch gives  you the developer the ability to program in C# for the iOS platform.

The iOS platform consists of 3 products currently – iPhone, iPOD Touch and the iPAD. All 3 products have been commercially great successes. So I decided to develop on this platform. I have been a c# developer since the beta of the .NET Framework. I still somewhere have the cds Microsoft sent out.

So once I made up my mind – I bought the latest Mac Mini. The system was the 599 USD version with Lion and Xcode 4.  I then followed the directions setting up my machine.  In hind sight I wish I did  the set up slightly different.  The current version of  Monotouch does not , I repeat, does not work well with Xcode 4. But if you are like me you would want xcode 4 as well.  In fact I got a number of errors. Partial list of examples below.

The solution was to roughly- ( see below for the exact steps)

  1. Install Xcode 3.2.6 to /Applications/Developer.
  2. Copy the developer folder to Developer3.
  3. install Xcode 4 to /Applications/Developer.

So what I did ultimately and it seems to work

  1. Install Mono
  2. Install MonoDevelop
  3. Install Xcode 4
  4. Install Monotouch
  5. Copy Developer Folder  (containing Xcode 4) to Developer4
  6. Install XCode 3.2.6     (please follow these directions from daniele! So Click that link!)
  7. Install Monotouch (yet again)
  8. Copy Developer Folder  (containing Xcode 3) to Developer3
  9. Copy Developer4 Folder  (containing Xcode4) to Developer
  10. Now In order to use IB (interface Builder) I used the excellent advice from Geoff Norton
  I am compiling and runing iPhone Monotouch apps in the simulator on Lion with the current version of Monotouch.
So I can work in Xcode 4 and because I chose the right options while install xcode 3 make app for earlier version of MAC OS X and universal binaries as well.

Specific First Record via LinQ

September 9, 2010

I have not written to this blog in a while. But I will try to more often.

I was looking for  a way in Linq to bring certain records in focus by being first in the sort. After Looking around  and see this post. I came up with the following.

public static class linqExtentions
  public static IEnumerable SpecificRecordFirst(this IQueryable query, string PropertyToTest,object PropertyValue)
   Type propertyType = query.GetType().GetGenericArguments()[0];
   PropertyInfo property = propertyType.GetProperty(PropertyToTest, BindingFlags.Instance | BindingFlags.Public);
MethodInfo whereMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m => m.Name == "Where").ToArray()[0].MakeGenericMethod(propertyType);

ParameterExpression parameter = Expression.Parameter(propertyType,"m");
MemberExpression member = Expression.MakeMemberAccess(parameter,propertyType.GetProperty(PropertyToTest));
BinaryExpression equal = ParameterExpression.Equal
(PropertyValue != null) ? Expression.Constant(PropertyValue, PropertyValue.GetType()) : null
LambdaExpression lambda = Expression.Lambda(typeof(Func<,>).MakeGenericType(propertyType, typeof(Boolean)), equal, member.Expression as ParameterExpression);
IQueryable query2 = whereMethod.Invoke(null, new Object[] { query, lambda }) as IQueryable;
if (query2.Count() < 1)                 throw new Exception("SpecificRecordFirst- First Record Doesnt Exist");
if (query2.Count() > 1)
throw new Exception("SpecificRecordFirst- First Record is not unique");
yield return query2.First();
BinaryExpression Notequal = ParameterExpression.NotEqual
(PropertyValue != null) ? Expression.Constant(PropertyValue, PropertyValue.GetType()) : null
LambdaExpression lambda2 = Expression.Lambda(typeof(Func&lt;,&gt;)
.MakeGenericType(propertyType, typeof(Boolean)), Notequal, member.Expression as ParameterExpression);
IQueryable query3 = whereMethod.Invoke(null, new Object[] { query, lambda2 }) as IQueryable;
foreach (var elem in query3)
yield return elem;

I wrote this 6 in the morning. I am wondering If this could be done differently.


I thought about this a little more . Here

public static IEnumerable SpecificRecordsFirst(this IQueryable query, Expression<Func> expression)
   Func func = expression.Compile();
   var firstRecords = query.Where(func.Invoke);
  foreach (var firstRecord in firstRecords)
     yield return firstRecord;
  var secondRecords = query.Except(firstRecords.AsEnumerable());
  foreach (var secondRecord in secondRecords)
     yield return secondRecord;

Much better IMHO


Get every new post delivered to your Inbox.