|
IMHO the best design it's il rewriting . You as you said can do it by reflection , of course you must write a il parser to achieve that.
For instance you could inject code to do new things like checking the code , adding new funcionality , or you can profile it, etc, etc ...
To do this I advise you read the ECMA specs of the IL language (CIL or MSIL or ...) , and to read "Inside IL Assembler" or "Programming CIL", 2 good books about the IL Language and to read Compiling for .NET that shows some good tricks to parse and generate IL code via Reflection or component pascal .
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
Thaxs for your'e suggestions - I got a book on IL (don't remember the exact name) and I really want to implement it at that level if it is possible. However, theres a difference between IL in it's text form (the OPcodes in text) and the ones that resides in the module/assembly (the "compiled" ones). As I understood it, your suggestion is that I learn the numerical form of OP-codes, parse the binary and modifies the codes with my own enhancements at that level? The problem is, I can't see the connection between the reflection of an object, and the IL code that represent it. Let's say I start using Reflection, and finds a type that qualifies for enhancment - is there a way to, for example, get a memorystream of the IL representation of that type, and the fields/properties within it? That's what I'm after.
In short, this is what I would like to do:
// Do iterate type's in assembly A1
// Found a type with a certain attribute, say [MyAttr()]
// Iterate all instance-fields that type contains
// For each field, retreive the IL code for it, and change that code with my enhancment
// Write the enhanced type back to assembly A1
/psatvz
|
|
|
|
|
psatvz wrote:
// Do iterate type's in assembly A1
// Found a type with a certain attribute, say [MyAttr()]
// Iterate all instance-fields that type contains
// For each field, retreive the IL code for it, and change that code with my enhancment
// Write the enhanced type back to assembly A1
Yes, it's full possible to do it with Reflection
Reflection permits generation of il on memory , and serialization of the results to disk.
You could check source code of Reflector for .NET on http://www.aisto.com/roeder/dotnet/[^]
or the source of Anakrino decompiler(do a search on google) to help you with retrieving your il.
Forget the parser , with reflection, you have access to function names,I think that you don't have access to local names of the variables (or at least I didn't see this anywhere on the web or on the books ...), then you can add the attribute to the piece of code that you want and rewrite the il of the original application (dangerous), or write to a new assembly.
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
Man - thanx! This was a great opening, now I got enough to start working with.
Really - thanks a lot!!
/psatvz
|
|
|
|
|
Ok, no that I know how to do this (thanx to the tips I got here) I came up with a new idea, based on this, witch leads to a antoher question, namely:
Is it possible to change/enhance the once allready loaded code for a given type, during runtime?
My guess is no (since it seems like to much of a risk to allow such a thing), but I have to assure that it can't be done until I can drop it, since it would be such a great solution to what I am trying to solve. So, what I would like to do is basically this:
* A type is loaded into memory, and all metadata allong with it (methodtables etc etc).
* My enhancer code (allready in memory) is 'nofified' of this loaded type (this, I allready know how to do).
* My enhancer code detects that this type has a property/method X that qualifies for 'enhanced' logic (know how to do aswell).
* My enhancer code looks up the memory where the IL-code for the property/method X resides (I think I know how to do this, but I'm not sure).
* My enhancer makes sure that code is 'enhanced' with the right features, and when the property/method X is invoked, the 'enhanced' code is executed by the runtime instead of the original code.
The difference between this and my first approach (witch I now know how to do) is that the code-enhancing is carried out in memory, and my first approach was parsing the IL-code on disk (e.g without loading the types that where to be enhanced), enhanced it and then wrote the enhanced code back to disk.
Any help highly appreciated!
/psatvz
|
|
|
|
|
You might want to look at John Lam's work for a .NET aspect weaver[^]
Unfortunately I don't see any mention of a way of getting a hold of his weaver; but perhaps if you e-mailed him he could give you more information than I
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thanks James, that was a good tip. Especially since I've read almost nothing on AOP, and his site (and his RAW software, the one you told me about, in particular) got me interested in that. However, just as you said, I can't either find any way to get the software, or find any more information bout it. I'll maybe send him a mail, as you suggested.
Thanks again!
/psatvz
|
|
|
|
|
Ok, now I've found out how to solve the case, and how to implement my code enhancer the absolutly best way (by, during runtime, switch the enhance-qualified IL-code before Jitted), so for the moment I'm fully satisfied.
Thanx everybody!
/psatvz
|
|
|
|
|
Im wondering if someone find any way to use an http port other than 80 to ship the library to the client side. To create Embedded Windows form.
For those that do not understand here a nice and simple tutorial on how display Windows Form inside internet explorer.
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=388
Thanks.;)
(define Email (lambda ()
elacroix@videotron.ca))
Im not a church numeral im a free variable
|
|
|
|
|
Is it possible to enumerate through the "members" of an enum, say, to fill a combo box? I want to do something like the following (which I've verified already that it doesn't work):
Dim I As IEnumerable
For Each I In System.DayOfWeek
MsgBox(I.ToString())
Next
Thanks in advance.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
This is how you would do it:
myComboBox.Items.AddRange(System.DayOfWeek.GetNames()); This'll get the names in a string[]. The Items property of the ComboBox is an ObjectCollection, so it has the AddRange method. Which has a signature of:
public void AddRange(object[] items);
Because string is an object, you will be able to add the items to the combobox.
The problem with what you were trying to do is that you defined I as IEnumerable. A class implements IEnumerable to let it's consumer know that it can enumerate through it's collection. You can't loop through an object's IEnumerables because that doesn't exist.
Hope I helped.
David Stone
But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*.
Shog9
|
|
|
|
|
Hey David, thanks for the reply! I know I can't use IEnumerable; I just stuck it in there to demonstrate basically what I was trying to do; I never tried to compile that. I had completely forgotten that the GetNames member was there, because my Intellisense doesn't show it unless I type System.Enum.GetNames. It also doesn't show things like Page.RegisterClientScriptBlock, despite that being a perfectly valid method. Oh well.
Again, thanks a ton.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Right, you should actually define I as IEnumerator, thorugh David's code is a better way to accomplish what you're wanting.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
hi
it seems there is a new step accomplished on the road of generic implementation: it's called Gyro
see @
http://research.microsoft.com/projects/clrgen/
it looks cool
what do you thinks about it?
NB: it seems this guy deliver upgrade every 4 monthes since last year and this it beta .. perhabs a proposal at the end of the year??
|
|
|
|
|
Thanks for the link
Generics for me it's a great piece of extra flexibility and a must for .Net 2.
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
Hello cpians
I was working my way through the System.Windows.Forms namesapce and couldn't find an essential class.
in MFC you could turn a CPropertySheet into a wizard with just one line of code. I couldn't find a way to create a wizard with the .NET FCL.
does anyone know of such a way, or do I hve to create a collection of Panels, and "next" and "back" buttons and do it myself?
thanks
Noam
Noam Ben Haim
Web Developer
Intel
noam.ben.chaim@intel.com
|
|
|
|
|
Sadly it is one of those major holes in the .NET experience. You have to roll your own Wizards.
Have a look at http://www.sellsbrothers.com/tools/Genghis/[^] for one already done.
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
This is agrivating and I thought about posting it in the Soapbox forum because this is more of a rant; but the standard Web Controls don't generate proper XHTML and this sux. I guess, you're asking how should it, you never told it you wanted XHTML. But that is just the point. Some of us take pride in producing very specific code even if it is HTML. And the use of Web Controls is limiting this a bit.
Case in point for those who are intrested: DataGrid, HeaderStyle has an attribute horizontalalign which I would like to set to center. It changes it to Center. Not much I understand but there is a difference. It's not to spec.
They that can give up essential liberty to purchase a little temporary safety deserve neither liberty or safety.
--Benjamin Franklin
|
|
|
|
|
Talk to Paul Watson about this - it's a pet peeve of his as well.
IMO the HTML generated by the Web Controls is appalling.
cheers,
Chris Maunder
|
|
|
|
|
Paul Menefee wrote:
And the use of Web Controls is limiting this a bit.
As Chris said, a pet peeve of mine. In fact I have yet to use a single .NET Web Control for a public web site project. I use them for back-end admin suites etc. where code purity is not such an issue, but even there I cringe when I see the crap .NET generates.
I do not actually know what MS was thinking. They could have even have just generated good HTML 4.01 and I would have been happy (at least then it would have been simple to change it to XHTML compliant.)
I still have not tried but you can "re-write" the HTML that web controls generate. So I am sure in the near future someone is going to release a slew of XHTML compliant .NET Web Controls.
Even so, web controls IMO are not ready for prime time. They require too much server round-tripping and many of their great features means allowing wads of hidden elements on your page filled with paragraphs of data, hardly condusive to fast web applications.
And don't get me started on VS.NET and it's "helpful" HTML features. I still do not know how to turn off that annoying "feature" where when you paste some HTML it inserts IDs into all the elements.
I use ASP.NET solely for the access to "proper" languages, not for the web controls or postback features etc.
|
|
|
|
|
I've written an interface in C# which I've marked as a dual COM-interface.
The interface:
[
InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("5ECF7F7A-974D-4e5d-9329-679C0D2D3F99")
]
public interface ICodeColorizer {
string Colorize(string strOrgCode);
}
My questions are:
- How do I implement a COM-class using this interface in native C++?
- How do I use this COM-class in the .NET application?
1. I have no idea about this one.
2. I guess it's just enough to add the COM-reference.. right?
I tried adding the interface with the same GUID in the COM-project and use that. But .NET had second thoughts on type-equality. According to .NET the original interface as written in C# was not the same interface as the one specified in my COM-idl file.
|
|
|
|
|
1. You got to use regasm.exe first (or tlbexp.exe) to produce a .tlb and register the object.
2. Provide implementation for this interface in your class. I believe at this point you've got to use special attributes such like ComSource .
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site. Support for development will ship at the same time as the Windows XP Service Pack 1 (SP1) release.
|
|
|
|
|
There's a thread in the lounge that talks about what to use to start a new project for .NET; most says that C# is the way to go, over Managed C++.
Why ? isn't it the same ? isn't the same .net framework ? the syntax is different, but that's no biggies, I can live with it, so what's the difference ?
I have the Visual C++.net box and doesn't come with support for C#, but there's a csc.exe ( C# compiler ) somewhere on my machine, is it the same compiler that would come if I bought the C#.net box (or the full visual studio )? I tries to compile a simple "hello world" program with that csc.exe compiler and it looks ok!
Thanks.
Max.
|
|
|
|
|
|
Managed C++ can do a few things that C# can't, firstly you can produce regular unmanaged applications as well as .NET applications (which you can't with C#). You can also mix and match managed and unmanaged code in the same application, so from a regular MFC app you can make .NET calls.
Not to mention that you already have the VC++.NET box, so you have the IDE to make it easier. There's nothing to stop you using the csc compiler, but it'll get really tough once you start to do anything more than a simple program.
If you've not used VC++ 6 (or any other version of VC++) then you should be in a good position to get on with the VC++.NET IDE.
I personally would recommend going with MC++ (despite its messyness) since if you get on with that you open yourself up to being able to produce almost anything.
--
Paul
"I need the secure packaging of Jockeys. My boys need a house!"
- Kramer, in "The Chinese Woman" episode of Seinfeld
MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446
|
|
|
|
|