Re: Do we have extention properties in C# 3.0?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 24 Jul 2008 17:10:38 -0700, not_a_commie <notacommie@xxxxxxxxx> wrote:

My biggest complaint with the extension methods is that they don't
support the 'where' clause. You have to specify the exact type. I'd
rather see support for that before adding support for properties.

Do you mean something like this:

using System;

namespace TestGenericExtensionMethod
{
static class Extensions
{
public static void TestMethod<T>(this T t) where T : TestBase
{
Console.WriteLine("{0}.TestMethod", t.GetType().Name);
}
}

class TestBase
{
}

class TestDerived : TestBase
{
}

class Program
{
static void Main(string[] args)
{
TestDerived td = new TestDerived();
Object obj = new Object();

td.TestMethod(); // works fine
// obj.TestMethod(); // CS0311 error
Console.ReadLine();
}
}
}

Your wish is granted! :)

I'd
also like to see the 'where' clause enhanced to support 'primitive',
meaning types that support these operators: +,-,/,*,%, etc. or maybe
some way to specify operators in the 'where' clause.

I think lots of people would like to see useful ways to use generics with operators like that, whether via a constraint or some other mechanism. Marc Gravell has posted a useful workaround to the current situation. You should be able to use Google Groups to look back at the archives and find his articles on the topic.

Maybe that will also appear in a future C#. It's not a trivial problem to solve (extension properties would be much easier :) ).

Pete
.



Relevant Pages

  • MySQL support for NULL in WHERE clause
    ... I am reading perldoc DBI, ... That section has a table listing which database brands support which clause styles. ... As to support for style 5, please note that i did not create a stored procedure, ...
    (perl.dbi.users)
  • Re: user permissions
    ... I would like to add some comments regarding 'EXECUTE AS' clause in SQL ... Server 2005 as a complement of Rick's response. ... Microsoft Online Community Support ...
    (microsoft.public.sqlserver.security)
  • RE: Not in query
    ... I think you may set the where clause in the second query to be the contrary ... In the first query, we return all the items that the PersonID less than ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Do we have extention properties in C# 3.0?
    ... support the 'where' clause. ... You have to specify the exact type. ... rather see support for that before adding support for properties. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: where JOB_ID IN (:JOB_ID)
    ... wish there was a support for touple) ... Brian Peasland wrote: ... to return one value in the IN clause. ...
    (comp.databases.oracle.server)