LarsJ

DotNet.au3 UDF to access .NET Framework from AutoIt

9 posts in this topic




Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Lars,

Thanks for jumping on the .NET wagon, and delivering this nice UDF. !! 

In the theoretical background you provided, there's 1 crucial item missing to get to understand the full picture of the .NET CodeDOM Compiler Class ...

The .NET CodeDom Class is just a wrapper around the CSC and VBC EXE. And has some limitations :

https://stackoverflow.com/questions/7852926/microsoft-roslyn-vs-codedom 

CodeDom is a precursor to Roslyn, but is only marginally related. Essentially, CodeDom is a simple and (somewhat) language agnostic way to generate code that was added in .NET 1.0 to support designers (a la WinForms). Because CodeDom was an attempt at providing a unified model that can generate code in C#, VB, and other languages, it lacks high fidelity with any of the languages that it supports (that's why you can't create a switch statement with CodeDom). CSharpCodeProvider.CompileAssemblyFromSource is simply a wrapper around executing csc.exe

...
One big difference I see: with CodeDom, each time you compile some C# or VB.NET, it happens out of process. CSC.exe or VBC.exe are the real workers behind the scene.

So basically you can do the same with just a few lines of code.

DotNet Compiler Wrapper

image64.png

Hopefully you keep us surprising with your expertise on this matter :)

Rgds

ptrex

 

Edited by ptrex

Share this post


Link to post
Share on other sites

Hopefully, I do not offend anyone by saying that the code in CLR.au3 is a bit messy. DotNet.au3 is primarily a rewrite of CLR.au3 so the code appears a bit nicer. And at the same time it's a complete translation of CLR.ahk. DotNet.au3 (and CLR.ahk) can also be used on Windows XP.

I'm not very excited about the .NET Framework or .NET code, so don't expect a lot of code from me.

There are a few topics that I find interesting, which I also find interesting from an AutoIt point of view. One of these topics is the ability to execute compiled code in particular in relation to array manipulations.

This is illustrated in the example with prime numbers. So this is the kind of examples with just a few code lines I have in mind. And for such small pieces of code, I don't think I need anything more advanced than this. All examples I've tested works fine.

There are a few other topics I find interesting. Maybe I'll make a couple of examples for these topics.

The section in first post about .NET concepts is just a simple overview. It certainly is not the full picture of anything. And I don't think you need the full picture to use the UDF or to add compiled C# or VB code to your AutoIt scripts.

Share this post


Link to post
Share on other sites

Not offended at all ... always happy to see a good UDF popping up. ;)

Just wanted to complete that background info, which dependencies CodeDom has (relying on CSC.exe and VBC.exe), for those who wants to take a shortcut..

(Please regard this as complementary info)

At least it must have been a good "Brain Gym" for you doing the conversion from AHK to AU3 ;)

Rgds

ptrex

Share this post


Link to post
Share on other sites

Would be nice to see example on generics. We struggle with the powershell automation namespace when we get a collection of psobjects back. Will check the clr and dotnet udfs to see if this udf gives better result. Endstate should be a broad native support for .net.

Share this post


Link to post
Share on other sites

ptrex, I was very curious to see if it was possible in a straightforward way to translate the AutoHotkey code into AutoIt code. And that was possible. My conclusion is that there is not much they can do in AutoHotkey code that we can't do in AutoIt code.

junkew, I don't think there are many generic examples that are particular interesting from an AutoIt point of view. I have read most of the posts. I have to admit that I have not clicked all the links. I don't use PowerShell so I'll not be able to help in this area.

Share this post


Link to post
Share on other sites
  1. The general problem we face in clr.au3 but assume with dotnet.au3 will be similar (i will test coming week) is calling methods on generic collections. 
    So also looking for another function in another namespace that return(s) a generic collection and manage it from AutoIt code (no issue in C#).
    Powershell collection is just an example 
Return Value
Type: System.Collections.ObjectModel.Collection(Of PSObject)
A Collection(Of T) collection of PSObject objects that contain the output of the pipeline.

 2 .  Exercise :D instead of compiling with the compilers of .net you can emit on the fly (much harder and did not see many examples on the internet)
      https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/emitting-dynamic-methods-and-assemblies
      would be in the end similar to FASM solutions but then completely in AutoIt.

Share this post


Link to post
Share on other sites

Larj,  Thanks, ....Good to know we don't have to be shy working with AU3 rather than AHK :ILA2:  It's a pitty you don't use PowerShell because it has a lot to offer !  As mentiioned before it can access all .NET classes and much more. But then again if you don't have a use case for it, it makes sense.

Junkew, Yes I still hope someone can break this open how to access the PSOBJECT Members  which is derived a .NET BASE Object:)

AutoIt returns  these values from IsObj () COM Object Type:

$objPsCollection = $pObjectPS.EndInvoke($objAsync)
    
ConsoleWrite("$objPsCollection: " & IsObj($objPsCollection) & @TAB & "$objPsCollection: " & ObjName($objPsCollection) & " - " & ObjName($objPsCollection,6) & " - " & ObjName($objPsCollection,3) & @CRLF)
Quote

$objPsCollection: 1    $objPsCollection: Object - {81C5FE01-027C-3E1C-98D5-DA9C9862AA21} - System.Object

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now