User User registration types are Super and Common
public eumn RegistrationType
{
Super;
Common;
}
public User
{
RegistrtionType type;
......
}
Consider this situation. Through a certain service, the client will obtain the class name and the values of each attribute from the server, including User, and other classes Product, Shop, etc. Of course, these are all strings. On the client, we need to assemble this information into a class instance. We can judge the passed class name through if, and come up with a new instance, judge each attribute and assign a value. But if we are not sure which categories will be transmitted, we cannot use if to judge. At this time, we can use reflection to complete it. As long as the class name is obtained, an instance of a class can be reflected and then the attribute can be assigned.
For example, the server side passes "User Super", that is, this is a User class, and its RegistrtionType is Super. How to convert this Super string into an enum? You can use the following method, which says that an instance user is reflected first, then its attributes are obtained, and then the value is assigned.
(user, ().ConvertFromInvariantString("Super"), null);