Click here to Skip to main content
15,914,222 members
Home / Discussions / C#
   

C#

 
AnswerRe: received data by UDP client Pin
F-ES Sitecore9-May-15 2:25
professionalF-ES Sitecore9-May-15 2:25 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 3:38
hasan hadi9-May-15 3:38 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:05
professionalF-ES Sitecore9-May-15 7:05 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 7:42
hasan hadi9-May-15 7:42 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:48
professionalF-ES Sitecore9-May-15 7:48 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 8:07
hasan hadi9-May-15 8:07 
AnswerRe: received data by UDP client Pin
Dr Gadgit10-May-15 5:03
Dr Gadgit10-May-15 5:03 
Question(solved) shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 20:41
professionalBillWoodruff7-May-15 20:41 
1. there's lots of precedents in .NET itself for having classes that are non-generic (can be instantiated), and that have static "utility" methods.

2. when you write a generic class like this (deliberately abbreviated) example:
C#
public class Node<T> : IEquatable<Node<T>> where T : IEquatable<T>
{
    public List<Node<T>> Nodes { set; get; }
    public int Level { set; get; }
    public int ID { set; get; }   
    public T Value { set; get; }
    // and so on ...

    // you can add static properties, methods, etc. in the body of 'Node:
    public static Func<Node<T>, Node<T>, bool> GatherFunc;
    
    public static Dictionary<int, List<int>> Gather(Node<T> node, GatherMode gathermode, Func<Node<T>, Node<T>, bool> customfunc = null)
    {
      // code to create a Dictionary<int, List<int>> of Nodes where each KeyValuePair
      // in the Dictionary contains a Key which is the 'ID of a Node, and a List of Node ID's
      // of the Nodes that match one of the properties of the Key Node based on the Property
      // indicated by the value of the Enum 'GatherMode (GatherMode Enum not shown here)
      
    }
}
3. The issue is that when you want to invoke those static function in the generic class:

a. you can't use Extension methods with generic classes

b. you have to use a rather elaborate syntax to invoke those methods, like:
C#
var result1 = Node<TestClass>.Gather(XNode, Node<TestClass>.GatherMode.Values);

var result2 = Node<TestClass>.Gather(XNode, Node<TestClass>.GatherMode.Names);
c. yes, you can using a 'Using directive statement, for example:
C#
using node = May_1_2015_MultiList.Node<May_1_2015_MultiList.TestClass>;
and, as you can see, that requires you fully qualify the references, even though all the classes, including Node, are in the same NameSpace.

Is there any other way to invoke the static methods using a simpler syntax ?
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"


modified 8-May-15 9:32am.

AnswerRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 22:31
professionalSascha Lefèvre7-May-15 22:31 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 22:46
professionalBillWoodruff7-May-15 22:46 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 23:53
professionalSascha Lefèvre7-May-15 23:53 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff8-May-15 0:40
professionalBillWoodruff8-May-15 0:40 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre8-May-15 5:27
professionalSascha Lefèvre8-May-15 5:27 
SuggestionRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Richard Deeming8-May-15 0:42
mveRichard Deeming8-May-15 0:42 
Questionhow do I get datasource to put to any drive c# Pin
Member 97020587-May-15 14:19
Member 97020587-May-15 14:19 
AnswerRe: how do I get datasource to put to any drive c# Pin
Dave Kreskowiak7-May-15 16:50
mveDave Kreskowiak7-May-15 16:50 
AnswerRe: how do I get datasource to put to any drive c# Pin
OriginalGriff7-May-15 20:35
mveOriginalGriff7-May-15 20:35 
AnswerRe: how do I get datasource to put to any drive c# Pin
Richard Deeming8-May-15 0:35
mveRichard Deeming8-May-15 0:35 
QuestionHow to run a setup file in different sysytem.. Pin
Jayamanickam7-May-15 2:32
Jayamanickam7-May-15 2:32 
AnswerRe: How to run a setup file in different sysytem.. Pin
OriginalGriff7-May-15 3:10
mveOriginalGriff7-May-15 3:10 
GeneralRe: How to run a setup file in different sysytem.. Pin
Brisingr Aerowing7-May-15 4:21
professionalBrisingr Aerowing7-May-15 4:21 
GeneralRe: How to run a setup file in different sysytem.. Pin
ZurdoDev7-May-15 6:00
professionalZurdoDev7-May-15 6:00 
QuestionRe: How to run a setup file in different sysytem.. Pin
ZurdoDev7-May-15 4:06
professionalZurdoDev7-May-15 4:06 
QuestionC# web browser Pin
Jonteepersson967-May-15 1:56
Jonteepersson967-May-15 1:56 
GeneralRe: C# web browser Pin
Sascha Lefèvre7-May-15 2:04
professionalSascha Lefèvre7-May-15 2:04 

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.