Click here to Skip to main content
15,881,709 members
Home / Discussions / C#
   

C#

 
QuestionHow to export extjs chart into pdf? Pin
Janu Kya Kar Rahi ho31-Jan-14 18:53
Janu Kya Kar Rahi ho31-Jan-14 18:53 
QuestionRe: How to export extjs chart into pdf? Pin
Richard MacCutchan31-Jan-14 22:16
mveRichard MacCutchan31-Jan-14 22:16 
QuestionHow do I keep a player from override another player's move by reclicking a button Pin
Member 1045350931-Jan-14 9:29
Member 1045350931-Jan-14 9:29 
AnswerRe: How do I keep a player from override another player's move by reclicking a button Pin
Dave Kreskowiak31-Jan-14 13:45
mveDave Kreskowiak31-Jan-14 13:45 
AnswerRe: How do I keep a player from override another player's move by reclicking a button Pin
agent_kruger31-Jan-14 23:13
professionalagent_kruger31-Jan-14 23:13 
JokeRe: How do I keep a player from override another player's move by reclicking a button Pin
Eddy Vluggen1-Feb-14 8:17
professionalEddy Vluggen1-Feb-14 8:17 
GeneralRe: How do I keep a player from override another player's move by reclicking a button Pin
agent_kruger1-Feb-14 18:45
professionalagent_kruger1-Feb-14 18:45 
Questionc# extension methods syntax question Pin
Jon Joeney30-Jan-14 23:23
Jon Joeney30-Jan-14 23:23 
Hi, I have a syntax question on extension method syntax.

Here is my most simple extension method code

C#
using System;
using ConsoleApplication1;

namespace extensionTestNamespace.test.com
{
    public static class ExtensionTest
    {
        public static String AAAAAAA<T>(this T x) where T : TestClass1
        {
            return "Extension Method Test";
        }
    }
}


and here is the code that uses it

C#
using System;
using extensionTestNamespace.test.com;

namespace ConsoleApplication1
{
    public class TestClass1 { }
    public class TestClass2 { }
    public class TestClass3 { }


    class Program
    {
        private void run()
        {
            TestClass1 test1 = new TestClass1();
            TestClass2 test2 = new TestClass2();
            TestClass3 test3 = new TestClass3();

            //this works and I want it to work
            Console.WriteLine(test1.AAAAAAA());

            //this line won't compile, doesn't work, and
            //I want to add the same extension method 
            //to TestClass2 and don't know how
            Console.WriteLine(test2.AAAAAAA());     

            //this line won't compile either, but I
            //specifically don't want to add
            //the extension method to TestClass3
            Console.WriteLine(test3.AAAAAAA());     
        }


        static void Main(string[] args)
        {
            Program program = new Program();
            program.run();
        }
    }
}


My question is the syntax to allow the extension method AAAAAAA to test1 and test2 but not to test3. I had wanted to write this code

public static String AAAAAAA<T>(this T x) 
    where T : TestClass1
    where T : TestClass2


but it won't compile.

What I do not want to do is add a special extension method for each class type. What I do want is a single extension class but the where clause constraint has TestClass1 and TestClass2 but not TestClass3.

I don't know how to do it. Can it be done and if so I would appreciate help on the C# syntax.

Thank you
AnswerRe: c# extension methods syntax question Pin
harold aptroot31-Jan-14 0:05
harold aptroot31-Jan-14 0:05 
AnswerRe: c# extension methods syntax question Pin
OriginalGriff31-Jan-14 0:23
mveOriginalGriff31-Jan-14 0:23 
GeneralRe: c# extension methods syntax question Pin
BillWoodruff31-Jan-14 5:56
professionalBillWoodruff31-Jan-14 5:56 
GeneralRe: c# extension methods syntax question Pin
OriginalGriff31-Jan-14 6:06
mveOriginalGriff31-Jan-14 6:06 
AnswerRe: c# extension methods syntax question Pin
BillWoodruff31-Jan-14 0:57
professionalBillWoodruff31-Jan-14 0:57 
GeneralRe: c# extension methods syntax question Pin
Richard Deeming31-Jan-14 2:05
mveRichard Deeming31-Jan-14 2:05 
GeneralRe: c# extension methods syntax question Pin
BillWoodruff31-Jan-14 5:48
professionalBillWoodruff31-Jan-14 5:48 
AnswerRe: c# extension methods syntax question Pin
Ennis Ray Lynch, Jr.31-Jan-14 9:49
Ennis Ray Lynch, Jr.31-Jan-14 9:49 
QuestionConsole Application c# & use shape & color Pin
vajihe.mirzaei30-Jan-14 5:38
vajihe.mirzaei30-Jan-14 5:38 
AnswerRe: Console Application c# & use shape & color Pin
OriginalGriff30-Jan-14 5:57
mveOriginalGriff30-Jan-14 5:57 
AnswerRe: Console Application c# & use shape & color Pin
Dave Kreskowiak30-Jan-14 6:18
mveDave Kreskowiak30-Jan-14 6:18 
AnswerRe: Console Application c# & use shape & color Pin
Rahul VB30-Jan-14 17:45
professionalRahul VB30-Jan-14 17:45 
AnswerRe: Console Application c# & use shape & color Pin
Pete O'Hanlon30-Jan-14 18:55
mvePete O'Hanlon30-Jan-14 18:55 
GeneralC# Pin
karthick.RR30-Jan-14 2:26
karthick.RR30-Jan-14 2:26 
GeneralRe: C# Pin
Dave Kreskowiak30-Jan-14 3:30
mveDave Kreskowiak30-Jan-14 3:30 
GeneralRe: C# Pin
Rahul VB30-Jan-14 22:37
professionalRahul VB30-Jan-14 22:37 
GeneralRe: C# Pin
Wayne Gaylard30-Jan-14 22:58
professionalWayne Gaylard30-Jan-14 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.