Some common tricks about properties

   If you want to define some static variables that are common to the entire project, these values ​​are defined from the config file. When converting into static variables, it is best to write them as properties, because the configured values ​​can be judged and typed in the properties. Conversion, This can avoid judgment and conversion every time a static variable is called.

Although I am familiar with the function of attributes, I still didn't think of it when I actually used it. Mark it here! ! !

 

public static DetectType Config_FaceDetection
        {
            get
            {
                DetectType detectType =(DetectType)int.Parse(ConfigurationManager.AppSettings["FaceDetection"].ToString());//ID photo identification;
                if (!Enum.IsDefined(typeof(DetectType), detectType ))
                {
                  throw new Exception("In the confing file, the photo recognition configuration is abnormal!");
                }
                return detectType;
            }
        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325948284&siteId=291194637