Something like this?:pre:static T[] Foo<T>(params T[] c) { var ret = new List<T>(); foreach (var obj in c) { ret.Add(obj); } return ret.ToArray(); }
|
|
# ? Jun 26, 2019 17:52 |
|
|
# ? Jun 8, 2024 05:40 |
|
if I use a generic, doesn't that mean I have the type at compile time? Can I pass a type deduced from reflection into a generic?
|
# ? Jun 26, 2019 18:26 |
|
Your are looking for Array.CreateInstance. https://docs.microsoft.com/en-us/dotnet/api/system.array.createinstance?view=netframework-4.8
|
# ? Jun 26, 2019 19:18 |
|
Rocko Bonaparte posted:How can I use reflection in C# to create an array (as in T[], not Array)? All I've found involves an explicit cast, but I don't necessarily know the type. Using reflection is, in general, a code smell. What are you trying to accomplish? Why can't you use an interface to accomplish it?
|
# ? Jun 26, 2019 19:34 |
|
New Yorp New Yorp posted:Using reflection is, in general, a code smell. What are you trying to accomplish? Why can't you use an interface to accomplish it? I'm working on a cooperatively-multithreaded Python interpreter and I'm having to shepherd parameters coming from the interpreter into embedded .net functions. The list is the parameters as recovered from the interpreter stack to pass into CALL_FUNCTION. The function that exposed this problem is the internal equivalent of Python's __build_class__, which is the first one I've had to implement using *args. The .net equivalent is params, so my .NET implementation of __build_class__ is using a signature that includes params to accept the *args. I'm nowhere near implementing the full language spec here but I do need subclassing and those do come in as 0+ optional parameters to __build_class__ in the wild so I'm trying to honor that convention from CPython as much as possible. I'm doing a lot of this particularly for some tweaks to do coroutines. No, IronPython cannot do that and I did poke it with a stick first. FrantzX posted:Your are looking for Array.CreateInstance. Edit: Actually I'm looking this up more and isn't that kind of strange? Is Array actually what the base array type is anyways? Rocko Bonaparte fucked around with this message at 20:56 on Jun 26, 2019 |
# ? Jun 26, 2019 20:42 |
|
Rocko Bonaparte posted:That's what I tried to use yesterday when I first was searching about this. There was a Stack Overflow discussion about it that ended with the same problem I had. How do I cast that to an actual [] array? MethodInvoke is refusing to accept the Array data type as an acceptable argument to a params parameter. The people there told the OP to just cast to T[], but that only works if you know T statically. mystes fucked around with this message at 22:32 on Jun 26, 2019 |
# ? Jun 26, 2019 22:28 |
|
Actually I think Array.CreateInstance is fine. I think in last night's shenanigans that I had some detritus make it into the parameters and it was choking on that instead of that particular array. I rearranged it and I can see myself making it into the function now with the right stuff going into the params field.
|
# ? Jun 26, 2019 22:31 |
|
Can someone explain the stupid "type or namespace name 'ProfileCommon' could not be found" error to me? StackOverflow's answers are all exceptionally smug even by their standards and full of dead links that would have supposedly explained what's going on. All I know is I made a Web Application in VS2017 (because web site isn't a frigging option any more), and if I copy the raw files to the web server it works, but if I publish it first I get that dumb error. What's it bitching about and what do I need to stick in where to make it shut up?
|
# ? Jul 8, 2019 17:43 |
|
You've probably read this then but it seems pretty straightforward: https://stackoverflow.com/questions/11073973/the-type-or-namespace-name-profilecommon-could-not-be-found Basically the default project creates a config profile out of the box that doesn't get deployed to server as part of publish. The guys in the question above add some Using directives and the last one just stubs out the class so it doesn't complain about it.
|
# ? Jul 8, 2019 19:44 |
|
Scaramouche posted:You've probably read this then but it seems pretty straightforward: I still don't love that apparently that was straightforward to you, though, because it kept making my eyes cross and that means I've got a gap in my knowledge somewhere.
|
# ? Jul 8, 2019 23:14 |
|
Yeah it's kind of a weird area because it's not really code thing like "x = !(thing) ? 1 : 2;" but instead is kind of a Microsoft head file/project housekeeping thing. That yes, the entity defined in the default project does need to be hooked up some way or somehow worked around, but it doesn't really get taught/learned the same way programming concepts do.
|
# ? Jul 9, 2019 00:08 |
|
Any WPF/XAML experts? I have a toggle button (more exactly a Telerik RadRibbonToggleButton) and when it is checked it turns a really strong shade of blue, the same colour as the window's title bar. I don't like this. I want to be able to control what shade of blue it turns when checked. I have completely failed to find a way to do this. I tried setting the Background property of the button; it works as long as the button isn't checked, but gets ignored when the button is checked - it turns the same shade of blue. I tried modifying the Style in the XAML file so that it sets the Background property and has a trigger to set the Background differently when the button "IsChecked". Predictably, this also did not work. I saw a StackOverflow post that suggested changing the Template that applies to toggle buttons. I tried doing that and it just hosed up all the toggle buttons so that the icons don't display, which is obviously no good. I have non-toggle Buttons on this Ribbon whose background colour I can control. I could therefore achieve what I want to do by changing the toggle buttons into normal Buttons and setting the background on them by binding to properties, but this seems like hacking around my own lack of understanding.
|
# ? Jul 11, 2019 12:05 |
|
Hammerite posted:Any WPF/XAML experts? I have a toggle button (more exactly a Telerik RadRibbonToggleButton) and when it is checked it turns a really strong shade of blue, the same colour as the window's title bar. I don't like this. Wild guess: have you changed your machine's desktop color theme, and does changing it affect how the toggle button looks when it's enabled? I've used some apps where buttons and other ui elements turn pink to match my ridiculous color theme. Not that "change your theme" is a practical workaround, but it might explain why it's not responding to the things you've tried changing so far.
|
# ? Jul 11, 2019 12:25 |
|
Careful Drums posted:Wild guess: have you changed your machine's desktop color theme, and does changing it affect how the toggle button looks when it's enabled? I've used some apps where buttons and other ui elements turn pink to match my ridiculous color theme. I haven't changed the machine's desktop color scheme to my knowledge. I just tried opening up the "themes and related settings" widget and selecting a different colour. It caused the taskbar and various window title bars to change color, but nothing changed about the app I'm working on, even after I closed and reopened it.
|
# ? Jul 11, 2019 12:46 |
|
Hammerite posted:Any WPF/XAML experts? I have a toggle button (more exactly a Telerik RadRibbonToggleButton) and when it is checked it turns a really strong shade of blue, the same colour as the window's title bar. I don't like this. I want to be able to control what shade of blue it turns when checked. I have completely failed to find a way to do this. I tried setting the Background property of the button; it works as long as the button isn't checked, but gets ignored when the button is checked - it turns the same shade of blue. I tried modifying the Style in the XAML file so that it sets the Background property and has a trigger to set the Background differently when the button "IsChecked". Predictably, this also did not work. I saw a StackOverflow post that suggested changing the Template that applies to toggle buttons. I tried doing that and it just hosed up all the toggle buttons so that the icons don't display, which is obviously no good. I think you need to figure out what specific hook Telerik has given you to do this. Hopefully one exists. For my own content: I found a static initializer that uses HttpContext.Current today. I’d post in the coding horror thread but I don’t think they’d get it.
|
# ? Jul 11, 2019 19:45 |
|
Hammerite posted:Any WPF/XAML experts? I have a toggle button (more exactly a Telerik RadRibbonToggleButton) and when it is checked it turns a really strong shade of blue, the same colour as the window's title bar. I don't like this. I want to be able to control what shade of blue it turns when checked. I have completely failed to find a way to do this. I tried setting the Background property of the button; it works as long as the button isn't checked, but gets ignored when the button is checked - it turns the same shade of blue. I tried modifying the Style in the XAML file so that it sets the Background property and has a trigger to set the Background differently when the button "IsChecked". Predictably, this also did not work. I saw a StackOverflow post that suggested changing the Template that applies to toggle buttons. I tried doing that and it just hosed up all the toggle buttons so that the icons don't display, which is obviously no good. https://docs.telerik.com/devtools/wpf/controls/radribbonview/styling-and-appearance/styling-ribbontogglebutton RadRibbonToggleButton is just an extension of this, so the same stuff may apply?
|
# ? Jul 12, 2019 19:35 |
|
Hopefully this makes sense... I'm developing a fun project in C# using Rider/MacOS/.Net Core 2.2. It's a lot of fun and Rider is fantastic. I'm to the point to where I need to start writing some fairly complex linq queries and I'd like to test these out on a scratch pad similar to the experience LinqPad gave back in the .NET 4.5.x days. I noticed Rider has a "Scratches" section but I'm either missing something or just not 'getting it' - does anyone know how I could do something similar to this using Rider?
|
# ? Jul 14, 2019 21:23 |
|
karma_coma posted:Hopefully this makes sense... I know rider has LINQ support in its recommendation engine. I usually just write my really dumb loops and press alt+enter a couple times.
|
# ? Jul 14, 2019 21:57 |
|
karma_coma posted:Hopefully this makes sense... For windows... Write code in a .cs file, right click the file in Solution Explorer and click "Execute in Interactive" https://dailydotnettips.com/use-c-interactive-window-for-your-coding-experiment-in-visual-studio-2015/ Funking Giblet fucked around with this message at 22:08 on Jul 14, 2019 |
# ? Jul 14, 2019 22:06 |
|
leper khan posted:I know rider has LINQ support in its recommendation engine. I usually just write my really dumb loops and press alt+enter a couple times. Hahaha, this is what i've been doing Rider/Resharper suggestions are fantastic. I was kind of hoping there was an easier way ... I remember defining your Db in LinqPad and then being able to go to town on writing some queries but I may be wrong about how much set up was required. Thanks for the suggestions guys
|
# ? Jul 14, 2019 22:16 |
|
C# interactive should be cross-platform tooling. Even if Rider doesn't have a specific window for it, you should be able to launch csi.exe from the command line. Save a .csx script that loads up your database, then run queries in the CLI.
|
# ? Jul 14, 2019 22:44 |
|
NihilCredo posted:C# interactive should be cross-platform tooling. Even if Rider doesn't have a specific window for it, you should be able to launch csi.exe from the command line. It does, and this is exactly what I needed. Thanks a million, this solved what I was after.
|
# ? Jul 15, 2019 00:25 |
|
Hammerite posted:Any WPF/XAML experts? I have a toggle button (more exactly a Telerik RadRibbonToggleButton) and when it is checked it turns a really strong shade of blue, the same colour as the window's title bar. I don't like this. I want to be able to control what shade of blue it turns when checked. I have completely failed to find a way to do this. I tried setting the Background property of the button; it works as long as the button isn't checked, but gets ignored when the button is checked - it turns the same shade of blue. I tried modifying the Style in the XAML file so that it sets the Background property and has a trigger to set the Background differently when the button "IsChecked". Predictably, this also did not work. I saw a StackOverflow post that suggested changing the Template that applies to toggle buttons. I tried doing that and it just hosed up all the toggle buttons so that the icons don't display, which is obviously no good.
|
# ? Jul 15, 2019 05:53 |
I have two WPF (.NET Framework 4.5) applications. I'd like to make a sort of soft integration between them: If both are installed, one can detect the other is installed, and offer to send a message to the other. If the other is already running, the message is sent to the existing instance, otherwise start a new instance. This sounds very similar to what an out-of-process COM server can do, but it seems that pattern is not well supported by .NET Framework. Any suggestions for other technologies to look at, or should I just do something "stupid" with Win32 messages, named pipes, or similar?
|
|
# ? Jul 17, 2019 13:44 |
|
Cuntpunch posted:https://docs.telerik.com/devtools/wpf/controls/radribbonview/styling-and-appearance/styling-ribbontogglebutton RadRibbonToggleButton is just an extension of this, so the same stuff may apply? NoDamage posted:Telerik has its own set of themes which have custom styles defined for all of their widgets (and also style overrides for all of the system widgets). What theme do you have set up for Telerik? Essentially what you'll need to do is create a custom style that inherits from the default RadRibbonToggleButtonStyle and then override the appropriate properties for the checked state, and/or possibly override the control template as well, but the specifics will depend on exactly which theme you're using. Thanks for the tips. I can see I need to get a better understanding of how Telerik's styles work if I want to take this any further.
|
# ? Jul 17, 2019 14:12 |
|
nielsm posted:I have two WPF (.NET Framework 4.5) applications. I'd like to make a sort of soft integration between them: If both are installed, one can detect the other is installed, and offer to send a message to the other. If the other is already running, the message is sent to the existing instance, otherwise start a new instance. This might be useful: http://blogs.microsoft.co.il/arik/2010/05/28/wpf-single-instance-application/
|
# ? Jul 17, 2019 14:20 |
|
Hammerite posted:This might be useful: To the original question: this is kind of a tangent answer, that mostly worries about using mutex's to ensure that an app only runs once. (It also uses Remoting, so it won't be portable to .NET Core) In terms of cross-process communication like that, you've got a couple of problems to solve: -Identifying that the other product is installed -Talking to it In terms of identification - are these both in-house applications with well-known identities? In terms of going 'hey, is this installed?' that sounds a lot like a problem for just peeking at the registry(either for your own key, or Windows's own install list) and/or filesystem. In terms of talking to it, how robust of a communication protocol do you need? Does the other process need to send responses? Named pipes have pretty clean support in .NET and are simple enough to get going. Do you NEED a super-fancy solution like a middleman service? But back to that link: I've only skimmed it a bit, but what's all the ceremony about? Is there some ultra-harmful thing in the direct solution of 'check for existing Mutex, exit out immediately if it exists, otherwise create it'?
|
# ? Jul 17, 2019 15:01 |
|
Cuntpunch posted:To the original question: this is kind of a tangent answer, that mostly worries about using mutex's to ensure that an app only runs once. (It also uses Remoting, so it won't be portable to .NET Core) I can't comment on how it compares to your suggestion of using a Mutex because I haven't tried my hand at implementing that. Looking at relevant questions on StackOverflow, it appears that there are a lot of details to get right if you do go down that route: https://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c/229567 The reason I posted it is that nielsm specifically mentioned the need to handle messages in an existing instance of the application or start a new instance, depending on whether an instance exists - and I knew that this code supports that use case, because we use this approach in an application I was involved in developing last year that does exactly that.
|
# ? Jul 17, 2019 15:21 |
Yes both are in-house applications. It would be a UI nightmare to properly combine them, but reasonably simple to add some basic "send this item to the other app" UI. I looked at the class in that blog post, and it does look like an overly specialized solution for people who don't want to understand what IPC is, but the IpcChannel class it uses seems useful as a way to send structured messages.
|
|
# ? Jul 17, 2019 15:22 |
|
nielsm posted:Yes both are in-house applications. It would be a UI nightmare to properly combine them, but reasonably simple to add some basic "send this item to the other app" UI. What I've seen done, looking at something like Quixel bridge that sends data to other apps, is to have an application listen on a port and just send stuff over the network. This won't start a new instance though.
|
# ? Jul 17, 2019 16:00 |
|
Hammerite posted:I can't comment on how it compares to your suggestion of using a Mutex because I haven't tried my hand at implementing that. Looking at relevant questions on StackOverflow, it appears that there are a lot of details to get right if you do go down that route: https://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c/229567 In doing some more peeking at it, it looks like the 'big' problem this solves is less about the described problem - 'how do I ensure only a single instance' - and more one of 'if (x) is running and someone attempts to start a new process, with args, then make sure that the second process terminates early, but that the args it received are sent to the running instance for handling'. The SO post has some information, but is also a little bit in the weeds on some edge cases that the directly stated use case doesn't involve (what happens if two users on the same machine try to run the same 'single-instance' app?) - but even that still somewhat seems predicated upon a use *as a Mutex*. Where you're using this as a synchronization object, rather than simply as a system level flag of 'this application is running'. In that simplified case, is there really a harm in Mutex.TryOpenExisting?
|
# ? Jul 18, 2019 08:12 |
Win32/NT kernel mutex objects can be created as either system global or session local, by adding a Global\ or Local\ prefix to the mutex name. I don't know how well that translates to .NET Framework. A session local mutex will only be visible in the logon session that created it. I'm surprised .NET does not have a good (and easy) local RPC mechanism.
|
|
# ? Jul 18, 2019 08:31 |
|
Does anyone have any recommendations for a complete novice's guide to learning C#? I've gotten a DevOps job that didn't run into the infuriating problem of "Oh you need 3+ years of coding experience for us to even consider you, gently caress off", they're willing to let me get up to speed, but I need to start practicing / hitting the books yesterday. I was a comp science major for a semester many moons ago (2001 or so), I know the very basics of C++ still, I can cobble together BASH and Python scripts OKish... so yeah, figured I'd ask for recommendations in here. But the fact that I've been a Linux admin for 12 years, they're Azure, and they gave me a 4' wide desk "just for now" already has Star Trek klaxons ringing in my head... but I digress.
|
# ? Jul 18, 2019 21:08 |
This was my favorite site starting out. https://www.dotnetperls.com/
|
|
# ? Jul 18, 2019 22:50 |
|
CHEF!!! posted:I've been a Linux admin for 12 years, they're Azure I don't see how their choice of cloud platform relates to your sysadmin experience.
|
# ? Jul 18, 2019 23:29 |
|
New Yorp New Yorp posted:I don't see how their choice of cloud platform relates to your sysadmin experience. Well if they are running Windows VMs I could see it matter to them. I don't know how that is weird.
|
# ? Jul 19, 2019 07:39 |
|
Mr Shiny Pants posted:Well if they are running Windows VMs I could see it matter to them. I don't know how that is weird. Azure is platform neutral. You can have an entire Linux cloud in Azure.
|
# ? Jul 19, 2019 11:02 |
|
Cuntpunch posted:Azure is platform neutral. You can have an entire Linux cloud in Azure. New Yorp New Yorp posted:I don't see how their choice of cloud platform relates to your sysadmin experience. Sorry, should have been more specific about this. They chose Azure because of the MS licensing savings, Linux seems to be a curiosity to them, and I pray I am wrong about the latter. I also failed to mention I've used AWS for 6 years and my Azure experience is personal level tinkering so to say I'm in "oh poo poo oh poo poo must catch up" mode right now is like saying water is wet. Thanks for the recommendation, Polio Vax Scene. CHEF!!! fucked around with this message at 11:52 on Jul 19, 2019 |
# ? Jul 19, 2019 11:48 |
|
CHEF!!! posted:Sorry, should have been more specific about this. They chose Azure because of the MS licensing savings, Linux seems to be a curiosity to them, and I pray I am wrong about the latter. I also failed to mention I've used AWS for 6 years and my Azure experience is personal level tinkering so to say I'm in "oh poo poo oh poo poo must catch up" mode right now is like saying water is wet. Hopefully they're in the process of modernizing things or you'll have the ability to influence the direction they head going forward, because these days it's all about PaaS applications and containers. In a lot of cases, the base OS that applications run on is simply not relevant on a day to day basis. If they're stuck in a mindset of "we must manage our own Windows VMs" then yeah, that's going to suck. But the tooling for that is largely platform agnostic unless they've gone the desired state configuration route.
|
# ? Jul 19, 2019 19:52 |
|
|
# ? Jun 8, 2024 05:40 |
|
Cuntpunch posted:Azure is platform neutral. You can have an entire Linux cloud in Azure. That is why I said "if they are running Windows VMs".
|
# ? Jul 20, 2019 09:55 |