How will you store the table table constant Data in your C # project?

I am currently writing a plugin for CAD style software. The plugin performs calculations based on data read from the CAD model and a large number of searches in the table (think of printed tables in the calculation guide). I inherited this plugin, and the current solution defines a class Constantthat has a bunch of static structure elements and two-dimensional arrays. Then these arrays are indexed by enumeration values ​​at runtime to find the corresponding data.

I am not very happy with the decision, because the representation in the class is Constantquite difficult to read - the enumeration values ​​used when extracting the data are, of course, not visible when editing the data (although this only ever happens manually and very rarely).

I would prefer not to associate DB (and the engine) with a small plugin, but I would like to use similar semantics, for example, using LINQ to select values ​​where some fields match, etc.

What is your preferred solution to this problem?

  • Do you use a bunch of XML files and parse them at runtime?
  • Do you use the template engine (t4?) To generate classes from XML files at compile time?
  • You store XML versions of datasets in resources (read them at runtime, LINQ to dataset ...)
  • Constants, , ( - ...)
+3
5

. , , - ( ), ( ) , LINQ-to-Objects.

xml , - .

, , ( , ).

: ( , /// .. ). ( ) :

// during release
MyDataModel data = new MyDataModel(); // wraps multiple data lists
data.Load(); // from database tables, using ORM
data.Save("data.bin"); // serialization

data.bin (, , ...); :

MyDataModel data = new MyDataModel();
data.Load("data.bin"); // deserialization
data.Freeze(); // make immutable

, " popsicle" - "" (, ), Freeze , ; , ( ) . : , !

+4

, XML-dataset-in-resources. ( , , ), , XML .

+1

, XML . , .

VS, : Build Action = > Embedded Resource .

:

// name is the name of the embedded resource
Assembly.GetExecutingAssembly().GetManifestResourceStream(name); 

.

, , , . , API.

+1

Constant.
, , MDB (MS Access) MDF (SQL Express). .

, Constant . . pre-build , .

0

XML ( ), // .


, Pavels, , XML Visual Studio (VS): VS 2003 (., , " 6.28. XML-: " , ), ​​ VS 2005 (., , XML Visual Studio 2005 Visual Studio 2003) VS 2008 (., , XML- Visual Studio 2008), , . (, ) XML, , , VS 2010, XML.


: XML- XML . , XML Intellisense (.. ) . XML - "", " " XML Notepad 2007.

XML- , , , , .NET- / LINQ- Microsoft XML (Xsd.exe). ( , XML-, , t4).

, , , XML, imho.

XML Constant, . '/t' Xsd.exe. , , / .

, (), .., XML LINQ ( ).

0

Source: https://habr.com/ru/post/1712645/


All Articles