且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将类转换为可配置项

更新时间:2023-02-16 22:32:15

通过添加实际存储数据的属性和字段。没有理由(我可以看到)你在内部定义枚举,这些枚举可以全部放在命名空间中的类之外。



现在看来,你的类只是一个容器(并且应该标记为静态),用于一些枚举和一些字符串。



如果您真正解释了想要存储在其中的以及它的目的是什么,而不是询问如何使其可配置,那么它可能会有所帮助。 / BLOCKQUOTE>

Hi I am working on a project that has the following class:

public class RS
{
    public enum dtData { TransactionID, TransactionDateTimeStamp, FileToCompress, DirectoryToCompress, CompressedFileName, Action };
    public enum dtTransaction { TransactionID, TransactionDate, CompressedFileName, TransactionSuccessFlag, TransactionErrors };
    public enum dtError { TransactionID, ErrorMessage, InnerException, StackTrace, Data };
    public enum dsTables { Transaction, Data, Error };
    public enum WEBCONFIGXML { UniqueID, TransactionDateTimeStamp, XElement, FirstNode, ConfigFileName, ConfigDirectory, Action }
    public enum Enviornments { Test1, Test2, Test3}

    public enum WEBCONFIGURATORXMLELEMENTS { Variable, Name, Description, value, TemplateDerivable, EnvironmentName }
    public enum WEBCONFIGURATORXML { Environment, Name, FilePrefix }


    public const String ConnectionString = "<Property Name=''ConnectionString'' Value=''|*|ConnectionString_AppDatabase|*||*|ConnectionString_Extension|*|''/>";
    public const String sendQueuePath = "<Property Name=''sendQueuePath'' Value=''|*|SendQueue_Sql|*|''/>";         
}



What is the best way for me to convert this class to a configurable item and how would I call this new item from within my code? Thanks in advance.

By adding properties and fields that actually store data. There is no reason (that I can see) that you are internally defining enumerations, these can all be placed outside of the class in a namespace by themselves.

As it stands right now, your class is just a container (and should be marked static) for some enumerations and some strings.

Maybe it would help if you actually explained what you wanted to store inside of it, and what its purpose is, rather than asking how to make it "configurable".