简体   繁体   中英

Mark values as being entered by user or calculated by application

I'm currently planning a new application. The values used in this application can either be entered by the user or calculated by the application itself.

What I need to do is to mark the values in a way that I can clearly identify the source (user or app).

EDIT (additional information): The idea is not to identify that a user can input a value or not. The idea is to clearly have the possibility to flag values as being calculated or entered by the users. The value will not only be used in the view but also in calculations.

A class A would have a double v. This double can either be calculated or have been entered by a user.

class A
{
    public double v;  // <-- this would be the value I'd like to mark as program-defined or user defined
}

So, when I do this:

v = 1.0;

it would be marked as program-defined.

Has anyone a hint on how to achieve this in C#?

In C++ I would create a base class and derive from it. But in C# I would like to take a more general approach which doesn't force me to create a class per input type.

Any ideas on how to achieve this?

Thanks.

If you are looking for way to mark some properties or classes that they are used for user input or internally you can use attributes for this. https://docs.microsoft.com/en-us/dotnet/standard/attributes/writing-custom-attributes

Have a general class that implements a variable which identifies whether or not it is a value entered by the app or the user.

Possible variable types:

  • a string ('user', 'app' ...)
  • an enum , so if the enum is called Source it will be Source.User, if app Source.App.
  • an integer (as ID)

If you have a limited amount of types I'd personally go with an enum as it allows you to have suggested options. If you have many types I'd go with a string or an integer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM