|
22 Eargesplitten posted:What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call. The idea is that you want fields to represent the internal state of your class, and allow access to them through methods responsible for accessing/mutating them. In Java, this is clumsily accomplished through having a bunch of boilerplate methods for getThing/setThing. If you want something to be invisible from outside the class, don't provide get/set methods. If you want something to be readonly, don't provide a set method. Properties are just cutting the boilerplate out. You get a backing field and get/set methods without having to write a ton of extra crap. If you need to put some validation logic or something of the like in later, nothing from outside the class needs to change. Fields and properties are not interchangeable -- changing a field to a property changes the IL generated and represents a breaking change to the application that requires all dependent assemblies to be recompiled. Your last question doesn't make sense, partially because of ambiguity: A "field" is a class-level variable (public int Foo = 0;. A "property" is an auto-implemented field with appropriate get/set methods (public int Foo { get; set; } = 0). If you're talking about something like this: code:
|
# ? Sep 18, 2016 22:43 |
|
|
# ? Jun 7, 2024 02:22 |
|
22 Eargesplitten posted:What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call. Of course, if you just use auto-implemented properties like C# code:
C# code:
22 Eargesplitten posted:Also, why can't I set a variable to be private and then make the getters and setters public? Coming from Java, this whole thing seems weird. C# code:
|
# ? Sep 18, 2016 22:43 |
|
Installing the System.Net.Http package breaks .NET Framework applications. This library is a dependency of the NETStandard.Library package. This means you cannot reference .NET Standard libraries in .NET Framework apps without fatally breaking some basic HTTP functionality. "[The fix] will be part of the .NET Core 1.1 release. I believe the timing is within a few months." was the developer response. Just when I thought maybe this new .NET was getting perhaps half mature.
|
# ? Sep 19, 2016 07:11 |
|
Ithaqua posted:The idea is that you want fields to represent the internal state of your class, and allow access to them through methods responsible for accessing/mutating them. In Java, this is clumsily accomplished through having a bunch of boilerplate methods for getThing/setThing. If you want something to be invisible from outside the class, don't provide get/set methods. If you want something to be readonly, don't provide a set method. Also, fields can be used in interface definitions, so it is common to find that an auto implemented field is simply satisfying the interface definition. dougdrums fucked around with this message at 08:51 on Sep 19, 2016 |
# ? Sep 19, 2016 08:47 |
|
EssOEss posted:Installing the System.Net.Http package breaks .NET Framework applications. This library is a dependency of the NETStandard.Library package. This means you cannot reference .NET Standard libraries in .NET Framework apps without fatally breaking some basic HTTP functionality.
|
# ? Sep 19, 2016 15:28 |
|
I thought the whole point of putting things as separate packages in Nuget was so they could fix issues without having to wait for a monolithic release?
|
# ? Sep 19, 2016 17:11 |
|
SirViver posted:Yes, that is their point. The syntax being like a variable access (that btw during compile gets rewritten to a classic get() or set() method call) just makes things nicer to look at and condenses separate get/set methods into a single property. It still fulfills the same purpose as manually written getter and setter methods. Okay, that makes more sense now. I think I'll need to use it more for it to really sink in, but it's a start. The second example is the way I generally did it in Java.
|
# ? Sep 19, 2016 17:51 |
|
So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires?
|
# ? Sep 19, 2016 19:23 |
|
my favorite new thing is discovering a dude who just uploads Microsoft libs to nuget that they don't put there themselves, but with subtly different versions so if you grab something that should match, whoops, you actually needed this other one! does nuget.org not have protected namespaces for vendors?
|
# ? Sep 20, 2016 00:27 |
|
uncurable mlady posted:my favorite new thing is discovering a dude who just uploads Microsoft libs to nuget that they don't put there themselves, but with subtly different versions so if you grab something that should match, whoops, you actually needed this other one! Could you point me to one please?
|
# ? Sep 20, 2016 01:16 |
|
ljw1004 posted:Could you point me to one please? https://www.nuget.org/profiles/bmarshall
|
# ? Sep 20, 2016 01:38 |
|
I didn't exhaustively go through them but I'd expect anything in the MS namespace to be listed by MS. We explicitly got tripped up by a different package that wasn't an MS one on there and idk if it was a fuckup on our end or what but I don't think dude has ownership either way
|
# ? Sep 20, 2016 01:41 |
|
darthbob88 posted:So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires? HTTP responses are already a stream. Are you trying to just code:
e: Try this one for example: http://stackoverflow.com/a/26041298 AWWNAW fucked around with this message at 02:08 on Sep 20, 2016 |
# ? Sep 20, 2016 02:06 |
|
darthbob88 posted:So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires? Not sure if the HTTP classes have methods that wrap this.
|
# ? Sep 20, 2016 03:08 |
|
I'm dumbfounded that this is allowed by nuget. Hopefully this rear end gets nuked with extreme prejudice.
|
# ? Sep 20, 2016 12:38 |
|
AWWNAW posted:HTTP responses are already a stream. Are you trying to just code:
|
# ? Sep 20, 2016 17:39 |
|
AWWNAW posted:HTTP responses are already a stream. Are you trying to just I'm not an expert in this area, but I did search around when I looked into this a year ago, and I came to the opposite conclusion. I found places which told me you CAN return a stream, and than ASP.NET will itself take over responsibility for copying the stream and disposing your stream handle once it's done. Of course I can't find them right now. All I left in my code was a comment that it is allowed. code:
http://blog.guvweb.co.uk/2014/07/02/streaming-web-api/ Caveat: I might be misunderstanding something here! And I don't know if the same is true of ASP.NET Core.
|
# ? Sep 20, 2016 17:51 |
|
Horn posted:I'm dumbfounded that this is allowed by nuget. Hopefully this rear end gets nuked with extreme prejudice. these packages definitely seem misleading. but I hope they don't take down whoever it is that uploads stuff like the Blend SDK, which would otherwise be an irritating install on everyone's machines just to get System.Windows.Interactivity...
|
# ? Sep 21, 2016 04:47 |
|
I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read.
|
# ? Sep 21, 2016 06:18 |
|
ljw1004 posted:I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read. I generally agree with that guy's sentiment, but that "style" of bug reporting is so loving grating.
|
# ? Sep 21, 2016 07:43 |
|
It's leakin' memory like a hell! Wait is this dude complaining that the clr isn't freeing native memory for him? Yeah it made more sense after I read beyond his op. Strange way to describe a problem though... vvvvv dougdrums fucked around with this message at 13:52 on Sep 21, 2016 |
# ? Sep 21, 2016 10:42 |
|
dougdrums posted:It's leakin' memory like a hell! No, he is saying that the stuff is leaking memory when it should not and nowhere is it made apparent how to stop it or why it does it.
|
# ? Sep 21, 2016 10:58 |
|
dougdrums posted:It's leakin' memory like a hell! New thread title, please
|
# ? Sep 21, 2016 14:21 |
|
22 Eargesplitten posted:What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call. It feels like no one addressed your *specific* concern here so I'll throw in my two cents: Properties in C# are syntactic sugar over the exact same get/set pattern you use in Java. So the following code is equivalent: C# code:
Java code:
When you use them the C# code is exactly equivalent to the Java code (in fact the intermediate bytecode language is virtually identical to the Java code): C# code:
C# code:
Finally in C# 6 they introduced an additional bit of syntax. Sometimes you want to initialize your property to something other than the default. Autoproperties won't let you do that because you don't control what the name of the underlying field is (it's auto-generated) so there's no hook to initialize it. So now you have "auto-implemented properties". C# code:
C# code:
The point is these are all equivalent. C# properties are just syntax over normal get/set in Java. Behaviorally it's exactly the same.
|
# ? Sep 21, 2016 17:42 |
|
Running into a strange issue after upgrading some nuget packages in a web api solution. I have a few methods that just return a simple integer. The response used to be just an integer like code:
code:
Anyone seen this lately? I know the first response isn't valid json but would hate to have to throw in a converter for primitive types. Edit: The solution was fixing some of the initialization code for the jsonp formatter we are using. SixPabst fucked around with this message at 19:44 on Sep 21, 2016 |
# ? Sep 21, 2016 19:23 |
|
I'm drawing a blank on something related to list comparison.code:
I tried this as: code:
|
# ? Sep 22, 2016 19:21 |
|
Uziel posted:I'm drawing a blank on something related to list comparison. What type is WorkAreas? What type is areaTechAreaIds?
|
# ? Sep 22, 2016 19:50 |
|
Ithaqua posted:What type is WorkAreas? What type is areaTechAreaIds?
|
# ? Sep 22, 2016 19:52 |
|
Uziel posted:Both are List<int>.
|
# ? Sep 22, 2016 20:04 |
|
mystes posted:Are you trying to pass a list to contains?
|
# ? Sep 22, 2016 20:06 |
|
Uziel posted:Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.
|
# ? Sep 22, 2016 20:11 |
|
Uziel posted:Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though. I haven't written C# in a year or so but you should be able to use .Any() on the list instead of .Contains()
|
# ? Sep 22, 2016 20:15 |
|
Uziel posted:Does this tech have ALL of the areas in their work areas list? First thing that pops into my head code:
|
# ? Sep 22, 2016 20:29 |
|
I'm not sure what 'area' and 'tech' are, but I understand that you want to add only workers that are able to work in all of the given areas to the list. I think what you want to do is something like:code:
dougdrums fucked around with this message at 20:49 on Sep 22, 2016 |
# ? Sep 22, 2016 20:35 |
|
Uziel posted:Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though. To check if listA contains all items that are in listB use this: C# code:
Optionally, you could use HashSets since what you're actually doing is a set operation (i.e. asking "is B a subset of A?"): C# code:
C# code:
Bognar fucked around with this message at 15:06 on Sep 23, 2016 |
# ? Sep 23, 2016 14:54 |
|
ljw1004 posted:I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read. it is! thanks for helping get info out there. it's really useful to know these details (like: winrtxaml subclasses have IReferenceTracker for communicating refcounted graphs to the gc, but nonxaml controls can't use it) when planning app architectures
|
# ? Sep 23, 2016 16:00 |
|
although i admit most of the planning comes down to "keep avoiding the tech, reevaluate each time the developers announce heroic new measures to workaround the basic problematic premise"
|
# ? Sep 23, 2016 16:02 |
|
Bognar posted:However, I would opt to just implement IsSubsetOf as an extension on IEnumerable since Except is implemented in terms of HashSets so the performance is the same (http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,785):
|
# ? Sep 23, 2016 18:43 |
|
Edit: Nevermind, figured it out. This is working really strange... I'm getting new field items added to my list, but originalkey, data, and groupid are getting overwritten on every object. I'm assuming entity framework is just trying to be efficient and not run that query again... How do I stop that? Data and OriginalKey are [NotMapped], they're just used to help build the model for knockout.js mapping. code:
bobua fucked around with this message at 21:08 on Sep 23, 2016 |
# ? Sep 23, 2016 20:56 |
|
|
# ? Jun 7, 2024 02:22 |
|
bobua posted:Edit: Nevermind, figured it out. Thanks for sharing the solutions with us.
|
# ? Sep 24, 2016 09:57 |