<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="it-IT">
    <title>MVP Wannabe!</title>
    <link rel="self" type="application/atom+xml" href="http://blogs.ugidotnet.org/MVPWannabe/Atom.aspx" />
    <subtitle type="html">mykenta.blogspot.com .NET blog</subtitle>
    <id>http://blogs.ugidotnet.org/MVPWannabe/Default.aspx</id>
    <author>
        <name>Cristian Carlesso a.k.a. kentaromiura</name>
        <uri>http://blogs.ugidotnet.org/MVPWannabe/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 2.1.0.3">Subtext</generator>
    <updated>2009-06-18T20:51:12Z</updated>
    <entry>
        <title>"Lesser" less per c# e asp.net MVC </title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2009/06/18/lesser-less-per-c-e-asp.net-mvc.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2009/06/18/lesser-less-per-c-e-asp.net-mvc.aspx</id>
        <published>2009-06-18T20:31:18Z</published>
        <updated>2009-06-18T20:51:12Z</updated>
        <summary type="html">Come integrare facilmente un preprocessor per css in asp.net MVC


premessa:

Tutto è nato da questo post su EDIT (il blog di html.it): http://blog.html.it/18/06/2009/less-estendere-i-css

Ho pensato che sarebbe stato comodo avere una specie di pre-compilatore per i css che facesse esattamente quello che Cesare Lamanna ha esposto, ovvero aggiungere ai css le costanti e i mixins integrato nel mio sito in asp.net mvc

...</summary>
        <content type="html">Come integrare facilmente un preprocessor per css in asp.net MVC


premessa:

Tutto è nato da questo post su EDIT (il blog di html.it): http://blog.html.it/18/06/2009/less-estendere-i-css

Ho pensato che sarebbe stato comodo avere una specie di pre-compilatore per i css che facesse esattamente quello che Cesare Lamanna ha esposto, ovvero aggiungere ai css le costanti e i mixins integrato nel mio sito in asp.net mvc

...&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/96461.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/96461.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/96461.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/96461.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Sort su un' interfaccia di una lista generica utilizzando una lambda per definire il campo da filtrare su un oggetto qualsiasi</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2009/01/29/sort-su-un-interfaccia-di-una-lista-generica-utilizzando-una.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2009/01/29/sort-su-un-interfaccia-di-una-lista-generica-utilizzando-una.aspx</id>
        <published>2009-01-29T21:50:26Z</published>
        <updated>2009-01-29T22:10:23Z</updated>
        <content type="html">&lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Arial"&gt;Giocherellando un po su stackoverflow, ho notato la seguente domanda:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Arial"&gt;&lt;a href="http://stackoverflow.com/questions/485567/avoiding-code-repetition-when-using-linq"&gt;http://stackoverflow.com/questions/485567/avoiding-code-repetition-when-using-linq&lt;/a&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;In pratica viene chiesto un parere su come separare la logica di selezione di un campo da ordinare all' interno di una funzione di sort generica in maniera da evitare la riscrittura dello stesso codice, che differisce, sostanzialmente, solo ed esclusivamente per il campo in cui la sort agisce.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;La soluzione proposta da Matt Hamilton và più che bene, se non che è fortemente legato ad una lista definita privatamente nella classe e che comunque è legata ad una classe di selezione che è a sua volta fortemente legata all' oggetto a cui si fa il sorting, nulla di male in tutto ciò, se uno vuol far il sorting, conosce l' oggetto del quale vuol ordinare un determinato campo.&lt;/p&gt;
&lt;p&gt;Ho comunque voluto cimentarmi con un astrazione maggiore del Sort richiesto, aggiungendo un metodo Sort all' interfaccia generica &lt;font face="Verdana"&gt;IList&amp;lt;T&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;a href="http://stackoverflow.com/questions/485567/avoiding-code-repetition-when-using-linq/491449#491449"&gt;http://stackoverflow.com/questions/485567/avoiding-code-repetition-when-using-linq/491449#491449&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;public&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;static&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;class&lt;/span&gt;&lt;/font&gt;&lt;span class="pln"&gt; extIList &lt;/span&gt;&lt;span class="pun"&gt;{&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
   &lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span class="kwd"&gt;public&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;static&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;IList&lt;/span&gt;&lt;/font&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="pln"&gt;&lt;font color="#0000ff"&gt;T&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;Sort&lt;/span&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="pln"&gt;&lt;font color="#0000ff"&gt;T&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;TKey&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;(&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span class="kwd"&gt;this&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;IList&lt;/span&gt;&lt;/font&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="pln"&gt;&lt;font color="#0000ff"&gt;T&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;&lt;/span&gt;&lt;span class="pln"&gt; list&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#339966"&gt;SortOrder&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; sortOrder&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Func&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="pln"&gt;&lt;font color="#0000ff"&gt;T&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;TKey&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;&lt;/span&gt;&lt;span class="pln"&gt; keySelector&lt;/span&gt;&lt;span class="pun"&gt;)&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;{&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;span class="kwd"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="pln"&gt;sortOrder &lt;/span&gt;&lt;span class="pun"&gt;==&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;SortOrder&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Descending&lt;/span&gt;&lt;span class="pun"&gt;)&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;{&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
                &lt;/span&gt;&lt;span class="kwd"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;OrderByDescending&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="pln"&gt;keySelector&lt;/span&gt;&lt;span class="pun"&gt;).&lt;/span&gt;&lt;span class="typ"&gt;ToList&lt;/span&gt;&lt;span class="pun"&gt;();&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;span class="pun"&gt;}&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;&lt;font color="#0000ff"&gt;else&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;{&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
                &lt;/span&gt;&lt;span class="kwd"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;OrderBy&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="pln"&gt;keySelector&lt;/span&gt;&lt;span class="pun"&gt;).&lt;/span&gt;&lt;span class="typ"&gt;ToList&lt;/span&gt;&lt;span class="pun"&gt;();&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;span class="pun"&gt;}&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
    &lt;/span&gt;&lt;span class="pun"&gt;}&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="pun"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In questa maniera si può utilizzare la funzione di sort su un qualsiasi oggetto, &lt;/p&gt;
