« first day (1755 days earlier)      last day (3194 days later) » 

12:11 AM
@Pheonixblade9, good luck on your interviews! I'm hunting too
 
@KalaJ thanks :)
 
12:33 AM
Would you guys ever put remote work over salary + benefits?
 
@KalaJ sometimes, I plan on doing remote/stay at home mom when we have kids.
 
hmm I see
 
I prefer to work in the office though, because I have a tendency to get distracted when I remote.
 
okay gotcha
 
1:06 AM
@CuddleBunny stay-at-home-dev-dad is the dream
 
I should quit and get a job at Netflix before that happens <3
 
Anyone worked with RelativePanel yet?
 
@DemCodeLines not much, but I love it.
 
Is it possible to have two buttons, align next to each other on the right side of the parent.
 
yeah, sec let me refresh myself.
@DemCodeLines I don't have VS handy, but could you do RelativePanel.AlignRightWithPanel on one element and leftof on the other?
 
1:22 AM
Apparently I forgot that leftOf exists, thanks a lot hehe
 
np
I love it so much I was planning on recreating it in HTML
 
 
1 hour later…
2:54 AM
Following an old tutorial and getting this: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See go.microsoft.com/fwlink/?LinkId=260882 for more information.
I'm using MVC 5 instead of MVC 3 when this was published, could EF have changed since then? asp.net/mvc/overview/older-versions/mvc-music-store/…
 
3:16 AM
@KalaJ Use localdb instead of SQL CE?
 
that could work, what's the syntax for the connection string?
 
I think the tooling for SQL CE fell behind and it doesn't work very well with VS. Not sure if EF still supports it either.
You can still use it if you configure everything right but I've heard it is tricky.
 
Awesome thank you
 
 
2 hours later…
5:48 AM
el bueno morningo
 
@BenjaminDiele El bueno noche.
 
It's 7:53. That's morning yo!
 
Iepse piepse!
 
6:07 AM
Mornings!
 
6:28 AM
@Loetn That's almomst my cat's name :D
 
Morning !
 
@BenjaminDiele What's your cat's name then?
 
So its still one more day to go for the weekend... & i am stuck with Sqlite-Entity Framework Issue ..
 
@bhuvin Two days here :(
 
ahh man .. !
 
6:32 AM
@Loetn Piep :D
 
And that means kitty or something?
:p
 
@scheien Doesn't mean shit :p
@BenjaminDiele Ok, from now on, I will greet you every morning with 'piep'.
 
hehe
 
LET IT BE KNOWN TO MANKIND!
 
FUCK YEAH!
 
6:34 AM
:)
 
guys any idea : I am facing a really stupid issue :
I have a Password protected Sqlite database - Entity Framework pair ...
Now this works really weird randomly, I am fetching data based on a Primary key , and its right there still Entity Framework just is Adamant saying its not there ...
 
@scheien Nah, it's like when you see a kid or small animal, that looks through the fingers or such, "peeping".
 
Remove the Password : Poooffff ! Works great !
 
@BenjaminDiele: aha
 
@BenjaminDiele Ooh yeah, If you look at it that way :)
 
6:37 AM
guys any idea ?
 
@bhuvin What's not there?
 
Its like:
Select * from Table where id = 10;
The record : with id = 10 is already there into the Database
but Entity framework doesnt return the same ..
 
7:00 AM
morning guys
wsup @bhuvin
Need some advice
 
I want to develop a mobile app that will have a sharepoint backend
I have 0 experience in mobile app devs
 
@bhuvin But EF returns something?
 
so am trying to determine which is the easiest path to take
cordova apps
or windows universal app
 
Easiest for you? Windows Universal apps. But you won't have an app for iOS/Android/Firefox/Tizen/... like that. Best investment? Cordova, hands down.
 
7:15 AM
@RoelvanUden I will need to ease in.There is someone handling the android version so am not worried.That would leave iOS
Cordova looks like I would need a lot of time to learn those js libs
 
