0

I am not sure yet what is the best way to do this, I found that you can assign attributes to a class but there is no way to assign an attribute to a variable of the class.

Example

[attribute author....]
public class ABC
    int variable1;

what I am looking for is to assign an attribute to variable1.

so something like this

[attribute author....]
public class ABC
    [attribute or something to tie to variable1]
    int variable1;

So when I use reflection to access the class, I can get additional information from each variable. The reason for this is that I am creating an editor and I want to group variables in the editor but I don't want to hard code the variable names or keep a list of variables that should be grouped.

Any idea how to make something like that?

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136

1 Answers1

0

class_name.GetType().GetFields() returns the class variables aka fields. Use a Dictionary to store attributes for these fields.

draz
  • 793
  • 6
  • 10
  • I am already doing that, but I want to group my fields for presentation , for example there are fields from one class [DataMember] public bool drawTop { get; set; } = true; [DataMember] public bool drawBottom { get; set; } = true; [DataMember] public bool drawLeft { get; set; } = true; [DataMember] public bool drawRight { get; set; } = true; when i get them from reflection i do not know if i can group them in the editor or display them in different lines – Mystic River Mar 27 '20 at 18:04