Хранение шаблонов с использованием словаря в C # - PullRequest
0 голосов
/ 18 января 2010

Я должен хранить некоторые шаблоны на основе кода состояния. Я не могу сохранить их в базе данных.Поэтому я подумал о создании словаря с кодом состояния в качестве ключа и списком в качестве значения.Я выбрал список, потому что мне нужен шаблон строка за строкой. Поэтому каждая строка в списке является строкой.Есть ли лучший способ справиться с такой ситуацией.Пожалуйста, прокомментируйте.

private static readonly Dictionary<string, List<string>> NotaryForStates = new Dictionary<string, List<string>>()
    {
        {"AR",new List<string> {"Per Steve Hollowell, ESQ from the Legal Division of the AR, SOS. Telephone number for the Legal Division of the SOS: (501)-682-3012. Arkansas Code 16-47-101.", "State of Arkansas", "County of <notary county>","On this day, <sign date> before me, <name of notary>, the undersigned notary, personally appeared, <name of signer> who acknowledged he/she is the <title of signer> of <name of company> and that he/she as such <title of signer>, being authorized so to do, executed the foregoing instrument for the purposes therein contained, by signing the name of the corporation by himself/herself as <title of signer>.","In witness whereof I hereunto set my hand and official seal.","______________________","Notary Public","<Notary name>","My Commission expires: <notary commission date>"}},
        {"CA",new List<string>{"State of California","County of <Notary County>","On <sign date> before me, <Notary Name>, Notary Public, personally appeared <Signing Party Name>, who proved to me on the basis of satisfactory evidence to be the person(s) whose name is subscribed to the within instrument and acknowledged to me that he/she executed the same in his/her authorized capacity, and that by his/her signature on the instrument the person, or the entity upon behalf of which the person acted, executed the instrument.","I certify under PENALTY OF PERJURY under the laws of the State of California that the foregoing paragraph is true and correct.","WITNESS my hand and official seal.","______________________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}},
        {"FL",new List<string>{"State of Florida","County of <Notary County>","On <sign date> before me, the undersigned, a Notary Public, for said County and State, personally appeared  <Signing Party Name>,  personally known to me to be the person that executed the foregoing instrument and acknowledged that is a <signer title> of <name of company>  and that he/she did execute the foregoing instrument.   <Name of Signer> is personally known to me.","_____________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}}
    };

Ответы [ 2 ]

0 голосов
/ 18 января 2010

Другой альтернативой является использование файлов ресурсов (которые обычно используются для локализации). Файлы ресурсов предоставляют место для хранения текста или других типов объектов, которые можно использовать в веб-сайте, приложении WPF или Windows Forms, создавая тем самым центральное место для хранения текста. Использование файлов ресурсов также может упростить обслуживание вашего приложения.

0 голосов
/ 18 января 2010

Первый вариант: вы можете использовать простую строку вместо списка и отделить отдельные строки с помощью Environment.NewLine ("\ n"). Вы можете легко создать такие строки с помощью объекта StringBuilder и разделить его снова (если вам нужно) с помощью метода string.Split(). Это также (немного) быстрее, чем подход List<string>.

Второй вариант: вы можете использовать файлы и хранить только имя файла в вашем словаре.

Является ли один из вышеперечисленных вариантов лучшей альтернативой вашему первоначальному подходу, зависит от конкретного проекта, над которым вы работаете. В целом, подход List<string> вполне может быть в порядке ...

НТН!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...