Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, March 6, 2015

Having fun with C# dynamic and reflection: create a class that let us to avoid access modifier

Yeah, the title says it all.

Have you ever get tired of manually call reflection methods to get a value of an hidden field? Yes I do!

In my spare time I found a funny solution to work around this problem.
I found a dummy way to avoid access modifier without losing 'deafult' syntax: thanks to c# dynamic object!
public class MyClass
{
    private int value = 1 ; 
}
private static void Main(string[] args)
{
    MyClass myInstance = new MyClass();

    //cannot access private field 'value' here
    //myInstance.value = 2;

    dynamic myInstance2 = myInstance.Expose();

    //can do it!
    myInstance2.value = 2;
}

Monday, July 1, 2013

Convert from jar to dll

Nowadays, development is very eased from community.
We can easily re-use our code between different platforms in so many ways, gaining time, money and above all... today have multiple skills is not so as useful as before.

By the way, I recently had necessity to bring some java code to .NET runtimes.
No difficulties with IKVM.NET !

If you follow these steps you can convert from JAR to DLL or even from Runnable JAR to EXE!

Thursday, January 12, 2012

Syntax Highlighter in Blogger

Effettivamente il modo con cui postavo il codice,oltre al codice stesso, ha sempre fatto un po' ridere...

Visto che su Blogger non esistono plugin simili (credo) come in WordPress per mettere in risalto le righe di codice postate io da ignorante utilizzavo questo tool e successivamente applicavo "a mano" i colori.

Il codice è abbastanza visibile ma per me ogni volta diventava un peso stare li a evidenziare stringhe, commenti ecc...
E lì che per caso noto Syntax Highlighter! Un progetto Javascript opensource, forkabile in Github, integrabile su praticamente tutti i blog compreso questo schifo di Blogger :)