&lt;p&gt;nell' esempio ho usato un oggetto Person che ha due proprietà Name e Surname:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;IList&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Person&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;&lt;/span&gt;&lt;span class="pln"&gt; list &lt;/span&gt;&lt;span class="pun"&gt;=&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;List&lt;/span&gt;&lt;span class="pun"&gt;&amp;lt;&lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Person&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;&amp;gt;();&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
&lt;br /&gt;
list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Add&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="kwd"&gt;new&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Person&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="str"&gt;"David"&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="str"&gt;"Beckham"&lt;/span&gt;&lt;span class="pun"&gt;));&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Add&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="kwd"&gt;new&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Person&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="str"&gt;"Gennaro"&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="str"&gt;"Gattuso"&lt;/span&gt;&lt;span class="pun"&gt;));&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Add&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="kwd"&gt;new&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="typ"&gt;&lt;font color="#0000ff"&gt;Person&lt;/font&gt;&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="str"&gt;"Cristian"&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="str"&gt;"Carlesso"&lt;/span&gt;&lt;span class="pun"&gt;));&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
&lt;br /&gt;
list &lt;/span&gt;&lt;span class="pun"&gt;=&lt;/span&gt;&lt;span class="pln"&gt; list&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Sort&lt;/span&gt;&lt;span class="pun"&gt;(&lt;/span&gt;&lt;span class="typ"&gt;SortOrder&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Descending&lt;/span&gt;&lt;span class="pun"&gt;,&lt;/span&gt;&lt;span class="pln"&gt; &lt;font style="BACKGROUND-COLOR: #ffff00"&gt;X &lt;/font&gt;&lt;/span&gt;&lt;font style="BACKGROUND-COLOR: #ffff00"&gt;&lt;span class="pun"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="pln"&gt; X&lt;/span&gt;&lt;span class="pun"&gt;.&lt;/span&gt;&lt;span class="typ"&gt;Name&lt;/span&gt;&lt;/font&gt;&lt;span class="pun"&gt;);&lt;/span&gt;&lt;span class="pln"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Comunque siccome la logica di sorting è delegata alla parte evidenziata e siccome è slegata completamente dal tipo di oggetto che le viene passato, è possibile utilizzare la sort su un qualsiasi altro campo di un qualsiasi altro oggetto ;-) &lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/95347.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/95347.aspx</wfw:comment>
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/95347.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/95347.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Object To Generic Pattern</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2008/07/08/object-to-generic-pattern.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2008/07/08/object-to-generic-pattern.aspx</id>
        <published>2008-07-08T06:07:41Z</published>
        <updated>2008-07-09T03:48:45Z</updated>
        <content type="html">&lt;br /&gt;
