« first day (1380 days earlier)      last day (3570 days later) » 

5:01 AM
@Greg Hi
@Code-Apprentice ? are u here?
 
 
10 hours later…
2:59 PM
how do you guys organize your Extension Methods? I used to lump them into a big class, but lately I have been dividing them up. General ones go in the bucket class, but I have been putting the ones based on an interface (for mixins) into a static class in the same location. For example for IFoo I would have an ExtensionsForIFoo class in the same folder
Also, if I have a number of related extensions to solve a single problem, I'll pull them out into their own class as well. for example, several different string extensions for fuzzy matching would go into a FuzzyMatchingExtensions class
and does anyone have a separate project for general extensions that the include in their other projects?
just trying to un-deadify the chat since no one has talked in 10 hours
 
I don't have a strategy but have a couple ClassNameEx classes
 
@DreadPiratePeter What would you classify as "general ones"?
I find they can usually be grouped logically. I tend to have a "ReflectionExtensions" class with various shortcuts and utilities. "StringExtensions" is also common.
And I don't put them in their own projects, I usually put them in the MyProject.Common or MyProject.Shared project that already exists with shared code.
 
3:16 PM
yeah, I could do it by type. General ones are those I would use in a lot of projects. like:
public static bool In<T>(this T val, params T[] values)
{
      return values.Contains(val);
}
 
Yeah, I've written that one three or four times before, too. :)
(I work as a consultant and contractor, so I skip between many projects, but the code usually belongs to the client, so I find myself rewriting basic things like this a lot).
I might at some point put up a Github project with a lot of code I reuse, and convince the clients to let me use it in the project.
 
public static String WithSign(this int i)
{
    if (i >= 0) return "+" + i;
        return i.ToString();
}
do the github under an alias so you can use it as third party stuff ;)
 
I guess there ought to be a distinction between extension methods that are helpers for a specific domain, and extensions that really are general-purpose
and if they're general purpose, why not make them methods of the classes they operate on? If you can
 
In this case I'd put In<T> in a ListExtensions or CollectionExtensions.
 
yeah, I might start doing that my general extension bucket is getting pretty big
 
3:20 PM
I don't think I've ever had more the 7-8 methods in an extension class, and they're usually 2-3 line functions anyway.
If I have enough code to fit more than a screen or so, I'd probably split them.
 
For my current project (roguelike) I have a set of really nifty extensions to pull random items out of any enumerable. including a nice weighted one
 
Also, I don't see myself using the WithSign method. I'd probably let the UI layer do the formatting.
@DreadPiratePeter Yeah, that's a useful one. I've used that for unit testing and automatic test data generation.
 
I have really complex formatting needs for the roguelike, so I do it in the back end.
 
Well, if you're doing ASCII graphics, ToString is your UI layer. :)
 
actually its WPF and my entire UI is one ListView
 
3:24 PM
Although this might be doable by defining a custom UI culture and have it automatically format the way you want.
 
wwell, actually ItemsControl
 
I never tried writing a game with WPF. How's it working out for you?
 
everything just flows beautifully
 
3:29 PM
Can you take a look at this question: stackoverflow.com/questions/24982178/…
 
@KeremZaman It's not a C# question, is it? You should probably try in the SQL Server room. If there is one.
In fact, it's probably not even a good question for StackOverflow. Maybe SuperUser or ServerFault would be better for installing MSSQL and recovering a database.
 
@AvnerShahar-Kashtan What is SuperUser and ServerFault ?
 
@KeremZaman SuperUser.com and ServerFault.com - two sister-sites of Stack Overflow. The first targeted at computer enthusiasts and power users, the second for server administrators.
Actually, it seems there's even a Database Administrators site, which might be even more on-topic: dba.stackexchange.com
 
oh, thanks a lot @AvnerShahar-Kashtan
 
You're welcome.
 
3:47 PM
I have a quick question. I am trying to write a cross-cutting type of interface called ICharged, that works as a mix-in on my different object types. I wanted to implement UseCharge() as an extension on the ICharged interface as in 90% of the cases it is implemented exactly the same and I don't want to have to duplicate the code in all my classes that implement it, or make a bunch of base classes, like ChargedWeapon, ChargedGloves, etc since I already have a hierarchy.
If I want a particular class to do the charges a little differently can I just implement a concret method? I am thinking not, since it is not in the ICharged interface. Would I have to make a second static method for that class? I would think that that wouldn't work either.
if I was using a IFoo reference i would think it would use the IFoo method, not the DerivedFromFoo method
 
Depends on what you mean by "do things a little differently".
 
actually, UseCharge is a bad example
 
We have a similar patter for logging - a class implements ILoggable, and an extension method for ILoggable writes to the log.
 
