TheSwamp

Code Red => .NET => Topic started by: It's Alive! on August 31, 2007, 01:18:48 PM

Title: Anyone mess with Orcas yet?
Post by: It's Alive! on August 31, 2007, 01:18:48 PM
I wrote my first C# lambda expression today and it worked.. :|
For those who are interested, the C# 3.0 specification has been published
http://msdn2.microsoft.com/en-us/vcsharp/default.aspx

seems they added a ton of stuff to the language and to .NET 3.5 , more stuff to learn

Code: [Select]
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace cSharpTest
{
    public class SoSharp
    {
        [LispFunction("test1")]
        public static void DoTest1(ResultBuffer Args)
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            List<TypedValue> list = new List<TypedValue>(Args.AsArray());
            list.ForEach ( p => ed.WriteMessage(p.ToString()));
        }
    }
}


Title: Re: Anyone mess with Orcas yet?
Post by: It's Alive! on August 31, 2007, 02:55:27 PM
here is a fun one

Code: [Select]
//(test2 64)
        [LispFunction("test2")]
        public static void DoTest2(ResultBuffer Args)
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            List<TypedValue> list = new List<TypedValue>(Args.AsArray());

            Func<UInt64, UInt64> Factorial = null;
            Factorial = (n) => n <= 1 ? 1 : n * Factorial(n - 1);

            ed.WriteMessage("{0}", Factorial(Convert.ToUInt64(list[0].Value)).ToString());
        }

9223372036854775808
Title: Re: Anyone mess with Orcas yet?
Post by: LE on August 31, 2007, 10:47:17 PM
44616E69656C;

Can this beta be use with AutoCAD 2007 ?
Title: Re: Anyone mess with Orcas yet?
Post by: Kerry on August 31, 2007, 11:19:35 PM

I've had it installed for a while, but haven't made the time to play yet Daniel ... looks like you're having fun !
Title: Re: Anyone mess with Orcas yet?
Post by: It's Alive! on August 31, 2007, 11:27:09 PM
44616E69656C;

Can this beta be use with AutoCAD 2007 ?

Yes, that’s what version I was testing on. Since it’s still beta, I just stuck it on my laptop but I haven’t had any problems.
Title: Re: Anyone mess with Orcas yet?
Post by: It's Alive! on August 31, 2007, 11:32:43 PM

I've had it installed for a while, but haven't made the time to play yet Daniel ... looks like you're having fun !


Yes, I think it’s pretty cool so far, I just hope they don’t make the language so feature full that it becomes bloatware.
Title: Re: Anyone mess with Orcas yet?
Post by: It's Alive! on September 01, 2007, 01:18:25 PM
You can now target a specific framework in your project. In this function I targeted the 2.0 framework

Code: [Select]
static void Main(string[] args)
    {
      var TypedValueList = new List<KeyValuePair<int, int>>();
      for (int i = 0; i < 10; i++)
      {
        for (int x = 0; x < 10; x++)
        {
          TypedValueList.Add(new KeyValuePair<int, int>(x, i));
        }
      }
      var eList = TypedValueList.FindAll
        (pairs => pairs.Key == 0 && pairs.Value > 5).GetEnumerator();

      while (eList.MoveNext())
      {
        Console.WriteLine("\n{0}", eList.Current);
      }
      Console.ReadKey();
    }
And reflector picked up this
Code: [Select]
private static void Main(string[] args)
{
    List<KeyValuePair<int, int>> TypedValueList = new List<KeyValuePair<int, int>>();
    for (int i = 0; i < 10; i++)
    {
        for (int x = 0; x < 10; x++)
        {
            TypedValueList.Add(new KeyValuePair<int, int>(x, i));
        }
    }
    List<KeyValuePair<int, int>>.Enumerator eList = TypedValueList.FindAll(delegate (KeyValuePair<int, int> pairs) {
        return (pairs.Key == 0) && (pairs.Value > 5);
    }).GetEnumerator();
    while (eList.MoveNext())
    {
        Console.WriteLine("\n{0}", eList.Current);
    }
    Console.ReadKey();
}


So it seems that some of the new language features are backwards compatible with older frameworks
Title: Re: Anyone mess with Orcas yet?
Post by: It's Alive! on September 01, 2007, 02:01:21 PM
This is the same as above but I am using LinQ to query an in-memory collection using an extension method with a lambda expression.  :lol:

Code: [Select]
static void Main(string[] args)
    {
      var TypedValueList = new List<KeyValuePair<int, int>>();
      for (int i = 0; i < 10; i++)
      {
        for (int x = 0; x < 10; x++)
        {
          TypedValueList.Add(new KeyValuePair<int, int>(x, i));
        }
      }

      Func<KeyValuePair<int, int>, bool>
        Filter = pairs => pairs.Key == 0 && pairs.Value > 5;

      var eList = TypedValueList.Where(Filter).GetEnumerator();

      while (eList.MoveNext())
      {
        Console.WriteLine("\n{0}", eList.Current);
      }
      Console.ReadKey();
    }
Title: Re: Anyone mess with Orcas yet?
Post by: Kerry on September 02, 2007, 01:14:48 AM
LinQ ..
That reminds me of something I bookmarked recently

http://www.albahari.com/linqpad.html


and while I'm at it ...
' Reflexil is an assembly editor and runs as a plug-in for Lutz Roeder's Reflector. '
http://sourceforge.net/project/showfiles.php?group_id=200895

edit: Fixed lazy Sunday spelling ..
Title: Re: Anyone mess with Orcas yet?
Post by: sinc on September 04, 2007, 05:14:28 PM
Yes, I think it’s pretty cool so far, I just hope they don’t make the language so feature full that it becomes bloatware.

Now that's an optimist.  After all this time, still hoping to see non-bloatware out of Microsoft...   :-D
Title: Re: Anyone mess with Orcas yet?
Post by: Kerry on September 05, 2007, 05:21:31 AM
This may be worth bookmarking ..
Jomo Fisher -- C#, LINQ and Whatnot

http://blogs.msdn.com/jomo_fisher/archive/2007/07/23/the-least-you-need-to-know-about-c-3-0.aspx

FrontPage:

http://blogs.msdn.com/jomo_fisher/default.aspx

added/edit: links changed