|
it's called a 'code smell'
|
# ? Mar 14, 2017 04:13 |
|
|
# ? May 17, 2024 10:02 |
|
uncurable mlady posted:it's called a 'code smell' nah code smell is used for things that are a lot more fuzzy to describe. thats most def a lambda, it has a firm definition
|
# ? Mar 14, 2017 04:36 |
|
I shall name it "the mysterious case of the missing whitespace characters"
|
# ? Mar 14, 2017 09:16 |
|
The "premature minification" sounds good to me.
|
# ? Mar 14, 2017 12:02 |
|
If it's wrong to make operators look like other things by strategically omitting whitespace for anything else than comedic effect then I don't want to be wrong, because gently caress that poo poo.
|
# ? Mar 14, 2017 15:12 |
|
The Prostate Operator
|
# ? Mar 14, 2017 16:44 |
|
The Wizard of Poz posted:It's not "just an assignment". Oh okay, I thought you could assign expressions to variables, looks like I was mistaken, thanks for the clarification. Also uncurable mlady posted:it's called a 'code smell' Mr. Crow fucked around with this message at 21:54 on Mar 14, 2017 |
# ? Mar 14, 2017 21:51 |
|
After doing some more reading, it seems to be used in a few Linq-to-GPU schemes for writing functional kernels. http://www.aleagpu.com/release/3_0_2/doc/gpu_programming_csharp.html#lambdas for example. I take 'code smell' to mean that thing I do in other languages where I'm not quite sure how something is supposed to work, but I shoehorn in whatever does the job. Also I think they should be called delegate expressions instead of lambda expressions ... obviously actions are not lambda terms, and things like code:
|
# ? Mar 15, 2017 00:22 |
|
Just so we are clear, the only thing that smells about the example you started the discussion with is the weird-rear end formatting. The concept itself is a perfectly fine usage of C# if you format it correctly so it does not look like some weirdass "arrow through a portal":code:
|
# ? Mar 15, 2017 07:21 |
|
Yeah, it's a small bit of context, so to speak. I take it that some of y'all work with people who might actually take this to be a good idea…
|
# ? Mar 15, 2017 12:12 |
|
Mr. Crow posted:Oh okay, I thought you could assign expressions to variables, looks like I was mistaken, thanks for the clarification. I think this probably isn't what you meant, but you can assign capital-E Expressions to variables, using the same syntax: code:
|
# ? Mar 15, 2017 14:19 |
|
Let's talk Json.NET for a second. I'm pulling JSON from WeatherUnderground and hoping to insert it into a class I've generated from json2csharp, but I'm not exactly sure how to do so. J2C# returns multiple classes and I'm not really sure how to approach this.code:
Do I make classes for each of these and have the JSON deserialize into each? All the examples I've come across are dealing with a single class. Am I missing something and you can just slap it inside one class and it just works?
|
# ? Mar 16, 2017 15:40 |
|
Warbird posted:Let's talk Json.NET for a second. I'm pulling JSON from WeatherUnderground and hoping to insert it into a class I've generated from json2csharp, but I'm not exactly sure how to do so. J2C# returns multiple classes and I'm not really sure how to approach this. Do you have an example response from the API you can post? If you've got nested objects in your Json, the easiest way is to create a class structure that matches that, i.e. a top level class which holds instances of other classes for the nested stuff.
|
# ? Mar 16, 2017 15:53 |
|
Warbird posted:Do I make classes for each of these and have the JSON deserialize into each? All the examples I've come across are dealing with a single class. Am I missing something and you can just slap it inside one class and it just works? it should have given you a root object, like this code:
code:
code:
|
# ? Mar 16, 2017 16:00 |
|
One day I'm going to be able to say "I want to try to do X" and not end up grinding my teeth down to nubs. Can you do a pseudocode example or something of how to go from a given JSON object to a C# class or the like? I'm about to throw this computer through the first readily available window.
|
# ? Mar 16, 2017 17:05 |
|
Out of curiosity, do you have a reason for using json2csharp instead of Visual Studio's built-in "Paste JSON as classes" command?
|
# ? Mar 16, 2017 17:15 |
|
You probably want to use Newtonsoft Json. Their front page (http://www.newtonsoft.com/json) gives basic examples and I'm sure you can find 1000s more on stackoverflow.
|
# ? Mar 16, 2017 17:15 |
|
Horn posted:You probably want to use Newtonsoft Json. Their front page (http://www.newtonsoft.com/json) gives basic examples and I'm sure you can find 1000s more on stackoverflow. He is, I think. He said he was using Json.NET which is what the Newtonsoft library is called. Warbird posted:One day I'm going to be able to say "I want to try to do X" and not end up grinding my teeth down to nubs. Can you do a pseudocode example or something of how to go from a given JSON object to a C# class or the like? I'm about to throw this computer through the first readily available window. It's a one-liner to do the actual deserialization if you have your classes structured the same as your json, and any non-matching property names decorated with the JsonPropery attribute as Drastic Actions said: code:
What errors are you actually getting? If you give us your code and and example response, it should be fairly obvious what's going wrong. chippy fucked around with this message at 17:29 on Mar 16, 2017 |
# ? Mar 16, 2017 17:27 |
|
Horn posted:You probably want to use Newtonsoft Json. Their front page (http://www.newtonsoft.com/json) gives basic examples and I'm sure you can find 1000s more on stackoverflow. Isn't newtonsoft the default json package installed with MVC?
|
# ? Mar 16, 2017 17:28 |
|
NihilCredo posted:Out of curiosity, do you have a reason for using json2csharp instead of Visual Studio's built-in "Paste JSON as classes" command? None whatsoever. "I've been meaning to try working with APIs. It would be neat if I could make a desktop application to show the temp outside." was the entire planning process here. Strictly to see how it worked. The only reason I'm using whatever it is I am is because that's whatever guide I walked into recommended it. I really hope the VS command you're talking about is a joke or obtusely hard to use. If that's something built in and easy to use then in going to be sick. Several hours a billion chrome tabs later all I have to show is a headache. Assume I know absolutely nothing but the basics of programming. (ie- I once spent two weeks wondering why the html files on my webserver weren't rendering before I figured out that I needed to install Apache) Warbird fucked around with this message at 17:42 on Mar 16, 2017 |
# ? Mar 16, 2017 17:39 |
|
I find serialization is effortless until it isn't and then it's a huge pain in the rear end, so have some solace there. Usually if you're having problems try and make it simpler and get the basic value types into a class then start building from there. Lists and complex types are always hit and miss depending on which serialization library you're using.
|
# ? Mar 16, 2017 17:41 |
|
Mr. Crow posted:I find serialization is effortless until it isn't and then it's a huge pain in the rear end, so have some solace there.. Preach. In fact, I think you can extend this comment to working with 3rd party web based APIs, generally. I've had to do a lot of work with the Salesforce and Workplace (Facebook at work) APIs recently, and it's all either been beautiful or excruciating.
|
# ? Mar 16, 2017 17:50 |
|
NihilCredo posted:Out of curiosity, do you have a reason for using json2csharp instead of Visual Studio's built-in "Paste JSON as classes" command? God drat it, why did this have to work? Thank you all for the help! One more, hopefully easier, best practices question. Right now I've got the generated classes sitting below my main loop/program code:
|
# ? Mar 16, 2017 18:22 |
|
Warbird posted:One day I'm going to be able to say "I want to try to do X" and not end up grinding my teeth down to nubs. Can you do a pseudocode example or something of how to go from a given JSON object to a C# class or the like? I'm about to throw this computer through the first readily available window. I wrote an Xamarin Workbooks Example of JSON.NET Serialization and Deserialization. You can download Workbooks here. It's free. I would also say that I tend to not use types when using JSON.NET, and just deserialize it to `dynamic`.
|
# ? Mar 16, 2017 18:22 |
|
I had it working via a bit back, but you lose intellisense. I need all the help I can get, so not having it is not ideal.
|
# ? Mar 16, 2017 18:53 |
|
Most C# coding standards mandate one class per file, it's usually a good rule until it isn't. For code like that I'd put all your generated classes in a separate file because they are "different" sort of code that should be separate from your logic, but not move them out to individual files per class because they are so closely interlinked and if you want to regenerate them it's all in one place. Really it's a per-taste thing, the compiler doesn't care.
|
# ? Mar 16, 2017 23:46 |
|
I'm looking at creating an Excel VSTO Addin that does the following: - Pulls data from SQL Server to an Excel Workbook. - User then makes changes to data (offline) - User then makes a request to "push" the data back into the database. - A list of differences is shown. - User then signs off on differences, adds comments, etc.. and the data is saved into SQL Server. My understanding is that this is basically a "disconnected entities" problem, and that EF6 could handle stuff such as the list of differences, via change tracking? Obviously there will be some massaging of the data between SQL Server & Excel, but is this the correct path to be researching?
|
# ? Mar 17, 2017 04:05 |
|
riichiee posted:I'm looking at creating an Excel VSTO Addin that does the following: I don't know anything about the EF6 stuff, but for Excel addins in general, Excel-DNA is slick as hell and may be worth looking into.
|
# ? Mar 17, 2017 12:56 |
|
MisterZimbu posted:Ugh, there's a longstanding bug in Visual Studio/.NET (?) that's been the bane of my existence for about a year. This was more of a frustrated rant than a call for support, but I ended up finding the cause of this - both of the projects had a common dependency that included an older WebApi from Program Files instead of from NuGet. Both projects also included Newtonsoft.Json, so when you build the whole solution, the correct DLL gets included. However, when you built a single project, it would rebuild the dependency, and copy WebApi - and its older Json.net DLL - into the output of the other project.
|
# ? Mar 17, 2017 13:19 |
|
Doing Regex stuff now because that's less frustrating than JSON/APIs. Right? Right? I've actually had a decent amount of success, but I'm tripping at the finish line. I've got a large .XPS document that I've used a scientific process to extract the data out of (zoomed all the way out and just copied pasted the text out to a .txt) and I've gotten it down to one big ol' flat CSV. Now I just want to toss some newlines in on every third comma so Excel can make it into the semi structured table it was in when it was a .XPS. code:
|
# ? Mar 17, 2017 15:10 |
|
Warbird posted:Doing Regex stuff now because that's less frustrating than JSON/APIs. Right? Right? I'm guessing that the leading ^ is anchoring just at the start of your string. Since you're starting with what I assume is a single line of text anyway, setting the multiline option won't work. What you probably want is a regex more like: code:
|
# ? Mar 17, 2017 16:06 |
|
Beautiful, thank you! The output is still a bit off, but I'm 99% sure that due to some inconsistent formatting somewhere in the source doc. Hooray for unstructured text inputs! Edit: Yep, some dumbass double spaced where they weren't supposed to and it threw things off mid file. Hopefully tweaking regex to break on a large whitespace amount will sort it out. Warbird fucked around with this message at 17:06 on Mar 17, 2017 |
# ? Mar 17, 2017 17:01 |
|
Warbird posted:Beautiful, thank you! The output is still a bit off, but I'm 99% sure that due to some inconsistent formatting somewhere in the source doc. Hooray for unstructured text inputs! Wow, you really have a way of picking "awkward" stuff. RegEx compared to JSON makes serializing seem so simple.
|
# ? Mar 17, 2017 17:20 |
|
Mr Shiny Pants posted:Wow, you really have a way of picking "awkward" stuff. RegEx compared to JSON makes serializing seem so simple. I'm just happy I could finally contribute. RegEx is something that weirdly clicked with me back in college, and I love using them to solve text processing problems.
|
# ? Mar 17, 2017 17:29 |
|
Mr Shiny Pants posted:Wow, you really have a way of picking "awkward" stuff. RegEx compared to JSON makes serializing seem so simple. JSON was "I don't want to work, but do something that I could leverage as being useful to work to justify not working", RegEx is "I need to parse a huge amount to text for work and I don't want to wish I was dead doing it". On that note, anyone know if VS has functionality for me to load in a .edmx and see all the entity relationships and so forth?
|
# ? Mar 17, 2017 20:19 |
|
I'm using ASP.NET Core and EntityFramework Core. I'm trying to add an item to a list from a database query doing the following: code:
quote:Argument 1: Cannot convert from 'System.Linq.IQueryable<GroupListViewModel>' to 'GroupListViewModel' So my question is, what did I do wrong? Why won't it let me add an item to the List<GroupListViewModel> ?
|
# ? Mar 19, 2017 00:24 |
|
ModeSix posted:I'm using ASP.NET Core and EntityFramework Core. Without more context, it looks like your .Select is going to return an IQueryable result which could potentially contain multiple objects. Then you are trying to add it as a single object to your list. You can either use SingleOrDefault or FirstOrDefault to make it to a single object. If you WANT the possibility of a collection being returned by your .Select then you can pass the results to .AddRange on your list instead of .Add.
|
# ? Mar 19, 2017 00:34 |
|
Dr. Poz posted:Without more context, it looks like your .Select is going to return an IQueryable result which could potentially contain multiple objects. Then you are trying to add it as a single object to your list. You can either use SingleOrDefault or FirstOrDefault to make it to a single object. If you WANT the possibility of a collection being returned by your .Select then you can pass the results to .AddRange on your list instead of .Add. Perfect! Thank you, AddRange was exactly what fixed it and it's doing exactly what I want it to do now. I did in fact want all of the returned objects added to the List, because I need to iterate over them in the View to fill out a table with multiple columns. Appreciate the help. ModeSix fucked around with this message at 00:40 on Mar 19, 2017 |
# ? Mar 19, 2017 00:37 |
|
IS NUGET DOWN!?!?!?!?!?
|
# ? Mar 22, 2017 07:05 |
|
|
# ? May 17, 2024 10:02 |
|
Where the hell do I find an official copy of the Microsoft Limited Public License? I'm doing one of those awful licensing scans on our code and need to prove that we're allowed to use code from MSDN examples, which according to this page is allowed under the "Microsoft Limited Public License."quote:Software accessible on the Documentation Portals is made available by the designated publisher under the associated license terms. If Software is accessible on the Documentation Portals without license terms, then subject subsection (c) below you may use it to design, develop, and test your programs. If any such Software without license terms is marked as “sample” or “example,” then you may use it under the terms of the Microsoft Limited Public License. Searching for "Microsoft Limited Public License" gets me a bunch of Stack Overflow questions and some other sites' copies of different versions of the license, but nothing official. I need the latest, official version of the license, especially considering that some sites' versions specify that the license only applies to code running on Windows, while the apparent newer version is slightly more flexible (enough that we should be okay with Xamarin). e: Eh, nevermind, our scanner thing has the license in its own database. Good enough for me. GameCube fucked around with this message at 20:36 on Mar 22, 2017 |
# ? Mar 22, 2017 20:27 |