Ultimamente sto usando Ninject che usa i generics in un modo che mi ha fatto ripensare al mio codice, in particolare mi sono imbattuto in un pattern che può essere riassunto cosi:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="font-family: Verdana; font-weight: bold;"&gt;
&lt;p&gt;Ogniqualvolta un metodo ritorna un &lt;span style="color: rgb(0, 0, 128);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;object&lt;/span&gt; è molto probabile che possa tornare un generics&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Perchè?&lt;br /&gt;
&lt;br /&gt;
Se un metodo ritorna un oggetto è molto probabile che si tratti di un metodo di una classe di factory, visto che &lt;span style="color: rgb(0, 51, 102);"&gt;object &lt;/span&gt;è il padre di tutti gli oggetti, fino all avvento dei generics risultava naturale, ritornare o un interfaccia nota, o un &lt;span style="color: rgb(0, 51, 102);"&gt;object&lt;/span&gt; generico.&lt;br /&gt;
&lt;br /&gt;
Per esempio mi è capitato di usare questa metodologia quando ho creato uioc, un container ioc per cf2.0 ( http://codeplex.com/uIoC ) , che piu che un container ioc è una superfactory che richiama gli oggetti tramite stringa anzichè nome.&lt;br /&gt;
&lt;br /&gt;
Comunque indipendentemente da questo, ritornare un object comporta il quasi sicuramente dovere fare un cast dove si richiama il metodo, esempio:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;public class &lt;/span&gt;Pippo{&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    &lt;span style="color: rgb(0, 51, 0);"&gt;public object&lt;/span&gt; Get(&lt;span style="color: rgb(0, 51, 102);"&gt;string&lt;/span&gt; id){&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;        &lt;span style="color: rgb(0, 51, 102);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 51, 102);"&gt;this&lt;/span&gt;.container[id];&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    }&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;}&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;br /&gt;....&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;Pippo p = &lt;span style="color: rgb(0, 51, 102);"&gt;new&lt;/span&gt; Pippo();&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;p.initialize();&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;IList&lt;/span&gt; lista = (&lt;span style="color: rgb(0, 51, 102);"&gt;IList&lt;/span&gt;)p.get(&lt;span style="color: rgb(255, 0, 0);"&gt;"Lista di sviluppatori javascript"&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;se volessimo aggiungere uno sviluppatore dovremo fare o un &lt;br /&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;lista.add(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0); font-family: Courier New;"&gt;"Andrea Giammarchi"&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;);&lt;/span&gt;&lt;/pre&gt;
oppure il scomodissimo&lt;br style="font-family: Courier New;" /&gt;
&lt;pre style="font-family: Courier New;"&gt;((&lt;span style="color: rgb(0, 51, 102);"&gt;Ilist&lt;/span&gt;)p.get(&lt;span style="color: rgb(255, 0, 0);"&gt;"Lista di sviluppatori javascript"&lt;/span&gt;)).add(&lt;span style="color: rgb(255, 0, 0);"&gt;"Andrea Giammarchi"&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
se invece cambiassimo il metodo in &lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;public T &lt;/span&gt;Get&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;T&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 51, 102);"&gt;string &lt;/span&gt;id){&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    &lt;span style="color: rgb(0, 51, 102);"&gt;return this&lt;/span&gt;.container[id];&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;}&lt;/pre&gt;
&lt;br /&gt;
potremo scrivere&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;pre style="font-family: Courier New;"&gt;p.get&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;IList&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 0, 0);"&gt;"Lista di sviluppatori javascript"&lt;/span&gt;).add(&lt;span style="color: rgb(255, 0, 0);"&gt;"Andrea Giammarchi"&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
non abbiamo quadagnato molto in termini di codice scritto, ma abbiamo 2 vantaggi,&lt;br /&gt;
il primo è che l intellisense ci fornisce direttamente i metodi una volta chiusa la parentesi, senza dover esplicitare il cast&lt;br /&gt;
il secondo abbiamo eliminato il &lt;s&gt;boxing/unboxing&lt;/s&gt; Cast dell &lt;span style="color: rgb(0, 51, 102);"&gt;IList &lt;/span&gt;che ci permette di non avere cast non validi a runtime&lt;br /&gt;
e nel contempo dovrebbe ottimizzare un po la velocità di esecuzione ( a scapito di un maggiore grandezza dell'eseguibile )&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;...e se dovessimo ritornare &lt;span style="color: rgb(0, 0, 128);"&gt;null&lt;/span&gt;?&lt;/h3&gt;
&lt;br /&gt;
potrebbe essere in metodi che ritornano un object che in caso di errore in creazione e affini si voglia tornare &lt;span style="color: rgb(0, 51, 102);"&gt;null&lt;/span&gt;..&lt;br /&gt;
usando un generics ovviamente non è possibile tornare&lt;span style="color: rgb(0, 51, 102);"&gt; null&lt;/span&gt;, ci viene in soccorso la keyword &lt;span style="color: rgb(0, 51, 102);"&gt;default&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
esempio:&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;if&lt;/span&gt;(hoAvutoUnProblema){&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;   &lt;span style="color: rgb(51, 153, 102);"&gt; // return null&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    &lt;span style="color: rgb(0, 51, 102);"&gt;return default&lt;/span&gt;(&lt;span style="color: rgb(0, 51, 0);"&gt;T&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;}&lt;/pre&gt;
&lt;br /&gt;
che ritorna un valore di default.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Potremo applicare questa metodologia anche quando, per esempio, si deve passare un oggetto &lt;span style="color: rgb(0, 51, 102);"&gt;Type&lt;/span&gt; come parametro ad un metodo, che ci costringe a scrivere &lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;typeof&lt;/span&gt;(NostraClasse)&lt;/pre&gt;
&lt;br /&gt;
esempio anzichè:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;public void &lt;/span&gt;register(&lt;span style="color: rgb(0, 51, 102);"&gt;string&lt;/span&gt; id, &lt;span style="color: rgb(0, 51, 102);"&gt;Type&lt;/span&gt; type){&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    &lt;span style="color: rgb(0, 51, 102);"&gt;this&lt;/span&gt;.container.add(id, type);&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;}&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;br /&gt;..&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;p.register(&lt;span style="color: rgb(255, 0, 0);"&gt;"lista di programmatori"&lt;/span&gt;,&lt;span style="color: rgb(0, 51, 102);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(0, 51, 102);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;string&lt;/span&gt;&amp;gt;));&lt;/pre&gt;
&lt;br /&gt;
avremo:&lt;br /&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;br style="color: rgb(0, 51, 102);" /&gt;&lt;span style="color: rgb(0, 51, 102);"&gt;public void &lt;/span&gt;register&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;T&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 51, 102);"&gt;string&lt;/span&gt; id){&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;    &lt;span style="color: rgb(0, 51, 102);"&gt;this&lt;/span&gt;.container.add(id,&lt;span style="color: rgb(0, 51, 102);"&gt;typeof(T)&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;}&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;..&lt;/pre&gt;
&lt;pre style="font-family: Courier New;"&gt;p.register&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 51, 102);"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;(&lt;span style="color: rgb(255, 0, 0);"&gt;"lista di programmatori"&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
questo ci permette di scrivere qualche carattere in meno.&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/93335.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/93335.aspx</wfw:comment>
        <slash:comments>16</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/93335.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/93335.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Eliminazione dei for in c# 3.5</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2008/06/25/eliminazione-dei-for-in-c-3.5.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2008/06/25/eliminazione-dei-for-in-c-3.5.aspx</id>
        <published>2008-06-25T04:59:37Z</published>
        <updated>2008-06-25T05:24:33Z</updated>
        <summary type="html">Nel seguente post dimostrero' come le nuove funzionalita' offerte dal nuovo compilatore di c# possano venir incontro ad una programmazione piu parlante, in particolare vedremo come utilizzare gli extension method e le lamda expression per eliminare i for nei programmi :d</summary>
        <content type="html">Recentemente ho assistito ad una serie di incontri organizzati dall' &lt;a href="http://www.xplabs.it"&gt;XPLabs&lt;/a&gt;, introduttivi al mondo dell &lt;a href="http://it.wikipedia.org/wiki/Programmazione_estrema"&gt;XP&lt;/a&gt;.&lt;br /&gt;
Indipendentemente dall effettivo o meno miglioramento che si ottiene seguendo certi canoni ho voluto un attimo approfondire alcuni punti che erano rimasti in sospeso.&lt;br /&gt;
In particolare non avevamo approfondito la metodologia da applicare per eliminare i for dal codice,&lt;br /&gt;
e cosi ho trovato &lt;a href="http://www.xplabs.it/docs/francesco-cirillo/2007/JavaDayRoma2007-EliminareFOR.zip"&gt;questa presentazione in powerpoint&lt;/a&gt; che spiega come farlo in Java.&lt;br /&gt;
&lt;br /&gt;
Sinceramente prima di leggerlo mi ero già fatto un idea di come si potessero eliminare in c# e la soluzione illustrata non dista molto da quella che avevo pensato io che a uso dei delegati.&lt;br /&gt;
&lt;br /&gt;
Comunque siccome quella slide ha ispirato questo articoletto, ho voluto citarla per correttezza.&lt;br /&gt;
&lt;br /&gt;
Una soluzione piu simile a quella proposta si può ottenere molto semplicemente usando le nuove estensioni del linguaggio offerte dal nuovo compilatore c#&lt;br /&gt;
in particolare in questa prima parte vedremo come utilizzare le lambda expression e gli extension method per ottenere un codice "parlante" , &lt;br /&gt;
libero da cicli, che ricorderà molto da vicino un listato ruby :D&lt;br /&gt;
&lt;br /&gt;
prendiamo il seguente codice:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;public static void&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt; DoSomething(){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;    // inizializzazione e popolamento di una collezione&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         string[] pippo = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;new string&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;[]{&lt;span style="color: rgb(255, 0, 0);"&gt;"a"&lt;/span&gt;,&lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;,&lt;span style="color: rgb(255, 0, 0);"&gt;"c"&lt;/span&gt;};&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;// per ogni elemento (iterazione)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;for&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;int &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;i=0,max=pippo.Length;i&amp;lt;max;i++){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;           &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;  // selezione&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;if&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;pippo[i] != &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;// output&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 MessageBox.Show(pippo[i]);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br /&gt;
    &lt;br /&gt;
in poche righe abbiamo del codice che fa tante cose, ovvero&lt;br /&gt;
1) inizializzazione di una collezione&lt;br /&gt;
2) iterazione all interno della collezione&lt;br /&gt;
3) selezione di determinati elementi della collezione&lt;br /&gt;
4) output a video&lt;br /&gt;
&lt;br /&gt;
Partiamo con generalizzare la funzione anzichè usare un array di stringhe (in futuro potrei volere un altro contenitore di stringhe...)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;public static void &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;DoSomething()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;// inizializzazione e popolamento di una collezione&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         IEnumerable pippo = (IEnumerable)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;new string&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;[] {&lt;span style="color: rgb(255, 0, 0);"&gt; "a"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"c"&lt;/span&gt; };&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="color: rgb(51, 153, 102); font-family: Courier New;" /&gt;
&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;         // iterazione&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;for &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;(IEnumerator iter = pippo.GetEnumerator(); iter.MoveNext(); )&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt; // fetch&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;string &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;tmp = iter.Current as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;string&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="color: rgb(51, 153, 102); font-family: Courier New;" /&gt;
&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;             // selezione&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt;if &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;(tmp != "b")&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;/span&gt;&lt;span style="color: rgb(51, 153, 102); font-family: Courier New;"&gt;// output&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 MessageBox.Show(tmp);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ok fino a qui nulla di strano, il codice è piu generico e abbiamo introdotto uno step aggiuntivo che è il fetch del dato corretto dalla collezione.&lt;br /&gt;
Vorrei partire da questo codice per migliorarlo, eliminando il for...&lt;br /&gt;
&lt;br /&gt;
Mi viene in mente che tra le novità introdotte nel javascript 1.8 c'è una funzione aggiunta agli Array che si chiama reduce e che prende in input una funzione che torna vero o falso,&lt;br /&gt;
a cui reduce passera ogni elemento dell array e ritorna una Array scremato in base al risultato, &lt;br /&gt;
mi piacerebbe ottenere un qualcosa di simile..&lt;br /&gt;
&lt;br /&gt;
il codice che vorrei ottenere è un qualcosa di simile a:&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; IEnumerable collection = pippo.Reduce(mioDelegatoDiSelezione);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...già che ci siamo ci vorrebbe un metodo Each che per ogni elemento facesse qualcosa..&lt;br /&gt;
&lt;br /&gt;
Il codice che vorrei ottenere e' dunque somigliante a :&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold; font-family: Courier New;"&gt; pippo.Reduce(&lt;span style="color: rgb(255, 102, 0);"&gt;mioDelegatoDiSelezione&lt;/span&gt;).Each(&lt;span style="color: rgb(255, 102, 0);"&gt;mioDelegatoDiOutput&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Qui un classico programmatore OO penserebbe a come poter estendere pippo senza violare l' information hiding...&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://veroprogrammatore.blogspot.com"&gt;"Il Vero Programmatore"&lt;/a&gt; C# invece è al corrente delle innovazioni apportate al compilatore 3.0, &lt;br /&gt;
in particolare delle "extension method", che permettono di estendere una classe base ... senza realmente estenderla, &lt;br /&gt;
infatti gli extension method non sono null' altro che del "syntactic sugar" introdotto nel compilatore che permette di scrivere anzichè:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt; MetodoStatico (istanzaOggettoBase, parametri...);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br /&gt;
direttamente&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; istanzaOggettoBase.MetodoStatico(parametri...);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
dando dunque l impressione di aver esteso una classe :D&lt;br /&gt;
&lt;br /&gt;
quindi creeremo in un diverso namespace una classe statica e pubblica (che chiameremo ad esempio ExtensionMethods):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255); font-family: Courier New;"&gt; public static class &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;ExtensionMethods{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public static&lt;/span&gt; IEnumerable Reduce(&lt;span style="color: rgb(0, 0, 255);"&gt;this &lt;/span&gt;IEnumerable me, Func&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;,&lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt; rule){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(51, 153, 102);"&gt;// creo una lista che conterra' l IEnumerable risultante&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new &lt;/span&gt;List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt;();&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(51, 153, 102);"&gt;// itero sulla collezione (non sto eliminando il for, ma a mio avviso non occorre :D )&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt;(IEnumerator iter = me.GetEnumerator();iter.MoveNext(); ){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;span style="color: rgb(51, 153, 102);"&gt;// salvo l oggetto in una variabile temporanea per caching e comodita' ;D&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;tmp = iter.Current;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            &lt;span style="color: rgb(51, 153, 102);"&gt; // controllo se l oggetto passa la regola&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;(rule(tmp)){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                &lt;span style="color: rgb(51, 153, 102);"&gt; // aggiungo nella collezione finale l oggetto&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 result.Add(tmp);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(51, 153, 102);"&gt;// ritorno la lista scremata&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;result;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
adesso abbiamo esteso IEnumerable aggiungendo un metodo Reduce che vuole in ingresso un oggetto di tipo&lt;br /&gt;
Func&amp;lt;object,bool&amp;gt;, ovvero un delegato di un metodo che vuole in ingresso un oggetto e restituisce un valore booleano&lt;br /&gt;
&lt;br /&gt;
In questo momento utilizzando le lambda expression possiamo scrivere:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public static void &lt;/span&gt;DoSomething()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         IEnumerable pippo = (IEnumerable)&lt;span style="color: rgb(0, 0, 255);"&gt;new string&lt;/span&gt;[] { &lt;span style="color: rgb(255, 0, 0);"&gt;"a"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"c"&lt;/span&gt; };&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(51, 153, 102);"&gt;//per ogni elemento della lista scremata&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;foreach &lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;string &lt;/span&gt;tmp &lt;span style="color: rgb(0, 0, 255);"&gt;in &lt;/span&gt;pippo.Reduce(&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             meBoxed =&amp;gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;var &lt;/span&gt;me = meBoxed &lt;span style="color: rgb(0, 0, 255);"&gt;as &lt;/span&gt;string;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;me != "b";&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             })&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         ){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             &lt;span style="color: rgb(51, 153, 102);"&gt;//mostralo a video&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             MessageBox.Show(tmp);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br /&gt;
Ora pero' aggiungiamo anche un extension Method Each&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt; public static void&lt;/span&gt; Each(&lt;span style="color: rgb(0, 0, 255);"&gt;this &lt;/span&gt;IEnumerable me, Action&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt; action){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(51, 153, 102);"&gt;//ciclo sulla lista&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt;(IEnumerator iter = me.GetEnumerator();iter.MoveNext(); ){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(51, 153, 102);"&gt;//applico l azione all elemento della lista&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         action(iter.Current);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
..da notare che ora volendo potremo riscrivere Reduce come:&lt;br /&gt;
&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt; public static &lt;/span&gt;IEnumerable Reduce(&lt;span style="color: rgb(0, 0, 255);"&gt;this &lt;/span&gt;IEnumerable me, Func&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;,&lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt; rule){    &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new &lt;/span&gt;List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt;();&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     me.Each(item=&amp;gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;(rule(item)){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;             result.Add(item);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     });    &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;result;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
..si commenta da sola!&lt;br /&gt;
&lt;br /&gt;
bene ora il codice di DoSomething diventerà :&lt;br /&gt;
&lt;br /&gt;
&lt;br style="font-family: Courier New; color: rgb(0, 0, 255);" /&gt;
&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt; public static void&lt;/span&gt; DoSomething(){&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     IEnumerable pippo = (IEnumerable)&lt;span style="color: rgb(0, 0, 255);"&gt;new string&lt;/span&gt;[]{&lt;span style="color: rgb(255, 0, 0);"&gt;"a"&lt;/span&gt;,&lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;,&lt;span style="color: rgb(255, 0, 0);"&gt;"c"&lt;/span&gt;};    &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     pippo.Reduce(meBoxed =&amp;gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; me = meBoxed &lt;span style="color: rgb(0, 0, 255);"&gt;as &lt;/span&gt;string;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;(me != &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }).Each(item =&amp;gt;{MessageBox.Show(item);});&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
E ancora meglio:&lt;br /&gt;
&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;    private &lt;/span&gt;Func&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;,&lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt; excludeStringB = meBoxed =&amp;gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;var &lt;/span&gt;me = meBoxed &lt;span style="color: rgb(0, 0, 255);"&gt;as &lt;/span&gt;string;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;me != &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    };&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;/span&gt; &lt;span style="font-family: Courier New;"&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;    private &lt;/span&gt;Action&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt; showMessageBox = item =&amp;gt;{MessageBox.Show(item);};&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public static void&lt;/span&gt; DoSomething()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         IEnumerable pippo = (IEnumerable)&lt;span style="color: rgb(0, 0, 255);"&gt;new string&lt;/span&gt;[] { &lt;span style="color: rgb(255, 0, 0);"&gt;"a"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"b"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"c"&lt;/span&gt; };&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;         pippo.Reduce(excludeStringB).Each(showMessageBox);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;     }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br /&gt;
volendo si possono spostare le 2 lambda in 2 classi diverse (ad esempio Filter e Action), ma per questo esempio credo possano bastare cosi :D&lt;br /&gt;
&lt;br /&gt;
svantaggi di questa tecnica?&lt;br /&gt;
Stiamo ciclando 2 volte sulla stessa collection, quindi c'e' sicuramente uno svantaggio in termini di prestazioni&lt;br /&gt;
gli oggetti tra di loro hanno ancora un legame forte, vedremo nel prossimo post riguardante la&lt;span style="color: rgb(255, 153, 0);"&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;IOC&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153);"&gt; &lt;/span&gt;come poter separare&lt;br /&gt;
la logica di creazione definendo le dipendenze esternamente (utilizzando &lt;span style="color: rgb(255, 0, 0);"&gt;NInject&lt;/span&gt; ;) )&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/93170.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/93170.aspx</wfw:comment>
        <slash:comments>10</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/93170.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/93170.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Inferring, extension method and spaghetti 2.0</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2008/03/06/inferring-extension-method-and-spaghetti-2.0.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2008/03/06/inferring-extension-method-and-spaghetti-2.0.aspx</id>
        <published>2008-03-06T09:12:09Z</published>
        <updated>2008-03-06T09:12:09Z</updated>
        <summary type="html">A volte una discussione tra due veri programmatori può essere una discussione veramente terra a terra anche quando si parla di argomenti complessi, per esempio ieri ero in chat con un amico che per mantenere anonimo chiamerò ( ...continua)</summary>
        <content type="html">A volte una discussione tra due &lt;a href="http://veroprogrammatore.blogspot.com/"&gt;veri programmatori&lt;/a&gt; può essere una discussione veramente terra a terra anche quando si parla di argomenti complessi, per esempio ieri ero in chat con un amico che per mantenere anonimo chiamerò Giammarchi A.&lt;br /&gt;
