06/27/08

Generic Visitor Implementation thanks to C# 3.0

Hi,

I've finally achieve my dream : Having a generic visitor ! How did I do that, really simple : I used extension methods. I let you see the class you may understand better if I don't explain ;)

public static class VisitorHelper
{
    public static void Accept<T, V>(this T visitable,
      V visitor, VisitorContext context)
      where V : IVisitor<T>
    {
        visitor.Visit(visitable, context);
    }
}

My main worry was to know if it would pass a unit test with inheritance matter, and it does !!! The visitor context is an abstract class which has some information needed for the visitor. It has nothing really important to do here.

[EDIT] After reading my previous post, you may have guessed that you can use this visitor without specifying type and using compiler type inference.

myObject.Accept(visitor,new MyVisitorContext());

06/02/08

Article on Tech Head Brothers

An article I've written has been posted on Tech Head Brothers. For the ones of you who read french, you may read it here.

06/01/08

Generics in C#

Generics in C#

Have you already used generics in C# ? Yes ? Then you may already have struggled with the issues I'm going to talk about.

When you are in a generic method, you may want to cast your generic object into another type to do some specific treatment :

    class Program
    {
        static void Main(string[] args)
        {
            GenericMethod<Class1>(new Class1());
        }

static T GenericMethod<T>(T item) { Class1 c1 = ((Class1)item); return item; } }

However when you do this, you have the compiler that says you "cannot convert type 'T' to 'Class1'". The tip is to use the as keyword, and the compiler wont bore you anymore :

    class Program
    {
        static void Main(string[] args)
        {
            GenericMethod<Class1>(new Class1());
        }

static T GenericMethod<T>(T item) { Class1 c1 = item as Class1; return item; } }

One more thing really useful : when you want to use generic methods, you do not necessarly need to specify the generic type. If the method expect this generic type as parameter, the compiler can infer it :

	class Program
	{
		static void Main(string[] args)
		{
			GenericMethod(new Class1());
		}

static T GenericMethod<T>(T item) { Class1 c1 = item as Class1; return item; } }

Hope it was useful. Have fun, and keep your little fingers brawny.

04/30/08

Php for Visual Studio (Php4VS)

Morning everyone,

Some days ago, I've published a project on codeplex : php4vs. Currently, it provides basic functions, but I intend to implement intellisense. Though, we could have a great php IDE, but it would also have made me understand a bit more how to implement Language Service in VS, and how to work with MPF (Managed Package Framework). Once intellisense works, I will publish a post to let you know, how I made it work.

04/24/08

Lucene Persistence Engine Sample

Due to my preceding post, I had to publish a sample on how to use this Lucene Persistence Engine. And since a picture is worth a thousand words, I let try it. The sample is a small application that looks for content in an articles library.

You may find the sample here.

04/20/08

Lucene Persistence Engine for Euss

I have been working with EUSS for some time now. For the one who don't know it yet, I would suggest you to have a look at it. During my free time, I've developed a Persistence Engine based on Lucene. If you know EUSS or have taken some time to read the overview, you know that to request objects to EUSS, you use the OPath language, or with the .NET framework 3.5, you can use Linq. My persistence engine enables you use these languages with Lucene. Imagine the power of Linq combined with the Lucene ! I know, a LinqToLucene already exists, but my persistence engine goes further, since it enables to use aggregate functions (not in constraints). For instance, you may get the number of objects satisfying a condition with one single query. For those who have been reading so far, I guess you're impatient to test it, then here is the dlls to use, and there an example of an app.config/web.config :

<configuration>
    <configSections>
        <section name="euss" type="Evaluant.Uss.Configuration.EussConfiguration, Evaluant.Uss"/>
    </configSections>
    <connectionStrings>
        <add name="MsSQL" connectionString="Data Source=.;Initial Catalog=EUSS;Integrated Security=true"/>
    </connectionStrings>
    <system.diagnostics>
        <switches>
            <add name="Evaluant.Uss.SqlMapper.Sql" value="1"/>
            <add name="Evaluant.Uss.Lucene" value="1"/>
        </switches>
    </system.diagnostics>
    <euss>
        <engines defaultEngine="myIndexer">
            <engine name="myIndexer" factory="Evaluant.Uss.Lucene.IndexerProvider, Evaluant.Uss.Lucene">
                <add name="delegator" value="Lucene,SqlMapper" />
                <add name="DefaultEngineIndex" value="1" />
                <add name="IndexerDefaultIndex" value="0"/>
            </engine>
            <engine name="SqlMapper" factory="Evaluant.Uss.SqlMapper.SqlMapperProvider" connectionStringName="MsSQL">
                <add name="Dialect" value="Evaluant.Uss.SqlMapper.MsSqlDialect" />
                <add name="Driver" value="Evaluant.Uss.SqlMapper.MsSqlDriver" />
                <add name="MappingFileName" value="~/mapping.xml" />
                <metadata>
                    <add type="assembly" value="LucenePersistenceEngineSample.Domain" />
                </metadata>
            </engine>
            <engine name="Lucene" factory="Evaluant.Uss.Lucene.LuceneProvider, Evaluant.Uss.Lucene">
                <add name="Path" value="Index" />
                <add name="StoreAttributes" value="True" />
                <metadata>
                    <add type="assembly" value="LucenePersistenceEngineSample.Domain" />
                </metadata>
            </engine>
        </engines>
    </euss>
</configuration>

03/31/08

Hello World

Firstly, I would like thank Sami Jaber and Sébastien Ros for giving me the opportunity to have a blog on dotnetguru

Secondly, I would like to share with you my first project published on CodePlex.
XNA Components.

Nicolas Penin

<  June 2008  >
Mon Tue Wed Thu Fri Sat Sun
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

Recent Referers


Top Referers

Misc

powered by
b2evolution