a better example is OnAllChargesUsed() I want a default implementation that does nothing so that for the 90% of the charged items that don't care about that I don't have to implement an empty method, but for the 10% that do I can
 
If the extension method needs to be tweaked by the concrete class, you can add a concrete method to the interface - CustomLoggingAction(), for instance - and have the extension method call it, and call the default implementation otherwise.
Oh, ok. You don't want empty implementations.
 
3:53 PM
but then every class would have to implement CustomLoggingAction() defeating the purpose
I could put an empty OnAllChargesUsed extension method in, but I don't know how I would overload that
there is always reflection, but I don't wan't to put a bottleneck in for what is in essence a convenience
I suppose I could put in a second IChargedListener interface and check if the object implements it before calling the On... methods
that actually might be the cleanest
then only the objects that care have to implement anything
 
4:35 PM
Hello guys. I have url address to .svc file that should represent WebService. Does anyone of you have experience how to use it in Visual Studio projects?
 
you want to write a client?
 
@Marek Generally you would add a Service Reference, which will automatically create local proxy code in your project for the service.
 
what he said
 
@AvnerShahar-Kashtan That is exactly what I have tried but it haven't found any webservice on that address.
 
try ?wsdl on the end
 
4:44 PM
@DreadPiratePeter I tried that too but it still haven't found any WS: vrep1-t.cssz.cz/VREP/ws/public.svc
 
if that doesn't work try hitting it in a browser and make sure that you can see it and aren't getting cert errors and such. And try telneting to the url and port and see if you get a handshake
ah, they have the wsdls turned off. you would need to get them to turn them on or send you a wsdl to use
otherwise you are an inclined-plane twisted around a post
 
Indeed. For VS to generate the code, it needs to know all about the service's interface, and the service currently explicitly says it doesn't publish it:
> Metadata publishing for this service is currently disabled.
Either the service publishers need to give you a wsdl (either manually or be exposing it through the service), or give you a DLL with the client classes.
 
A thought on my earlier problem with the mixins. I think the better solution is to implement the On... methods as events. That essentially what they are and even though in my usage case here, my object would be sending events to itself, it means only interested derived classes need to care, they can care conditionally at runtime, and it opens up a lot of cool other possibilities
 
Well its govt's WS.. I should better contact them.
 
such as an item that randomly charges one of your chargable items anytime you use a charge on an item
or a mage class that gets spellpoints back anytime you use a charged item
 
4:53 PM
@Marek In that case, there might be full WSDL hidden in the documentation somewher.e
@DreadPiratePeter That might be a problem, since if the event is launched by the extension method, you're effectively defining an event on a static class.
Or is the event defined in the IChargeable?
 
crap. foiled again
I really wish C# had real mixins. It would be so sweet
if I define the event in ICharagable I have to implement it everywhere
 
That's not so terrible, you know.
 
I could just say screw it and implement the whole thing as a postsharp attribute
 
Going back to the empty implementations of CustomChargingAction. You add it to the interface, have an empty implementation in most places, it takes up 3 more lines of code and that's it.
 
I don't like that 3 lines of code all over the place, it find it clutters things up.
 
4:58 PM
So we're back to two interfaces. The empty IChargeable and the optional ICustomChargeable.
 
maybe [ChargedItem] in postsharp gets me all I need.
 
Which inherits IChargeable.
 
@DreadPiratePeter Define a smaller interface?
 
Then you go public static void Charge (this IChargeable item) { if (item is ICustomChargeable) { (item as ICustomChargeable).CustomCharge();} else { /* do default charging */};}
Not too elegant, but saves a lot of code.
 
yeah, that is how I am going to do it.
 
5:02 PM
Going back to our earlier extension-method talk, I defined an As<T>() method which basically does a cast with fewer parentheses. item.As<ICustomChargeable>().CustomCharge().
With C#6.0's safe null navigation, it could be even more useful.
 
nice, thanks
gonna go with that. if I decide later I need the events then I can bite the bullet and implement the event in every ICharged implmenetation
It's a pleasure to be working with proper villains again
the people at my day job wouldn't understand the problem, let alone the solution
 
Yeah, I know the feeling. :)
I bounce around. My current project is actually filled with really OK people, who don't flinch at aspects and extensions-based architecture.
My previous project was with people who were, for the most part, still writing C++ in VS2005, and had ventured to try one little part of their system in .NET.
So they spent most of their time re-implementing in C# what they already had working in C++ - which was out of date and simplistic for C++, and entirely unnecessary for C#.
 
5:26 PM
most of our work these days (outside of my part) is done by bottom of the barrel offshore consultants
they are pretty much writing C in C#, minus the memory managment
no linq, so many for loops. I just want to cry
 
6:17 PM
woot! ICharged and IChargedListener implemented and working! thanks again folks. next up, basic combat
 

« first day (1380 days earlier)      last day (3570 days later) »