(anzi no, così mi sa che si capisce) dicevo, per farlo restare anonimo lo chiamerò Andrea G, è iniziato un discorso di cui vi posto un piccolo estratto (leggermente modificato) :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[... si parlava del linguaggio cobra ...]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;me:&lt;/span&gt; ...anche in c# 3.0 hanno aggiunto l'inferenza :p&lt;br /&gt;
e  si ottiene usando &lt;span style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 255);"&gt;var &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; pippo = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; String(&lt;span style="background-color: rgb(255, 255, 255); color: rgb(255, 0, 0);"&gt;"andr3a"&lt;/span&gt;);&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Andrea:&lt;/span&gt; lo so, me l'hanno rubata&lt;br /&gt;
questo in ESharp posso già farlo ma su C# 1,2 e non sul 3...&lt;br /&gt;
class var {} è l'abstract di Object, &lt;br /&gt;
che è la base di Array, String, Number, Function, etc&lt;br /&gt;
in ESharp ho già tutto&lt;br /&gt;
[..segue discussione semiseria su come sostituire la sua classe var con un altra che non diventi una parola chiave in futuro :D..]&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;me:&lt;/span&gt; inferred praticamente puoi creare una variabile senza esplicitarne il tipo&lt;br /&gt;
e il compilatore lo assegna alla prima volta in cui gli dai un valore&lt;br /&gt;
... tipo&lt;br /&gt;
  &lt;span style="color: rgb(0, 0, 255);"&gt;var &lt;/span&gt;a=&lt;span style="color: rgb(255, 0, 0);"&gt; "Fregna"; &lt;/span&gt;il compilatore dice &lt;span style="color: rgb(255, 0, 0);"&gt;"Fregna"&lt;/span&gt; è &lt;span style="color: rgb(0, 0, 255);"&gt;string &lt;/span&gt;dunque traduce in &lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;string &lt;/span&gt;a = &lt;span style="color: rgb(255, 0, 0);"&gt;"Fregna";&lt;/span&gt;&lt;br /&gt;
  questo in fase di compilazione&lt;br /&gt;
