Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a program in C#,and I want to use xml in it.
I am very new to XML,I have a fairly large configuration data with lots of fields.I have managed to define a class based on my configuration fields,my class has lot of enums ,lists and user defined types.
Now I want to read/edit/modify/save the values in configuration,I am thinking of using an xml file.
Can you give me some direction.Should I define a xml schema? What should be the design of my program? Or please suggest how to do this fast and clean through existing APIs like LINQ etc.
In a nut shell
Can you explain
How to save class with lot of fields to XML through C#?
Do I need a schema?
How to read it back in same class and validate through schema?
Approach should be simple and unit testable.
You can use the XSD.exe tool to create a schema from your XML and generate a serializable class. Then you can populate the class instance in your code and serialize it out to XML, or deserialize the XML back into a class instance.
Search with a phrase something like 'serializable class with xsd.exe' and you will find plenty of tutorials.
Of course, there are newer and better ways if you just want to persist application configuration.
example
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I would like to initialize a record from a class. For example, I read in a bunch of objects from a ReST call. These objects should be immutable, so the record type would fit the bill nicely, but I want to write a bunch of code to convert them to records.
Suggestions?
I'm assuming you don't have write access to the API that creates the classes? Because, honestly, it would probably better just to rewrite that.
There are libraries available such as AutoMapper (https://github.com/AutoMapper/AutoMapper).
Beyond that, there are no casts you can use, and unless the classes are highly regular, you need to write custom conversions for each class.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am programing a game and want to save a couple of variables that are bool type. All of the values are stored In class named "Variables". can it be done without using external files if possible?
If you're programming against the Windows Forms model you can look into saving such simple data in the Application settings. This will alleviate some learning curve on serialization.
Take a look here for some insight: Best practice to save application settings in a Windows Forms Application
If the save game data is going to get more complex you'll probably want to start searching for info on XmlSerializer, JSON serialization, or if you need your data concealed from prying eyes: BinarySerializer
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to create a module that will generate class library project from given database columns that will include info class,dataprovider class and contorller class each having their own .cs file. What i have done now is that create info,provider and controller class.
I have researched to create class library project programatically but still not much success..What i want to do is create a class library project programatically and move those files to the project folder.After that compile the library project and generate dll file and move that to bin folder of website.
Can anyone please point me to the right direction or give some useful resources so that i can use that to solve my problem.
I would use a T4 template and then you can programatically emit a C# class based on your database structure.
https://msdn.microsoft.com/en-us/library/bb126445.aspx
I have used the T4 template and it is very useful for same type of code generation. We can have XML for configuration (class and properties) and then automatically we can create classes for them. They are useful since the same configuration can be used for database layer, mapping properties to database fields etc. so your back-end layers can be automated.
Note: All classes should have common design. Also make class as partial so that you can always add more functionality to it.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm being tasked with making a modular program that uses external, easy to edit files to dictate if certain elements are shown, what classes are used, etc.
Using C# and Visual Studio 2008, what type of file should I use? I was suggested .ini, but there is also talk of using .xml for it?
Which file would be best, and is there a built-in C# method of working with those files?
There's a heap of different ways for achieving different things. You could for example use an appSetting in an app.config file to turn features on and off. If you wanted to change classes or services that are used, then you could use DI/IoC with something like Castle Windsor and configure that in code and or xml.
If you can be more specific with what you want to achieve, and some examples in code, you can probably get some better answers.
you can use custom sections in your config files.
Config files are xml, well known files in .net context.
See example here: http://msdn.microsoft.com/en-us/library/vstudio/2tw134k3(v=vs.100).aspx
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm looking for a quick and simple way to convert large JSON objects in a text file to C# object notation for a company project. I would prefer an online solution (similar to jsbeautifier.org) that would take my code, parse it, and return a C# formatted object.
Are there any tools (preferably online) that will do this? I'm hoping not to do this by hand, but writing a script might take time that I don't have right now. (I'm not too well-versed with C# library calls.)
Thank you!
I think following link will help.
Generate c# classes from json
Actually it uses the same project which achitaka-san said in his post. You can create a simple WebService in any host and use it.
This application generates C# classes from a sample JSON text, so you can use strongly typed programming with JSON.
http://jsonclassgenerator.codeplex.com
This is not online, but you just download an EXE, paste your JSON and get a c# class - taht's it.