If you bundle efforts on a Cordova app you can make one single app for each platform, which reduces effort and maintenance costs, and reduces number of skill sets required (It's just web, not C#, Java or Objectice-C/Swift)
You would need to know/learn HTML/CSS/JS, yes. Skills that can then be applied to every platform and every future project, web or mobile app, for your entire lifetime.
 
that is a strong point you have there Roel
 
@Gotalove : hey ..
@Loetn : Nope .. Null value ..
 
Of course. I'm a modern day genius (and I will get recognition after I die).
3
:P
 
haha you already have my respect
 
7:20 AM
i guess dat could be backed by the SO Fraternity .. Kudos @RoelvanUden !
 
any idea how long an average joe would take to build a simple crud cordova app
 
Hello guys
 
@Gotalove What skills do you currently have (HTML/CSS/JS)?
 
Can someone answer a question for me? Should I use flat file or MySQL? or are there any other things for database (I am looking for speed)...
 
basic website jquery html css skills
 
7:24 AM
@AshSimpson Depends on what you want to save, I guess
 
@AshSimpson PostgreSQL is much faster than MySQL. Otherwise it depends on the characteristics of the database you're looking for.
 
What's monodb like? is that fast..
 
@Gotalove I expect around a week to get up to speed with modern MVVM techniques like Knockout or Angular, then an additional week to create functionality, and a few days to style it.
@AshSimpson Fast and unpredictable. May or may not save your data (eventually)
 
@AshSimpson Depends a lot on your data - what are you storing, and how much of it are you storing? Do you need to read everything, or perform common queries.
 
I need to read everything at the start up, and do common querys during the programs time being open. I don't have that many tables, 200 MAX and no more than 100 records in them (Except for 3 or 4 tables that will have around 4k MAX in them) and also the users table which might exceed to 100 - 200 k
 
7:27 AM
@RoelvanUden : Its dis issue which is maddening me .. :
without Password on Sqlite Database the App is working very fine ..
With Password : The Data is there into Database , but the Entity Framework while querying fails to fetch the same i.e.
Select * from Table where id = 11

When we do this into DB it gives the record , on Entity Framework it returns Null
Or sometimes it just fails to add the Data ...
 
Hi
 
Hi @jignesh !
 
@jignesh, Hi
 
Can anyone help me in this?
1
Q: Upload file with Azure Mobile Storage using SAS (Shared Access Signature)

iDroid ExplorerI know that there is library available for uploading the file using AzureMobileStoragee. I have refer this for same. But, They have not give information for how to use SAS with that. I have account name, and sas url for access and upload file there. But i don't know how to use that for uploading...

 
@bhuvin Did you create your db with EF, or was it database first?
 
7:29 AM
no its a Database first ..
 
that sounds hopeful,I had a peek into angular messed with it abit so thats a start.
 
@AshSimpson Can you do a flat binary file?
 
@bhuvin Hmm, maybe something with caching?
 
@JGrindal I can, but is that faster than any other solution?
 
@AshSimpson Loading everything into memory is the absolute fastest way.
Since you don't have much records, that's a possibility.
 
7:34 AM
So flat file is the way to go? ok.
At what point should I be using MySQL?
 
Hi all :)
any one with MVC exp?
 
@AshSimpson Indices still benefit speed even if the entire data set is in memory, so having a DB that can build indices and keep everything in memory is great for performance, and easy to use. MSSQL can do this.
@Gotalove If you want to get fancy, you can use TypeScript instead of JavaScript. It makes upfront learning curve a bit higher, but gives you a more controlled environment for yourself and collaboration, reducing overall maintenance and change costs (and your own frustration, possibly).
 