[..segue discussione su come questo sia banale, ovvio scontato e già presente in n linguaggi con n tendente all infinito.. :geek:]&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;me:&lt;/span&gt; si, ma sai che vantaggio&lt;br /&gt;
  ieri avevo un metodo che tornava stringhe&lt;br /&gt;
  e elaborava l'array con un &lt;span style="color: rgb(0, 0, 255);"&gt;foreach &lt;/span&gt;su &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[], &lt;br /&gt;
  per esigenze mi son accorto che non andava bene,&lt;br /&gt;
  ho cambiato il metodo ora torna un &lt;span style="color: rgb(0, 0, 255);"&gt;ArrayList&lt;/span&gt;&lt;br /&gt;
  e non ho modificato altro codice :d&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Andrea: &lt;/span&gt;si ma se poi alla variabile fai usare metodi di altra classe ...&lt;br /&gt;
  non va piu nulla&lt;br /&gt;
  var a = "Fregna";&lt;br /&gt;
  a.pow(2);&lt;br /&gt;
  :LOL:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;me:&lt;/span&gt; ma è ovvio!  a quel punto devi usare un interfaccia&lt;br /&gt;
  ...ah beh! Però &lt;span style="color: rgb(51, 153, 102);"&gt;C#&lt;/span&gt; ti viene in contro se proprio non vuoi modificare il codice...&lt;br /&gt;
  si perchè hanno pure introdotto gli &lt;span style="font-weight: bold;"&gt;extension method&lt;/span&gt;&lt;br /&gt;
  ora puoi fare&lt;span style="text-decoration: underline;"&gt; in una classe publica e statica&lt;/span&gt; una cosa del genere volendo :&lt;br /&gt;
