|
Smugdog Millionaire posted:I've been surveying people about this C# behavior: http://dotnetpad.net/ViewPaste/zgKo84NzE0-wEQs8fYvVkA That does exactly what i would expect it to be doing.
|
# ? Oct 27, 2011 19:00 |
|
|
# ? Apr 26, 2024 22:23 |
|
Smugdog Millionaire posted:I've been surveying people about this C# behavior: http://dotnetpad.net/ViewPaste/zgKo84NzE0-wEQs8fYvVkA EDIT: And here's how to make it behave the way I might have originally expected: http://dotnetpad.net/ViewPaste/EtPyvevTwUaRKCRRMZAfIg though I hope you don't mind some run-time resolution. Zhentar posted:If you read it just a little more often, you wouldn't be surprised at all. Jethro fucked around with this message at 20:32 on Oct 27, 2011 |
# ? Oct 27, 2011 19:41 |
|
I find that unsurprising. The only details you need to know for it to make sense are that unlike C++ templates, C# generics are only compiled to one copy of the function and that overload resolution is done at compile time.
|
# ? Oct 27, 2011 19:42 |
|
Jethro posted:It's not what I'd naively expect, but I read Fabulous Adventures in Coding often enough to know that this sort of thing can often act in ways contrary to a naive understanding. If you read it just a little more often, you wouldn't be surprised at all.
|
# ? Oct 27, 2011 20:12 |
|
"Generics are not templates" is a great summary.
|
# ? Oct 27, 2011 21:59 |
|
My company uses Microsoft Exchange server and for my ASP.NET website, I am trying to retrieve the Public Distribution Lists (PDLs) for what some users are in. Is there any way to do this?
|
# ? Oct 27, 2011 23:57 |
|
What version of exchange? Pray it is 2007 or better and you get exchange web services.
|
# ? Oct 28, 2011 00:31 |
|
wwb posted:What version of exchange? Pray it is 2007 or better and you get exchange web services. Yeah, it's 2010.
|
# ? Oct 28, 2011 00:34 |
|
I have a function that essentially does an object -> csv transformation. What I'd like to do though, is pass in an array of accessors for the properties instead of reflecting over names etc. What I want is to do something like ObjectToCSV(i => i.PropertyA, i.PropertyB, i.PropertyC.subPropertyA) and be able to tell in the function what the full property name is (e.g. PropertyA, PropertyB, PropertyC.subPropertyA) and its value.
|
# ? Oct 28, 2011 03:11 |
|
You're looking for LINQ expressions. Your method signature will look something like this:code:
code:
|
# ? Oct 28, 2011 05:18 |
|
Here's the basics of reflecting a lambda.code:
|
# ? Oct 28, 2011 12:47 |
|
Nurbs posted:I have a function that essentially does an object -> csv transformation. What I'd like to do though, is pass in an array of accessors for the properties instead of reflecting over names etc. You could use this extension to String to do what you want like this: code:
Or I suppose the extension method could be altered to do CSV formatting
|
# ? Oct 28, 2011 17:29 |
|
Nurbs posted:I have a function that essentially does an object -> csv transformation. What I'd like to do though, is pass in an array of accessors for the properties instead of reflecting over names etc. Are you re-inventing serialization?
|
# ? Oct 28, 2011 18:46 |
|
I have a static class in which I want to have some "constants" for other classes to use. Problem is, some of these constants can't actually use const keyword (e.g. one is a TimeSpan object, another is a string pulled from an environment variable). My solution is to make them properties with a private set that get initialized in the static constructor. I just wondered if there's a cleaner way to do this? Edit: Actually, it looks like readonly might be the keyword I need. Is that right? VVV Thanks, just found a page just like that Eggnogium fucked around with this message at 20:20 on Oct 28, 2011 |
# ? Oct 28, 2011 20:18 |
|
Eggnogium posted:I have a static class in which I want to have some "constants" for other classes to use. Problem is, some of these constants can't actually use const keyword (e.g. one is a TimeSpan object, another is a string pulled from an environment variable). The readonly keyword is your friend here: http://weblogs.asp.net/psteele/archive/2004/01/27/63416.aspx
|
# ? Oct 28, 2011 20:19 |
|
A constant can only be a primitive because all references to it in code are literally replaced with the declared value on compilation. A read-only variable, on the other hand, can be anything, but does not get the slight performance edge of avoiding a reference lookup on execution.
|
# ? Oct 28, 2011 20:29 |
|
Dietrich posted:A constant can only be a primitive because all references to it in code are literally replaced with the declared value on compilation. A read-only variable, on the other hand, can be anything, but does not get the slight performance edge of avoiding a reference lookup on execution. This doesn't actually impact me but out of curiosity, are readonly fields populated before the constructor is called? Like if I needed to do a few lines of processing before having everything set up to instantiate my read only field, would I be able to do that and assign to the field in the constructor? Or does the initialization have to be in-line in the class defintion?
|
# ? Oct 28, 2011 21:05 |
|
You can set ReadOnly variables in the constructor.
|
# ? Oct 28, 2011 21:34 |
|
Eggnogium posted:This doesn't actually impact me but out of curiosity, are readonly fields populated before the constructor is called? Like if I needed to do a few lines of processing before having everything set up to instantiate my read only field, would I be able to do that and assign to the field in the constructor? Or does the initialization have to be in-line in the class defintion? Read only fields can only be populated inline or during the constructor. It is good practice to make fields that are initialized via the constructor readonly unless you have need for them to be changed post construction. In fact it is one of the suggestions offered by resharper by default.
|
# ? Oct 29, 2011 01:11 |
|
ljw1004 posted:Are you re-inventing serialization? God no, that's not what I want to do. I was just looking for a way to de-serialize an object to csv with linq expressions representing X properties instead of string names of properties. Thanks to all the repliers! Nurbs fucked around with this message at 05:59 on Oct 29, 2011 |
# ? Oct 29, 2011 03:24 |
|
Eggnogium posted:This doesn't actually impact me but out of curiosity, are readonly fields populated before the constructor is called? Like if I needed to do a few lines of processing before having everything set up to instantiate my read only field, would I be able to do that and assign to the field in the constructor? Or does the initialization have to be in-line in the class defintion? Inline intialization is syntactic sugar for constructor code anyway. If you look at the actual IL any in-line field initialization statements are just copied into the top of all constructors defined on the class.
|
# ? Oct 29, 2011 05:23 |
|
I'm using connector/net to get a datatable object of a mysql table, and one of the columns in the mysql table is longtext. I'm trying to bind the column to a control, but the textbox/richtextbox controls don't seem capable of handling it, is there a different control I should be using? Edit: nevermind i'm a complete moron that doesn't use enough exception handling. NtotheTC fucked around with this message at 21:10 on Oct 30, 2011 |
# ? Oct 30, 2011 08:47 |
|
I have a C application that receives a FILE * and writes stuff to it, and I want to use this functionality from .NET (4.0). I know how to do basic platform invoke, but I can't figure out what to use for the FILE * in the call into the native application. I tried using the unsafe handle from an anonymous PipeStream but I'm not receiving any data (even after I turned buffering off on the C side - I couldn't see how to try that on the C# side). I feel like I should be using an UnmanagedMemoryStream but I can't figure out how to set it up. As icing on the cake, this needs to be asynchronous.
|
# ? Oct 30, 2011 21:03 |
|
The managed APIs wrap HANDLE which is not the same as FILE*. You will have to call a native method which returns a FILE*, like fopen. You might be able to use Windows APIs like _fdopen to get a FILE* from a HANDLE.
|
# ? Oct 30, 2011 22:19 |
|
GrumpyDoctor posted:I have a C application that receives a FILE * and writes stuff to it, and I want to use this functionality from .NET (4.0). I know how to do basic platform invoke, but I can't figure out what to use for the FILE * in the call into the native application. I tried using the unsafe handle from an anonymous PipeStream but I'm not receiving any data (even after I turned buffering off on the C side - I couldn't see how to try that on the C# side). I feel like I should be using an UnmanagedMemoryStream but I can't figure out how to set it up. Any reason why you can't just run a completely separate C# application that reads the file?
|
# ? Oct 30, 2011 23:57 |
|
Sedro posted:The managed APIs wrap HANDLE which is not the same as FILE*. You will have to call a native method which returns a FILE*, like fopen. You might be able to use Windows APIs like _fdopen to get a FILE* from a HANDLE. Ah, thanks. Time to do some digging I guess. (I found a stackoverflow question asking about the reverse problem. Ithaqua posted:Any reason why you can't just run a completely separate C# application that reads the file? There are no actual files (necessarily) involved.
|
# ? Oct 31, 2011 01:01 |
|
GrumpyDoctor posted:There are no actual files (necessarily) involved. You should consider involving them unless you have a compelling reason not to. Using FILE* across a managed->native boundary is going to be more headache than it's worth.
|
# ? Oct 31, 2011 02:06 |
|
Sedro posted:You should consider involving them unless you have a compelling reason not to. Using FILE* across a managed->native boundary is going to be more headache than it's worth. No, I mean there are literally no files to involve. The problem at the root of all this is that I have a native DLL that writes to standard output (Pretty Dumb, I know, but this is where poor planning gets you) and I want to capture that output. If there's a better way to do this, I'm all ears; I was under the impression that DLLs didn't have their own standard outputs, and since my hosting application uses a GUI it didn't have a standard output to redirect either, so I just quickly modified the DLL to write an an arbitrary FILE *, hoping that I could pass something useful to it. If that isn't the case there are definitely some other things I can try.
|
# ? Oct 31, 2011 07:31 |
|
You could wrap the dll in a console application, then invoke it as a subprocess (disabling its console window) and capture the stdout of that.
TasteMyHouse fucked around with this message at 13:52 on Oct 31, 2011 |
# ? Oct 31, 2011 13:44 |
|
TasteMyHouse posted:You could wrap the dll in a console application, then invoke it as a subprocess (disabling its console window) and capture the stdout of that. Yeah, that's what I decided to go with for the moment. Unfortunately, it turns out that Windows doesn't let you control buffering if you're redirecting standard output
|
# ? Oct 31, 2011 17:10 |
|
I'm not sure if this would be better placed in the web development questions thread, but here goes. I have a website in ASP.NET using MVC with a secure login system. What I now need is a good way to give the users file downloads, but obfuscate or limit the file URL so users can't just give the file location away to their friends. (Our site is only available to paid customers) What would be the best way to do this? I imagine passing a file id to a controller and then having the download popup would be the best route. But I wanted to ask in case I'm overlooking something important.
|
# ? Oct 31, 2011 20:06 |
|
When I had to do something like that, I generated a record keyed with a Guid indicating the target file on a downloads table. Their link would go to a page "downloads.aspx?id={guid}", which would then respond with the file contents. When the file finished transferring, download.aspx would update the record to indicate it had been downloaded. I had the logic such that a link would be good like 5 times in case they had issues downloading or misplaced the file. After it had been downloaded that number of times, or if a week had passed since the record had been created, the downloads.aspx would instead redirect them to a page stating that the link was no longer good. It's a pretty easy problem to solve if you couple it with a database. Dietrich fucked around with this message at 21:05 on Oct 31, 2011 |
# ? Oct 31, 2011 21:03 |
|
BUGS OF SPRING posted:I'm not sure if this would be better placed in the web development questions thread, but here goes. Ah you could always handle the file with session variables or post data.
|
# ? Oct 31, 2011 21:40 |
|
In managed C++, if I take a pin_ptr<> of a class member, does that prevent the entire class from being moved by the garbage collector (as long as the pin_ptr<> is in scope)?
|
# ? Oct 31, 2011 21:42 |
|
dwazegek posted:In managed C++, if I take a pin_ptr<> of a class member, does that prevent the entire class from being moved by the garbage collector (as long as the pin_ptr<> is in scope)? According to msdn quote:Pinning a sub-object defined in a managed object has the effect of pinning the entire object.
|
# ? Oct 31, 2011 21:46 |
|
Sedro posted:According to msdn Ugh, don't read documentation on Friday and then expect to remember all of it on Monday. Anyway, thanks, looks like I have a few changes to make.
|
# ? Oct 31, 2011 21:55 |
|
What are some existing systems in place for exchanging arbitrary objects defined at run-time potentially between threads or even processes using .NET? I'm thinking of something almost like some global Dictionary of string keys to objects as a starter. It would be nice if the object would be updated in the store the moment something in it was changed. For a starter I was going to serialize a bunch of stuff to a known spot on disk, but I see that getting obnoxious quick, and it also doesn't convey changes until the object gets stored again. I'd think basically an object-based database or something would work for this, but I am not really familiar with them, let alone getting them up and running with .NET and C# code.
|
# ? Oct 31, 2011 23:17 |
|
There are huge performance implications at each level of separation (ie. HTTP vs. inter-thread communication). I don't know of anything that abstracts it all away. Communicating between AppDomains: MAF is the only thing I know of Communicating between processes: WFC over named pipe Communicating between physical machines: WCF over TCP, HTTP, SOAP, etc. There are plenty of ways to communicate between threads. If you want a dictionary, ConcurrentDictionary is a nice thread-safe dictionary with no mutex locking.
|
# ? Nov 1, 2011 01:38 |
|
Rocko Bonaparte posted:What are some existing systems in place for exchanging arbitrary objects defined at run-time potentially between threads or even processes using .NET?. It would be nice if the object would be updated in the store the moment something in it was changed. Think hard before designing around the bit in bold. The best, cleanest, lowest bug-count, most robust, scalable, performant way to share data across thread/process boundaries is with IMMUTABLE data. A great way to get into the "immutable" mindset is with the F# language in VS2010. This language guides you into the pit-of-success by making it easier to write immutable data than mutable. You'll get the hang of it within a week of F# coding. It's possible, by changing your mindset, to forge ahead with immutability even in the unlikeliest places. For instance, you'd think that console/UI input and output is the most mutating thing there is -- but the Haskell language manages to do them in a completely immutable way! Let the mutation happen only at rare well-defined boundaries, e.g. you can expect the records in a database to mutate. But don't let that infect much of your own code. The C#/VB team had to wrestle with how to represent the parse-tree of source code in the editor window to plugins. The problem is that the parse-tree can be modified by the user, and the plug-ins run in different threads or processes. The solution we used was to give each plugin an immutable snapshot of the tree at a given moment in time. (Obviously, when the plugin wants to call an API to update the source code, it needs to check whether its snapshot is still current.)
|
# ? Nov 1, 2011 04:58 |
|
|
# ? Apr 26, 2024 22:23 |
|
I need a sounding board for an idea I had. I'm doing some SalesForce querying, and the result set, if larger than the batch size will be chunked by salesforce into batches, if there are more results than in the current set, it gives you a locator to start the next. What I was thinking was if I could create a collection that served as the front end to a collection of batches, iterating through each one as it was completed, instead of blocking the entire result set until it was sucked down. The idea would be to return an IEnumerable<T> that was really an IDictionary<int, TBatch> , where TBatch would be code:
Overly complicated? Already exists as something and I don't know it? Terrible idea that won't be the gain I think it is? I'm all ears.
|
# ? Nov 1, 2011 05:04 |