@RoelvanUden btw, got my first motorcycle lessons yesterday. 3 hours of manouvring in 30° weather :(
 
@BenjaminDiele Awesome. I love that with such weather!
@BenjaminDiele How was your first motorcycle experience? Other than hot.
 
"First" after 5 - 6 years. Great. Was awkward in the beginning, especially turning right and going "fast" (like 50km/h)
 
7:48 AM
@BenjaminDiele Haha. Sounds like fun. I forgot about the turning problem :D
@BenjaminDiele Using your own new bike or a different one?
 
morning ^^
 
@AshSimpson If you're consuming the whole of the data in sequence a flat file is almost assuredly the way to go. MySQL will see benefit once you need to search rows for matching multiple criteria and dealing with adding new rows which need to be sorted, etc. Additionally, once you hit enough data that it can't be feasibly dealt with in a flat file, obviously a SQL solution is the way to go.
 
@RoelvanUden It was a Yamaha from school, I think some FZ kinda bike.
The exam needs to be done with that bike, so it's best if I practice on it.
 
@BenjaminDiele @RoelvanUden Is it that strange to turn right?
 
As @RoelvanUden said, the best solution (if you can do it) is to load it all in memory and deal with it there.
 
7:49 AM
@JGrindal @AshSimpson SQL is not the "obvious" solution; consider NoSQL too.
 
I just found out there's a standard property in WPF elements that's been obsolete since pretty much its inception. Introduced in .NET 3.0, obsoleted in 3.0 SP1. Still supported in 4.6.
 
@RoelvanUden Fair enough. A DBMS is the obvious solution, I should say. I only said SQL because the options were MySQL vs Flat File.
 
@Loetn Yes, everyone can do one turn naturally easier (e.g. if you're right handed you turn easily to left, but not to the right). For some people it's the exact opposite too (a small minority). Almost nobody can make a corner in both directions without quite a bit of practice.
 
@Loetn Turning circles to the right. One of the exercises is doing figure 8's.
@RoelvanUden I'm left handed but like turning left :D
 
NoSQL is basically magic to me - if you can't structure your data, you deserve bad things to happen to you.
 
7:51 AM
Ooh, it's the same like turning with a car. One direction feels more natural than the other.
 
I recognize that we live in a world where that isn't true, but I like to think it is.\
 
@Loetn Yes but a car doesn't tumble over when your balance fails you
 
@JGrindal NoSQL doesn't mean your data is unstructured, it just means it isn't tabularly structured.
 
@RoelvanUden Hah, so it feels worse :)
 
@RoelvanUden It was actually pretty crazy yesterday. Couldn't get the bike on the ground, even when turning like an idiot (going from full left to full right)
 
7:54 AM
@Loetn Yeah. I was a terrible driving student. I couldn't make a proper turn to the right for the first 5~6 lessons (that's 5 to 6 hours of tumbling over, or failing to make a simple turn). It's supremely depressing :P
 
as long as I didn't touch my shifting (koppeling)
 
@BenjaminDiele "Couldn't"?
 
@RoelvanUden Did the slalom things in 2nd gear and needed to pull & push like a madman at the handle bars. Bike always stayed upright.
 
Ahhhh. :D Fun times!
 
Thus far :D
 
7:57 AM
@BenjaminDiele Pic of the bike type?
 
Looking, but can't find the exact type
@RoelvanUden found it! motorcycledaily.com/2013/11/…
 
@BenjaminDiele Ahhh. I can't drive those. :(
 
Why not? :(
 
The sitting position of those makes controlling them hard for me.
 
Hey, a topic I know nothing about. I bet everyone wants to hear my opinion :)
 
8:02 AM
Oh wait this position is more up-right, I can do that!
 
@TomW Isn't that like every developer?
 
@BenjaminDiele indeed. I've briefly considered motorcycles. Never attempted to ride one. The ability to more or less ignore traffic jams is persuasive
 
@BenjaminDiele looks really cool.
 
@TomW Yeah, but lane splitting is pretty dangerous :(
@codebrain It is very cool!
 
I am looking if it available in india
 
8:05 AM
@BenjaminDiele It's not dangerous, it's just the assholes that intentionally try to block you that make it annoying (tip: smashing off their mirror might persuade them to reconsider blocking a motorcycle again)
 
It's dangerous because not everyone expects a motorcyclist to show up from nowhere
 
I cant even drive it in this traffic :\
 
@scheien and because some bikers think it's a small freeway, and go waaay too fast
 
@scheien Especially when they show up from the left.
 
@Loetn: aye
 
8:07 AM
In a traffic jam, that is..
 
I just found out that there isn't a single datagrid on our website where column sorting actually sorts columns
it seems to just randomize the records
 
@StevenLiekens Consistency is key
 
well, it's semi sorted
it's consistently random
 
@Loetn: right hand passing are illegal in Norway, even in traffic jams.
 
@scheien In Belgium too. But most people do it in traffic jams
 
8:18 AM
MongoDB vs Postgre SQL??
 
"consistently random"
 
user image
2
 
@scheien tho no one cares whether one do right hand passes in Norway ;)
 
@Loetn: I totally understand why motorcyclist do pass on both left and right hand side in traffic jams, the problem is that some of them just blaze through in high speeds ignoring everyone else.
 