&lt;br /&gt;
  &lt;span style="color: rgb(0, 0, 255);"&gt;public static string&lt;/span&gt; pow(&lt;span style="color: rgb(0, 0, 255);"&gt;this string&lt;/span&gt; s,&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i){&lt;br /&gt;
      &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;(i&amp;gt;0){&lt;br /&gt;
        var sb = new &lt;span style="color: rgb(0, 0, 255);"&gt;System.Text.StringBuilder&lt;/span&gt;();&lt;br /&gt;
       &lt;span style="color: rgb(0, 0, 255);"&gt; for&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;a=0;a&amp;lt;i;a++)&lt;br /&gt;
            sb.Append(s);&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; sb.toString();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; "";&lt;br /&gt;
  }&lt;br /&gt;
In poche parole ho appena effettuato uno spaghetti code 2.0 :D :lol:&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Andrea: &lt;/span&gt;si&lt;br /&gt;
  mi piace C# perchè ti crei il tuo linguaggio per i fatti tuoi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;div&gt;
&lt;div style="text-align: left;"&gt;
&lt;div style="text-align: left;"&gt;&lt;span style="display: block; padding-left: 6em;"&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display: block; padding-left: 6em; text-indent: -1em;"&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style="display: block; padding-left: 6em;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style="display: block; padding-left: 6em;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display: block; padding-left: 6em; text-indent: -1em;"&gt;&lt;span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/91554.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/91554.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/91554.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/91554.aspx</trackback:ping>
    </entry>
    <entry>
        <title>I am so high, I can hear heaven.</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2008/02/29/i-am-so-high-i-can-hear-heaven.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2008/02/29/i-am-so-high-i-can-hear-heaven.aspx</id>
        <published>2008-02-29T08:40:19Z</published>
        <updated>2008-02-29T08:54:41Z</updated>
        <summary type="html">Son tornato a casa da Milano, dall'evento Heroes di presentazione ufficiale di VS , SQL Server e Windows 2008.
