|
Meysam Tolouee wrote: This is a question in StackOverFlow[^]
Without answer
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Why are you bothering us with it?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
The code makes perfect sense in its context. Were you looking at it through beer goggles?
"Seize the day" - Horace
"It's not what he doesn't know that scares me; it's what he knows for sure that just ain't so!" - Will Rogers, said by him about Herbert Hoover
|
|
|
|
|
I just came up with these two methods:
public static bool Implements(this Type t, Type interfaceType)
{
return t.GetInterfaces().Contains(interfaceType);
}
public static bool Implements<TInterface>(this Type t)
{
return t.Implements(typeof(TInterface));
}
They simply check if the Type t implements a specific interface.
I don't know of anything like this in the framework (I haven't checked).
What do you get when you cross a joke with a rhetorical question?
|
|
|
|
|
How about something like:
interfaceType.IsAssignableFrom ( t ) ;
(Untested, but I use IsAssignableFrom in similar cases.)
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I was going to suggest the same.
Basically, instead of writing someType.implements(interface) you write interface.IsAssignableFrom(someType) .
For some reason, when I encountered this method the first time, I thought that an "Implements" method would make more sense, even if they are basically the same.
|
|
|
|
|
Is it normally the case that you have a Type that you need to check vs. an actual instance?
For an instance there's:
if (foo is ISomething)
|
|
|
|
|
Reflecting over the types in an assembly, for instance (i.e. a basic plugin system).
What do you get when you cross a joke with a rhetorical question?
|
|
|
|
|
I guess since they're one-liners they weren't thought necessary. I don't think they exist in the framework so if they make things clearer then yes, they count as useful
|
|
|
|
|
One of the products we are presenting at a trade show tomorrow is around 30 dashboards in swf format with the data URL baked in. (a limitation of the designer) The URLs point to one of our web servers where the logic and raw XML data files reside. I found out this morning that we will not have internet access for the presentation. No connection to the webserver, and the dashboards fail with a nice XML data error. Big Fail!
I told the designer that she was going to have to recompile each one (10 minutes each) for the show and she broke down in tears. Then I remembered a little file named hosts. Ten minutes later, and the problem was solved. Ain't loopback a wonderful thing?
"Go forth into the source" - Neal Morse
|
|
|
|
|
Good thinking, and nice of you to be kind to the designer.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
If you're always thinking outside the box, chances are you're in the wrong box.
|
|
|
|
|
|
Alive or dead?
Did you look?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Can i quote you in my skype please ?
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
It's nice when developers know more than just how to copy and paste and tweak code. It's nice when they actually know how the computer works.
Nice quick thinking.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Application startup creates a
SqlConnection for each database it uses, and opens it, and this is then passed as a parameter from one module to the next for the lifetime of the application....to save the time opening and closing the connection.
|
|
|
|
|
See, I told you already. With smart programmers like this, we don't need connection pooling.
|
|
|
|
|
This is actually valid in certain, rather unusual circumstances (e.g. a networked database running an old engine or configured such that it doesn't pool connections from different processes). But it's almost guaranteed that the coder just didn't know what he was doing ...
|
|
|
|
|
..actually connection pooling is enabled and on (because we are using the ADO.NET client for SQL Server it is on by default and set to a pool size of 100 conenctions). The code is just not using it.
|
|
|
|
|
Duncan Edwards Jones wrote: Conscious perma-coupling for the lifetime Maybe an author of the idea couldn't find a proper woman, and wanted to make it up by designing a "couply" system... Maybe he should break up with Anna.avi and get merried.
|
|
|
|
|
A RichTextBox has an Rtf property, and a SelectedRtf property.
Even when all text is selected, their values differ.
Just try:
string rtf1 = richTextBox1.Rtf;
richTextBox1.SelectAll();
string rtf2 = richTextBox1.SelectedRtf;
System.Diagnostics.Debug.Assert(rtf1 == rtf2);
|
|
|
|
|
|
No, it does not. By the way, this is the Weird and Wonderful , or Coding Horrors forum - I really intended to place it here, because it is quite a WTF, and I do not expect a sensible answer for it (OK, if you know it, let me here it).
It rather looks like a philisophical design decision: since Rtf is always longer than SelectedRtf , the whole is more than the sum of its parts...
|
|
|
|
|
Try this test to get a better Idea.
Create a test project with a richtextbox and a normal text box.
two buttons and a label to show the length
In VB.net it would look like.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selLen As Integer
Dim selectedRtf As String = RichTextBox1.SelectedRtf
selLen = selectedRtf.Length
Label1.Text = selLen.ToString
TextBox1.Text = selectedRtf
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim selLen As Integer
Dim selectedRtf As String = RichTextBox1.Rtf
selLen = selectedRtf.Length
Label1.Text = selLen.ToString
TextBox1.Text = selectedRtf
End Sub
Using a converter to convert to C# it would look like this.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
int selLen = 0;
string selectedRtf = RichTextBox1.SelectedRtf;
selLen = selectedRtf.Length;
Label1.Text = selLen.ToString;
TextBox1.Text = selectedRtf;
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{
int selLen = 0;
string selectedRtf = RichTextBox1.Rtf;
selLen = selectedRtf.Length;
Label1.Text = selLen.ToString;
TextBox1.Text = selectedRtf;
}
Next create some text in wordpad with different formating. Copy paste to the richtextbox (ctl+V)
what this code does is gets the length of the string, the entire string with the hidden formating and copies it to the plain textbox to view all of it.
You can add the line to select all or just select it on the RTF box.
After going back and forth between the buttons you may notice that the second one shows more formatting and thus it is longer.
|
|
|
|