@Squiggle when you click the column header twice, you expect the sort order to be the same as it was to begin with
but it's not, it's random
every time
 
8:21 AM
@Joachim: I've seen a lot of people get stopped by the police for reckless driving on the highway :)
 
@scheien Yep, some of them even think that you know/see everything.
 
@scheien Well obviously speeding in either fields is cause for getting stopped, but passing on right hand if left field are running at 10km below speed limit I have even been behind police cars in right filed overtake left field.
 
@StevenLiekens best of luck with fixing that, mate.
 
@AshSimpson Broad question.
 
Can anyone tell me the best thing I can use for flat file querys? performing querys with flat file
 
8:23 AM
@AshSimpson what's the format within the file?
 
@Joachim: Well, sure there are stupid drivers too ;) I guess the police would do a fair assesment before pulling someone over anyway :)
 
something like this
users table:

[USER]
[ID]1[/ID]
[/USER]
[USER]
[ID]2[/ID]
[/USER]
@squiggle
 
@AshSimpson Weren't you going for in-memory? The flat file is just an implementation detail. You save and load with it, but that's about it. Everything else is queried in-memory.
 
so just like XML, but with the wrong brackets?
 
@AshSimpson How big are they, and how often do they change?
 
8:25 AM
^
 
no more than 4k records, except for a few tables that may go a bit higher.
And the user table may go up to 100 - 200k during time..
 
Because if it's relatively slow-changing data (like a user table) and isn't millions of rows, you should probably load it into an in-memory DB (possibly as simple as a Dictionary) and query that.
 
@Roel van, I was but I thought I would try flat file before doing that.
 
You're still going to have to load it into memory to do anything with it
 
@AshSimpson That is essentially a flat file..
 
8:27 AM
or import it into a queryable data store, like a database
 
oracle in-memory database, I found a link to this..
I may check this out.
 
@AshSimpson 100-200k files are going to generate a quite slow load process, you should perhaps use a Document storage such as MongoDB, Redis etc, and then you can simply use LINQ and not have to deal with a custom implementation.
 
@AshSimpson Don't take offense to this, but if you don't know about indices (e.g. building your own self balancing binary tree for them) and how in-memory queries would function, for the love of everything that is holy, use an off-the-shelve database.
 
@Roel van, good advice.
 
@AshSimpson If you need embedded databases, consider using sqlite or sqlce. For a C# mapping layer, consider EF (slow but powerful features), Linq2Db (linq and fast) or dapper (string queries, super fast). Leave NoSQL solutions out of the scope for now.
 
8:31 AM
moin moin
 
@SteffenWinkler hullo
 
@AshSimpson If it doesn't need to be embedded, PostgreSQL or MSSQL (recommended). Possibly using the in-memory setting for MSSQL absurd performance. That coupled with Linq2Db is crazy fast enough I presume.
 
@Roel van Okay, thanks for the advice.
 
@SteffenWinkler Morgen :)
 
@RoelvanUden may I ask why you're recommending the expensive piece of software that is MSSQL?
 
8:32 AM
EF folks - it's considered unsightly to call an Accessor from another Accessor, right?
 
@SteffenWinkler It's free o_o
 
Anyone using Json.net Schema? I am having trouble with horrible validation performance. Right now I use their example validation, however each business object has the JShema object cached so I don't have to constantly parse schema, but still performance is quite bad.
 
@AvnerShahar-Kashtan why would that be unsightly?
 
@RoelvanUden the Express version with 4GB of RAM and several other limitations that make it hardly better than MS Access.
 
@Squiggle Because an accessor is a single-purpose class designed to read/write a specific entity.
 
8:35 AM
(it's a sore point. I had to work with that thing for quite some time. The Express version is fine for proof of concept but that's about it IMHO)
 
I have a CaseTags entity and a Case entity, which for various bad reasons has no relationship/FK. Now I need to get only the CaseTags for Cases which match a criterion. Can't do JOINs (because no relationship), so I need to query Cases, get theirs IDs, then query CaseTags filtered by those IDs.
So I'm wondering where I should do the initial Case query - inside the CaseTag accessor, or one step earlier.
 
@AvnerShahar-Kashtan accessors are get and set on Properties...
terminology >.<
 