L'evento si svolgeva in due giornate ma ho potuto assistere solo a quella di oggi..
per fortuna non abbiam trovato coda a Mestre... ci è andata bene sia in andata che in ritorno,
anche perchè stamattina la nebbia ha fatto lo scherzetto di fingere di esserci ;D

(continua ...)</summary>
        <content type="html">Son tornato a casa da Milano, dall'evento Heroes di presentazione ufficiale di VS , SQL Server e Windows 2008.&lt;br /&gt;
L'evento si svolgeva in due giornate ma ho potuto assistere solo a quella di oggi..&lt;br /&gt;
per fortuna non abbiam trovato coda a Mestre... ci è andata bene sia in andata che in ritorno,&lt;br /&gt;
anche perchè stamattina la nebbia ha fatto lo scherzetto di fingere di esserci ;D&lt;br /&gt;
&lt;br /&gt;
Oddio dire di esserci stato oggi è un po troppo, visto che ieri non ho potuto dormire (in totale ho dormito la bellezza di 4 ore) ed essere riuscito ad addormentarmi durante un paio di talk (..) comunque è stato sicuramente interessante, ho avuto modo di ripassare cose già viste (che non fa mai male) e di scoprire un paio di spunti interessanti... ed ora veniamo alle pagelle, ho seguito il filone MSDN  e su questo dirò la mia modestissima opinione:&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Un nuovo approccio allo sviluppo e all'accesso ai dati&lt;/span&gt;&lt;br /&gt;
Speakers: Paolo Pialorsi e Marco Russo.&lt;br /&gt;
&lt;br /&gt;
Il miglior Talk della giornata, nonchè il motivo principale della mia presenza a Milano (ok, pure la NFR di VS2008 era tra i motivi principali ;D) un talk eccellente che avrei veramente approffondito per un altro paio di orette :d&lt;br /&gt;
comunque molto bravi i relatori voto 9 a tutti e 2&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Realizzare applicazioni web innovative&lt;br /&gt;
&lt;/span&gt;Speaker: Pietro Brambati&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
Anche questo talk è stato molto interessante, se non fosse per qualche orrore che ho visto nell utilizzo di javascript non nella maniera corretta... ma son piccolezze che solo uno come me che ha studiato tutte le best e worst practice di javascript può comprendere (in particolar modo mi riferisco a un href="javascript: che mi ha fatto rizzare i capelli e a un altra sciocchezza che però non ricordo...)&lt;br /&gt;
tra l' altro in questo talk c'è stato il momento più bello della giornata, quando per qualche millesimo di secondo lo schermo è diventato nero, e l'espressione del relatore faceva intravedere il suo pensiero in quel momento :D&lt;br /&gt;
voto 8&lt;br /&gt;
&lt;br /&gt;
Coffee Break voto 7 :D&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Sviluppo di applicazioni per Microsoft Office System&lt;/span&gt;&lt;br /&gt;
Speaker:Giuseppe Guerrasio&lt;br /&gt;
Questo talk non era di mio interesse, e mi sono appisolato un po, quindi non posso esprimere un giudizio in tal proposito&lt;br /&gt;
&lt;br /&gt;
Lunch Break voto 6 :p&lt;br style="font-weight: bold;" /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;La nuova frontiera delle applicazioni per l'accesso, la gestione e l'analisi dei dati&lt;/span&gt;&lt;br /&gt;
Speaker. Silvano Coriani&lt;br /&gt;
&lt;br /&gt;
Un talk molto interessante riguardante SQL server, che spiegava le maggiori innovazioni apportate, ho seguito questo talk quasi fino alla fine, mi son perso gli ultimi minuti&lt;br /&gt;
voto: 7&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;La nuova interfaccia utente nelle applicazioni smart client&lt;/span&gt;&lt;br /&gt;
Speaker: Luca Regnicoli&lt;br /&gt;
&lt;br /&gt;
Sinceramente non ho ben capito cosa c'entrassero gli smart client con questo talk, anche perchè son stato uno tra le 10 persone ad alzare la mano quando si è chiesto chi lavorava con gli smart client ..ma era senza dubbio interessante :D&lt;br /&gt;
siamo dovuti andar via un po prima della fine per evitare la coda in autostrada, comunque per quel che ho visto posso dare un 7.5 a questo talk.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://img132.imageshack.us/img132/687/heroym5.jpg" /&gt;&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/91442.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/91442.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/91442.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/91442.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Ed eccoci!</title>
        <link rel="alternate" type="text/html" href="http://blogs.ugidotnet.org/MVPWannabe/archive/2008/02/12/91154.aspx" />
        <id>http://blogs.ugidotnet.org/MVPWannabe/archive/2008/02/12/91154.aspx</id>
        <published>2008-02-12T06:14:26Z</published>
        <updated>2008-02-12T06:14:26Z</updated>
        <content type="html">Il mio blog stava diventando troppo un acrocchio di tecnologie, onde per cui ho optato per una suddivisione logica che mi permettesse di metter un po di ordine in quello che scrivo...&lt;br /&gt;
Ho ben pensato di creare un l' ennesimo blog su .NET qui su Ugi, la notizia forte è che questo blog sarà rigorosamente in italiano !!!&lt;br /&gt;
&lt;br /&gt;
Di cosa parlerò qui? non ne ho idea, forse un po del mio progetto &lt;a href="http://www.codeplex.com/uIoC"&gt;www.codeplex.com/uIoC&lt;/a&gt;&lt;br /&gt;
oppure di come funzioni Castle, visto che a lavoro l'ho usato un bel po, probabilmente posterò qualche esperimento con Linq e .net 3.5... insomma non ho idea di cosa ma qualcosa mi inventerò :D&lt;br /&gt;
&lt;br /&gt;
per chi non mi conoscesse(ovvero il 99.9% delle persone che leggeranno questo post) , beh il mio nome è Cristian, piacere!&lt;br /&gt;
&lt;br /&gt;
vi allego un po di link a ciò che ho fatto in passato:&lt;br /&gt;
&lt;br /&gt;
piccolo container IoC che funziona con il compact framework 2.0: &lt;a href="http://www.codeplex.com/uIoC"&gt;www.codeplex.com/uIoC&lt;/a&gt;&lt;br /&gt;
piccolo container IoC per JS : &lt;a href="http://code.google.com/p/jsioc/downloads/list "&gt;code.google.com/p/jsioc/downloads/list&lt;/a&gt;  con relativo esempio: &lt;a href="http://mykenta.blogspot.com/2008/01/simple-js-ioc-example-code.html"&gt;mykenta.blogspot.com/2008/01/simple-js-ioc-example-code.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
mini script per standardizzare un po il comportamento di set/getAttribute di IE:&lt;a href="http://mykenta.blogspot.com/2006/07/standardise-ie-setattribute-part-2.html"&gt;mykenta.blogspot.com/2006/07/standardise-ie-setattribute-part-2.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
links a varie pillole sul C scritte per HTML.it:&lt;br /&gt;
&lt;a href="http://mykenta.blogspot.com/2005/06/go-go-blog.html"&gt;mykenta.blogspot.com/2005/06/go-go-blog.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
ah si! come tesina per gli esami delle superiori ho pure scritto un compilatore(..in pascal):&lt;br /&gt;
&lt;a href="http://freeforumzone.leonardo.it/cartella.aspx?c=19716&amp;amp;f=19716&amp;amp;idc=86986"&gt;freeforumzone.leonardo.it/cartella.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
:lol:&lt;img src="http://blogs.ugidotnet.org/MVPWannabe/aggbug/91154.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://blogs.ugidotnet.org/MVPWannabe/comments/91154.aspx</wfw:comment>
        <slash:comments>4</slash:comments>
        <wfw:commentRss>http://blogs.ugidotnet.org/MVPWannabe/comments/commentRss/91154.aspx</wfw:commentRss>
        <trackback:ping>http://blogs.ugidotnet.org/MVPWannabe/services/trackbacks/91154.aspx</trackback:ping>
    </entry>
</feed>