A quick start with C# - Printable Version +- [TC] Gaming Forums (https://forum.city-driving.co.uk) +-- Forum: General Information (/forumdisplay.php?fid=1) +--- Forum: General Discussions (/forumdisplay.php?fid=4) +---- Forum: Developer Forum (/forumdisplay.php?fid=221) +---- Thread: A quick start with C# (/showthread.php?tid=27257) |
A quick start with C# - Adorable - 2017-08-29 02:02 Using [TC]s new API inside C# Applications: NOTE: Json.NET Library needed for converting from JSON -> .NET Code: class tcApi Obtaining Json.NET I recommend to anyone coding C# to use Visual Studio (A cross platform IDE), its just a matter of executing a command in the NuGeT Package manager console to obtain the library: Install-Package Newtonsoft.Json You do not need to download, drag and drop or link with the compiler. the program does it for you! Usage Add the classes "tcApi" and "Actions" to your project Make new instance of the class tcApi Use the method "getData" and pass in a string from the Action class, a deserialized dynamic object will be returned. Code: tcApi api = new tcApi(); NOTE: I covered the most important end points, rest will be added soon. Always refer to the documentation for the exact key value pairs property names as they are case sensitive, it is also important to surround your code with try {} and catch {} to avoid possible errors / crashes (eg: a mispelled username). RE: A quick start with C# - Kyle - 2017-08-29 07:27 Not like I understand any of this, but it looks nice! Good work RE: A quick start with C# - Pete - 2017-08-29 11:39 For a fetching function, like the examples already in the docs, that function should do all of the query building. All of the necessary data to run the request should be passed in to your main tcApi class. In your example you end up building the query strings in your helper class code, outside of the fetching function. The examples in the docs take in a very basic object which contains all of the necessary data to make the request, for example the config in the JS example: Code: var key = 'YOUR_KEY'; Your example should do the same so that the user of your function does not need to build query strings in order to make requests for data. If you'd like to have a go at making your main request function as fully featured as the PHP and JS examples in the docs, I can add it to that. |