samedi 7 mars 2020

How to check if a struct has only nested ints and structs inside?

How to check at runtime if a function argument that is a struct has only nested ints and similar structs inside in .NET?

So what I want is simple - throw an exception if a struct passed to a function does not look like this (contains ints or nested structs containing ints):

struct Z {
 N A;
 M B;
 int C;
}

struct N {
 int A;
 M B;
 M C;
}

struct M { 
 int A;
 int B;
}

 public void Act<T>(T str) where T: struct {
    // check if T is composed of nested ints or structs of nested ints
 }




Aucun commentaire:

Enregistrer un commentaire