@SteffenWinkler Doesn't matter. His database design is small, his data-set even smaller. Hosting express is actually fine, and hosting a full instance on Azure is cheap. If you have MSDN, MSSQL doesn't cost you anything either (and honestly, who doesn't have MSDN for company use?). PostgreSQL is nice, open-source, and I like it, but C# drivers are spotty at best, especially for a novice user.
 
@Squiggle For EntityFramework, Accessors are the classes that call the DBContext class and supply basic DAL actions.
 
The DBContext supplies the basic DAL actions it's self. Have you wrapped the context in a series of repositories or something?
 
8:39 AM
@Squiggle I've inherited a set of Accessor classes, one for each entities, which does has slightly more business logic. "GetCases", "GetCasesByStatus" and so on.
 
@RoelvanUden well, in that case it'd be okay, yes. But I'd go with MariaDB. It has much better default values (seriously, MSSQL defaults to a 1 MB growsize for logfiles. I figured that out when any and every SQL request timed out on a bigger database. Took me 2 hours. Who the fuck does that?) and is easier/faster to set up and administrate
 
Those are used by the business logic classes.
 
never worked with PostgreSQL so can't comment on that.
 
@AvnerShahar-Kashtan gotchya. I would never call those accessors.
 
@SteffenWinkler I would take PostgreSQL over MySQL/MariaDB any day. :P
 
8:42 AM
how come?
well I understand the 'over MySQL' nowadays, but why over MariaDB?
 
Saner default settings, faster performance, better (performing) features, better client drivers for most languages.
That said, if I use Postgre/Maria I would use nodejs rather than .NET, and there nothing beats the postgresql driver :P
 
ah, okay. Thank you :)
 
9:43 AM
much aneurysm
I had an argument last night spanning 2 hours with a 'senior' developer
Whose mind I managed to change
He was arguing that hard coding a control with a switch statement to select the content types and their values was the right way to do it
Rather than getting collections and using loops like sane people do
/wrists
@Roel our new designer was explaining mongo to me yesterday and it actually sounds amazeballs
As in you don't need an ORM because it kind of is one.
 
Hello
 
@Sippy A designer is explaining databases? Oh dear that sounds bad.
 
@Squiggle :D
Can someone help me with a question regarding ASP.NET Identity / Login?
 
no
 
9:58 AM
I'm trying to implement this method if a user's email is not confirmed, they should not be able to login until they confirm with the code sent to their email.
I have tried many ways but it seems it gets mixed with other statements.
using System;
using System.Web;
using System.Web.UI;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using Web_WebApp.Models;

