33 lines long condition in this piece of code is absolutely adorable! A drunk disassembler would have done a better job generating such code :) No kidding - recently, I had to restore some source code from a compiled dll, and reflector's result was way more reasonable than this one.
makumazan84
Posts
-
warning C4706: assignment within conditional expression -
Range CheckingI'm currently ROFL-ing inside, guys!!! A true pearl. Notice, that ANY int suits the condition )))
-
ModusOperandiThis is what happens when lawyers become programmers ) P.S. Once a musician saw my C# book and asked me "Why is this thick book called Do-Diese?" :)
-
DRY, SoC, IoC, KISS... (NOT)I think that this piece of code is adorable (in a coding horror kind of way). Reminds me of a scene in Tarantino's Kill Bill pt.1, the one where Uma Thurman was slaughtering bad guys in Japan ))) I've really enjoyed all these cases in the code, but it is the size of this method that makes me dizzy. I still wonder how the PM or co-workers haven't done something before this method grow that big.
-
Great C# generics naming [modified]Yeah ) From time to time I (and many other programmers) also got stuck when it comes to naming )) Probably, the part of the problem is that people who don't know generics usually google the first working example and rather often it uses such naming. To make things worse, Microsoft's MSDN website also "teaches" such generics namings. However, common sence should have won in my co-workers's case. Besides, he could have looked at other generics in that very same project, where type arguments are named like "TWrapper" or "TBaseObject" and thus bear some helpful info. Obvoiusly, exploding my poor brain with a whole bunch of T's wasn't a good option :-)
-
Great C# generics naming [modified]Ha-ha) Probably you are right. In this case, what does "t" stands for? Most likely (bc it is an instance of T), this is from the first Terminator, the one that got smashed by Sarah Connor during the final battle inside the factory. Luckily, the author of that generic is not a fan of Aliens series )
-
Great C# generics naming [modified]I've got a co-worker, who has done some great job in producing handsome and easy to understand pieces of code. The previos pearl was a 238 lines method, and when I asked to refactor it, he told that it was just fine. Still, this one is my favorite. (The name of the metHod is not that important)
public void SendMetod(IEnumerable t)
where T: class
where T1: class
where T2: classFor some company issues I cannot post the method itself(a nice piece of work too, trust me), but it's header is adorable. T, T1, T2 and t is kinna brain explosive -- Modified Thursday, September 2, 2010 5:53 AM
-
Strange error occures after writting (seemingly) working piece of xaml code in a WPF application. IDE=Visual Studio 2010Hi, All! I'm having another major trouble. I have developed a control, that has some properties, but once I set binding to these properties, a strange error occures during the build. Visual Studio highlights an irrelevant string from the xaml code with green color. here is a code sample which throws that error: Note 2 things: 1) Code below builds fine 2) In an output window of VS, it is stated, that System.Unimplemented exception occurred in PresentationFramework.dll. Usually, such exception means, that requested method is not implemented, which is kinda odd, because this property is indeed implemented.
-
how to convert an array of records into a hierarchical structurePartly my fault: original message has been parsed and it dropped the fact, that the field Children is a generic of type TreeBranch - it contains children of a certain node. Each of those children can have its own List of children, and so on. Anyways, it's all about converting an array of objects which have ID and ParentID into a tree hierarchy. Consider a case an array: (ParentID;ID) -,1 1,2 1,3 2,4 4,5 should look something like 1- 2- 3 4- 5 Because the depth of the tree is unknown, recursion is the only option - we have no idea about the nodes, that are inhereted from the current. For some dumb security reasons of my job I can't post the code here, but I'll do that later, since the task is very real life
-
how to convert an array of records into a hierarchical structureHi & thanks for reply&interest. Nevermind my previous thought - that idea was not working ) What I need to do is to write a recursive method, so it will be able to work at any depth. Not that great with recursion, but job needs to be done. Once I'll finish that, I'll post an answer to share with others.
-
how to convert an array of records into a hierarchical structurehere is a problem. I've got an array of records with 2 fields: ID and ParentID. This array represents a hierarchical tree, where each node can have multiple children. What I need is to convert it to a more compact form, like this (code is in C#)
public class TreeBranch
{
int ID;
List Children; //collection of children of this node
.........................
}................
List MainTree;// a collection that contains the whole tree I've came up with a dizzy solution, but I don't like it since it is O (n^2). Any ideas will be appreciated )
-
How to stretch Colum header in WPF datagrid?Hi, guys! I'm having a bit of a trouble with my columns' headers in WPF Datagrid. Some of them are too long, and horizontal stratching is not an option: there are too many of columns, and user will not be able to see full text in headers. Here is what I'd like to do I want header "Word1 word2 word3 word4 word5 word6" to look like "Word1 word2 word3 word4 word5 word6" - so it srteches vertically. Thanks in advance
-
A weird WPF build-time error [modified]I have a xaml file, which has a codeline, something like. xmlns:a="http://schemas.someadress.com/bla/bla/bla" - the name is defined in an assembly which contains that desired namespace. Above mentioned namespace contains a class, that I'd like to use in my xaml. But I cannot build the project with this file, bc Visual Studio throws me an error "The tag '' doesn't exist in a namespace "http://schemas.someadress.com/bla/bla/bla" Line A Position B" Interesting enough, that the intellisence can see that class in "a:" - when I start typing it pops up the class that I need. Adress "http://schemas.someadress.com/bla/bla/bla" is correct - I've copypasted it from an assemblyinfo. Besides, other xaml files in a project can perfectly use that specific class from that assembly. Note, that this question comes from a WPF noobie, and can sound dumb. Still, I've spent more than an hour and ran out of ideas. Any help will be greatly appreciated. Thanks in advance ------------ UPDATE: I got this one figured. The problem was that the project's compilation settings were set for .NET Framework 4.0 Client Profile. Once I switched to a regular 4.0, everything got fixed
modified on Friday, July 23, 2010 9:12 AM
-
How to get rid of "Enter text here" in DatePicker?Here is the problem: I have a DatePicker control (Framework 4.0) and once I delete the text in its textbox, a phrase "Enter text here" (enclosed in <> brackets) appears in a text box. I need to get rid of it, so when the user deletes the text in a DatePicker's textbox, the textbox remains empty. So far I've tried to examine DatePicker's code via reflector, but haven't found any clues. Any help will be greatly appreciated.
-
HTML Page download in C#Thanks for a reply, Harlod. I know about DownloadDataAsync, but I didn't try that. Now, I will try that, and post the result. UPDATE: I've implemented downloading via DownloadDataAsync, but still the problem of 2 pages remained :-( Also, the same exception was thrown.
modified on Saturday, June 26, 2010 10:11 AM
-
HTML Page download in C#Hi, all! Here is the problem: I'm writting some code that gets HTML page, and then grabs it's content. The content of the page is organized in multiple pages, and navigation between them is done by clicking on the page's number below the records (For example, there are 150 records, displayed in 10 pages * 15 records/page. Therefore, the web page contains 10 hyperlinks to other pages with records). Obviously, in order to get all the information needed, I need to loop through all the pages' links, download their HTML and afterwards parse the information. The problem is, that I can only download 2 pages from the list. For some unknown reason, my code freeses after it downloads 2 pages. The order of the pages does not matter, for example if I start from page #5, I can only get pages 5 and 6. According to common sense and VS debugger the problem lies in the method, that downloads HTML code
public delegate byte[] getHTTPdelegate(Uri address); // this is a delegate defined as a class member, used to perform async page download
public void downloadPage(string URL)
{
// creating new webclient
client = new WebClient();
//assigning download method to a delegate
getHTTPdelegate dl = client.DownloadData;// starting async download IAsyncResult ar = dl.BeginInvoke(new Uri(URL), null, null); while (!ar.IsCompleted) { Thread.Sleep(10); } // rawpage contains HTML in terms of byte\[\], the result of async download rawPage = dl.EndInvoke(ar); // this is also the line where exception occurs }
After downloading page #2, the application stops, and in a minute ar two throws an unhandled exception stating that operation has timed out. Please note, that the problem is not "why isn't it working?", but "why does it work only 2 times?", when it should be downloading all the pages. Any ideas will be highly appreciated.
-
random seeds?As I have understood your post, you are having troubles with random numbers generation. Here is a solution, that may be helpful. As it has been noted, a seed number is used to start numbers generation. In most occasions this number is dependent on current time, for example, Environment.TickCount can be such a seed. What happens sometimes, is that number sequences are being generated too fast, so that the time-related seed is not changed. This may result in troubles, when you are generating numbers not in one sequence. Here is a code example. We are generating an array of objects typed
sample
, and each object contains a set of randomly generated numbers.class sample
{
double[] dblMyArray = new double[20]; // number 20 bears no actual meaning, it's just an examplepublic sample() { Random rndObj = new Random(Environment.TickCount); for (int i = 0; i < dblMyArray.Length; i++) dblMyArray\[i\] = rndObj.NextDouble(); } } class Program { static void Main(string\[\] args) { sample\[\] mainArray = new sample\[10\]; // number 10 bears no actual meaning, it's just an example for (int i = 0; i < mainArray.Length; i++) mainArray\[i\] = new sample(); } }
Now, what will happen is a sad fact: all the objects in
mainArray
will have THE SAME values indblMyArray
. This is because modern computations are fast, and time related seed cannot change fast enough. You may run this code and check out the values. If you have a similar problem, the solution is to sleep a program for a short time, I used 1ms. This way the seed number will change, and each time you'll have different sequences. -
Remote Desktop issueHi, guys! I'd be really happy if someone could solve my trouble. Here is the story I've got a home network, with a LAN server, which is also a Internet gateway, has a static IP and gives the internet to the local area computers. One of the local area computers is a Windows 2008 Web Server. In order to connect to it I've added some exceptions on the LAN server, so the ports are redirected from the Lan Server to 2008 Web Server. The problem is that Remote Desktop is not working in this case. Actually, you can access the 2008 Web Server from the LAN computers, but you cannot access it via the Internet (by typing a Static IP of the LAN server) Thanks for the help, I really appreciate that
-
Problems with installing SQL Server 2008I've spent half of the day trying to install SQL Server 2008, but it wouldn't install. At the very end it shows me a table saying that "Database Engine Services Failed", and "Replication Failed". Evidently, because of this failures, the service in the services (control panel) will not start
-
How to set up an SQL ServerI've spent half of the day trying to install SQL Server 2008, but it wouldn't install. At the very end it shows me a table saying that "Database Engine Services Failed", and "Replication Failed"