namespace Web_WebApp.Account
{
public partial class Login : Page
{
protected void Page_Load(object sender, EventArgs e)
{


RegisterHyperLink.NavigateUrl = "Register";
// Enable this once you have account confirmation enabled for password reset functionality
ForgotPasswordHyperLink.NavigateUrl = "Forgot";
//OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];
Basically the user should enter the correct username and password in order to be validated and then system should look for the "email confirmed"
 
Hey Man who is gonna read all those 150 lines ?
 
I found a solution on ASP.NET forum, but it only looks for the username...
@codebrain you can simply ignore my question ;)
 
have email confirmed flag ?
 
Yes by default is 0
 
make it active\1 when email confirmed ?
 
10:04 AM
after they confirm it's flagged as 1
 
ok
wait
 
should I do this where it says:
if (IsValid)
{ ....
I have tried everywhere but it's not doing the job
This is my function:

if (!manager.IsEmailConfirmed(user.Id))
{

ScriptManager.RegisterStartupScript(this, this.GetType(), "LaunchServerSide", "$(function() { OpenLoginModal(); });", true);
LoginModalTitle.Text = "Account Verification".ToUpper();
LoginModalDetails.Text = "You must have a confirmed email account.";
ResendConfirm.Visible = true;
}
 
if(user != null && user.isEmailConfirmed)
?
 
I had it there once, but it only looks for the user
if you put an existing username but with the wrong password, it works but it's not validating the password.
 
so its not checking for email confirmation ? can you provide that piece of code ?
 
10:08 AM
I have it up there
Please note: It's ASP.NET Web Forms (Not MVC)
 
@RoelvanUden By designer I mean he's a front end guy who can design shit and also knows JS
He knows more shit than any of the contractors lol
 
@Sippy Ah, okay. Just note that MongoDB is not ACID compliant, has eventual consistency, has a tendency to drop write operators for no particular reason other than the alignment of the moon, is schema-free (meaning you can't rely on data beinv available), and still requires indices for performance reasons.
 
Yeah his explanation was basically "It's really cool" and my response was "Yeah but I bet that's contextual."
Apparently eBay runs on Mongo though vOv
 
Perhaps as a caching layer.
Or arbitrary volatile data. I doubt they'll put finances into a black box that drops shit.
 
eBay is held together by duct tape and batch jobs.
You'll appreciate that if you ever dig through their documentation or try to integrate with their business APIs
(it's shit)
 
10:20 AM
standard dotcom history hey
1) ship some crap
2) expand for 15 years and get loads of money
3) ...that's it. What do you want from me?
 
Can someone tell me how I can improove the build time in Visual Studio? It takes me a good 30 seconds to build a console app with 1 line of code in?
 
@AshSimpson Put in an SSD.
 
Okay.
Can someone also tell me which one of these methods are the best for keeping a console app open?
for (; true;)
Console.ReadKey();

while (true)
Console.ReadKey();
 
Neither.
Block the thread, or await the primary task if it's async.
Let the console exit when your app is done.
 
Its a console app that needs to wait for incoming socket connections, and it will close if a connection doesnt connect right? because the code will be done..
 
10:28 AM
No, the socket connecting is a blocking operation (or async with a task if you use async..), so just block or await it.
 
Hi folks
Are structures in .net immutable?
 
@Toby Not by default, no.
 
Ta. so if I have an array of structures and change a value on in indexed array position structure member, It will change that instance rather than a copy, right?
eg:
 
10:31 AM
(sorry vb, dunno c#)
Public Myarray(100) As MyStruct
Myarray(0).MyStructIntMember = 5

' Now the member of the struct at MyArray(0) will be 5 and not a copy?
I did test, but on an unrelated SO question an answerer assured me that structs were immutable and my code would not act as I intended. Being a noob I thought better to double check
 
The one awesome thing about Google Chrome requesting access for Flash now is that annoying video ads don't play anymore
rip old shitty ads
 
10:48 AM
@Toby Structs are copied when passed as arguments to methods. But when accessing an array, you can change the same instance you put into it.
 
@AvnerShahar-Kashtan thanks!
 
Can anyone suggest a good way to create a license system for people I am giving my console application too? I have given them it closed source, and used a web client to download a string that either says "yes" or "no" on a php page to the license being correct, is there a better way of doing this?
 
11:10 AM
hello
I made the following extension function to get SqlDataReader data:

public static T SafelyGet<T>(this SqlDataReader reader, String name) {
if (!reader.IsDBNull(reader.GetOrdinal(name))) {
Console.WriteLine("trying to cast {0} to {1}", reader[name].GetType(), typeof(T).Name);
return (T) reader[name];
}
return default(T);
}

But if I try to get a real column value it throws an InvalidCastException with that call:

reader.SafelyGet<double>("MyColumn")

I displayed the reader["MyColumn"] type, it shows System.Single.
Single s = (single) 0.4;
double d = (double)s;

it works. Why is it throwing an exception?
If I call the SafelyGet with a float parameter it works
(same thing happen with a smallint in DB & trying to cast to int)
 
@AshSimpson That's the general idea, but you can take it much further than that. First and foremost you have to consider how you intent to protect your program. It's MSIL right now, and easy to decompile and read. Making that harder is step one. Then you just do a basic HTTP request, meaning you can proxy and intercept it, therefore you need some kind of handshake protocol that's much harder to spoof with a proxied responder.
In the end of it's merely a fight to make every attack vector as complicated as you possibly can. And it's a fight you'll end up losing regardless of the effort you put in. DRM never works.
 
@nkoniishvt Check out this code:
This is what's happening - you're not casting a float to a double, but an object (which happens to be a float) into a double, and there's no conversion between object and double.
 
@AvnerShahar-Kashtan Interesting. So it checks if the value is of the right type, if it's not it tries to convert it? That's would explain why casting to float works
 
11:25 AM
@nkoniishvt float has an explicit cast to double. object does not. The (T) call, if I understand it correctly, isn't polymorphic - it looks for an explicit cast on object, which is the return type of the reader[name] call.
 
@AvnerShahar-Kashtan Ok thank you. I probably shouldn't use the (T) cast then and instead make a switch on T and call reader.GetX (where X is the DB type)
 
Try using System.Convert.ChangeType(), which uses function calls, so will attempt to polymorphically call IConvertible methods on core types.
Alternately, don't call SafelyGet<double>() on a value that's not a double.
That's not safe. :)
 
:D
@AvnerShahar-Kashtan it works well
 
@AvnerShahar-Kashtan Try not using Convert ever
 
@KendallFrey Any specific reasons? I'm pretty sure it's inefficient, but I don't know of any specific problems with it.
 
11:32 AM
It's not that it doesn't work, it's that it's just not necessary
 
@KendallFrey Fair enough. In @nkoniishvt's case, I would urge him to do (double)reader.SafelyGet<float>() in order to get a double. Or simply assign the float to a double, since there's an implicit widening conversion there.
But if you want the SafelyGet<> call to do conversions, in addition to casting, you could use System.Convert.
 
BTW, since I don't see anyone mentioning it, the issue here is with boxing.
@AvnerShahar-Kashtan You don't use System.Convert for casting, you use it for conversion :P
 
@AvnerShahar-Kashtan is the right way to write the function to throw an an InvalidCastException this way:

public static T SafelyGet<T>(this SqlDataReader reader, String name) {
int columnIndex = reader.GetOrdinal(name);
if (!reader.IsDBNull(columnIndex)) {
Object value = reader[name];
if (value is T) {
return (T) reader[name];
}
throw new InvalidCastException(String.Format("Trying to cast {0} to {1}", value.GetType(), typeof(T)));
}
return default(T);
}
 
!!tell nkoniishvt format
 
@nkoniishvt Format your code - hit Ctrl+K before sending and see the faq
 
11:38 AM
@KendallFrey Sure, but from the original question, it seemed that @nkoniishvt expected a conversion to take place (since s/he knew it was originally a float but wanted a double).
 
        public static T SafelyGet<T>(this SqlDataReader reader, String name) {
        int columnIndex = reader.GetOrdinal(name);
        if (!reader.IsDBNull(columnIndex)) {
            Object value = reader[name];
            if (value is T) {
                return (T) reader[name];
            }
            throw new InvalidCastException(String.Format("Trying to cast {0} to {1}", value.GetType(), typeof(T)));
        }
        return default(T);
    }
@CapricaSix thanks for the type
 
C# did conversions and casting wrong IMO
 
@CapricaSix tip*
 
@nkoniishvt I would expect a method called SafelyGet not to throw an exception.
 
Not even the documentation mentions the different between them
 
11:39 AM
@KendallFrey And the ability to overload casting operators to do conversions doesn't help either.
 
@AvnerShahar-Kashtan true
 
@nkoniishvt protip: press up to edit
 
@KendallFrey thanks :)
 
Hmm. It would be nice if the method returned T if it's a reference type, or Nullable<T> if it's a value type. But I don't think the syntax supports it. And you can't specify union-generic-arguments, so you can't constrain it to where T : class | Nullable<U>
 
@AvnerShahar-Kashtan It would be nice if C# did nullables right too :P
 
11:42 AM
@KendallFrey Yeah, it's a bit tacked on.
 
well, it's more that it's half-baked in
it works better when it's tacked on as a separate component
e.g. Haskell's Maybe
@AvnerShahar-Kashtan You could write an overload
 
@AvnerShahar-Kashtan it would be nice indeed
 
So basically Haskell does all the things better
Except readability
 
@KendallFrey Yeah, that was my first idea. T SafelyGet<T> where T: class, and Nullable<T> SafelyGet<T> where T : struct.
 
seems really funky though
 
11:52 AM
Also, I'm not it will compile.
Return values can't be used to disambiguate overloads, and I'm pretty sure generic constraints can't either.
 
generic constraints can't? ah damn
 
Hmm. Switching to the Roslyn compiler erased my fiddle code.
 
Perhaps someone have faced this before, and maybe there exist other ways or library's to do schema validation with? stackoverflow.com/questions/31851961/…
 
Nullable doesn't even work with T : class :(
this would be so much simpler in Haskell
safelyGet :: SqlReader -> Maybe a
 

« first day (1755 days earlier)      last day (3194 days later) »