Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
T

Thomas Weller 0

@Thomas Weller 0
About
Posts
151
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • \r\n
    T Thomas Weller 0

    I bet, the creator of this is proud of his clever and 'creative' solution... :sigh:

    blog.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful ruby

  • !(How to best use a try catch block) [modified]
    T Thomas Weller 0

    supercat9 wrote:

    On the other hand, it may not be possible to determine in advance all exceptions that might occur.

    Of course not. In that case we wouldn't need exceptions at all... What I mean is: 'Foreseeable' in terms of business/application logic. If something totally unexpected happens (like e.g. the 'ObjectDisposed' you mentioned), there should be a general top level exception handler at the application level, but for sure such an exception must never be swallowed silently by the executing code. Not in a million years, in no circumstance whatsoever!

    supercat9 wrote:

    I don't particularly like -1 as a return value

    Same with me, but in the case of my example -1 has a clear, discrete meaning that can de documented (less than 4 items -> computation not possible), while in the original snippet -1 means sth. went wrong (and I will never tell you what the problem was...). That's a huge difference - especially on large business-scale software projects, where you might have hundreds of such properties... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful tutorial

  • can we create object of partial class
    T Thomas Weller 0

    What exactly do you mean? The partial keyword means nothing but: the source code for a certain class can be found in more than one ASCII file. It's all about text... So a partial class is just another class, there is nothing like 'partial' in the IL code that the compiler generates. And of course you can instantiate a normal class... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C#

  • !(How to best use a try catch block) [modified]
    T Thomas Weller 0

    NEVER ever throw an exception to code a foreseeable condition - even if it might be rare. Exceptions are just not made for that, they are for error conditions! It's like knocking in a nail with a wrench: You might succeed somehow, but anyway this is hardly a good and recommendable practice...

    supercat9 wrote:

    how would you suggest coding it?

    public double CrappyTotal // and yes, this 'Total' is an 'Average'
    {
    get
    {
    if (this.SomeItem.Details.Length < 4)
    {
    return -1;
    }

        return (this.SomeItem.Details\[0\].Value +	
                this.SomeItem.Details\[1\].Value +		
                this.SomeItem.Details\[2\].Value +		
                this.SomeItem.Details\[3\].Value) / 4;
    }
    

    }

    I really would feel ashamed to code this with an exception instead, it's just ugly and bad craftsmanship... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful tutorial

  • If (null == something) or if (something == null)
    T Thomas Weller 0

    _Maxxx_ wrote:

    is there a good reason for using the former over the latter?

    There is, and AFAIK this reason comes from the good old C/C++ days. It was a very common error (the most common of all) to type if (reason = null) instead of if (reason == null). This small little typo led to very strange program behaviour and was very hard to debug, because it's very easy to overread it when inspecting the code. The problem was that the C/C++ - Compiler didn't even issue a warning when you typed something like if (reason = null), but it immediately complained about if (null = reason). So it's all about correctness and maintainability. I even saw companies with coding guidelines that dictated this style. Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# question

  • Enumerate Custom Class
    T Thomas Weller 0

    You could use reflection to enumerate over all the desired members of a class - like described in the post below. Alternatively simply implement a method object[] GetAllObjects() that returns everything you need. For serialization use the Serializable attribute and eventually the ISerializable interface (see here^ and here^). Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# help question

  • Threading
    T Thomas Weller 0

    Sure... The static keyword has nothing to do with how the code is executed, but only with where it lives (instance or type). Static/not static is simply irrelevant when it comes to different threads. In the end, it's all bytes that run through the processor, no matter where they come from... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# question

  • Enumerate Custom Class
    T Thomas Weller 0

    You seem to misunderstand the concept of enumerators: You don't enumerate a single class, but you enumerate over collections like e.g. List or Dictionary. Not quite sure what you are trying to do, but IEnumerable is definitely not the way... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# help question

  • A real Mess
    T Thomas Weller 0

    So what? As far as I've seen it, all the magic numbers are commented (not totally sure, somewhere in the middle my eyes began to bleed)... :laugh: Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful graphics

  • A real Mess
    T Thomas Weller 0

    What's your problem with Germans? There are idiots as well as geniuses and everything in between everywhere in the world... Maybe you should not care that much about weapons... :suss: Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful graphics

  • How to cast to a type stored in a field
    T Thomas Weller 0

    redivider wrote:

    Is "Type" not the right type?

    It is, but you are casting to _DataType, which is a variable, not a data type. Seems that you are confusing the two concepts of data type and variable (i.e. an instance of a data type). Besides that, the Object.GetType() method is the way to get type information from an object, casting will generally not work. So your code snippet should read something like this:

    private System.Type _Cow;
    private Dictionary<int, object> _BlobData;
    ...
    _Cow = _BlobData[0].GetType();

    Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# question help tutorial

  • I have no name, I don't exist
    T Thomas Weller 0

    Chris Losinger wrote:

    there is no "subtle bug" forum

    There is such a forum. It was called 'subtle bugs' for a long time and was just recently renamed to 'Wicked Code'. See here: http://www.codeproject.com/Feature/WickedCode.aspx. Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful c++ com algorithms debugging performance

  • Generics return type cannot cast.
    T Thomas Weller 0

    You can use a generic List instead of an untyped ArrayList, then copy the required references in the c'tor. (This assumes you are using .NET 3.5 - and of course your cIDList must be an IEnumerable, i.e. derived from any of the usual .NET collection classes). Here's what it will look like:

    public class cList<T>
    {
    private readonly List<T> ListItems = new List<T>();

    public cList(cIDList UseOwner)
    {
        if (UseOwner != null)
        { 
            ListItems.AddRange(UseOwner.OfType<T>());
        }
    }
    
    public T this\[int Index\]
    {       
        get
        {
            if ((Index >= 0) && (Index < ListItems.Count))
            {
                return ListItems\[Index\];
            }
          
            return null; // or default(T) or even better: throw an ArgumentOutOfRangeException...
       }
    }
    

    }

    Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    modified on Sunday, May 3, 2009 11:35 AM

    C# database help question lounge

  • A VS induced horror by me, kinda
    T Thomas Weller 0

    This is not an error at all... If an exception would occur in the if-condition, the resulting control flow would be without any return statement. So the compiler error is nothing but correct. No broken VS, just malformed code... Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    The Weird and The Wonderful question visual-studio data-structures help

  • Detect API Calls
    T Thomas Weller 0

    That's just not possible AFAIK. Out of curiosity: What are you trying to do? Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# question csharp json tutorial

  • Help with generics [modified]
    T Thomas Weller 0

    In this case you can simply declare two overloads, one for normal elements and one for arrays:

    static void function(ref T i)
    {
    DoSomething(i);
    }

    static void function(ref T[] i)
    {
    foreach(T element in i)
    {
    DoSomething(element);
    }
    }

    static void DoSomething(ref T i)
    {
    ...
    }

    Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# tutorial csharp html com data-structures

  • Help with generics [modified]
    T Thomas Weller 0

    You have to declare the argument as an array if it is one. Like so:

    static void function(ref T[] i)

    But your next line:

    int a = i[0];

    won't compile anyway, since the compiler cannot garantuee that T is of a type that is convertible to an int. Use something like this instead:

    static void function(ref T[] i) where T : struct
    {
    try
    {
    int a = Convert.ToInt(i[0]);

        // your code goes here
    }
    catch((FormatException) 
    {
        // error handling: conversion not possible
    }
    
    ...
    

    Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# tutorial csharp html com data-structures

  • publically readonly but internally writable objects?
    T Thomas Weller 0

    student_rhr wrote:

    I was just wondering if there is a preferred way of dealing with situations like these

    There are three ways (that I know of... :)): 1. Create an interface that only declares the elements (e.g. property getters) that the UI should see. 'Implement' it on the class of interest (actually you only have to declare it). Then pass this interface around instead of the 'real' object. 2. Implement the Data Transfer Object design pattern to handle the situation. It is described here^. In short, this method declares a struct or immutable class with all the data of interest, and if you have to pass around these data you create such an object (with a copy of the relevant data) for this purpose. 3. Declare the objects property setters and methods (if they are able to change the objects state) as internal, everything else as public. 'Internal' means exactly that: Public for everything inside the same assembly, invisible for everything outside. What best suits your needs depends on your overall architecture and the situation... Hope this helps. Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# design business help tutorial question

  • [Message Deleted]
    T Thomas Weller 0

    myventsi wrote:

    but it tells me

    first of all: who/what is it (a component from your runtime environment or the database) ? I guess it's the database? I can remember that MS SQL has a pretty narrow constraint on the length of identifiers, and I don't think that other DBMS are very different in this respect. If that's the case, you have no other choice than shortening the table name (you should do that anyway...). Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C#

  • Writing correct code
    T Thomas Weller 0

    Try this:

    DataGridView grid = new DataGridView();

    foreach(string colName in ColumnNames)
    {
    grid.Columns.Add(
    ([condition]) ?
    new DataGridViewColumn() :
    new MyColumn());
    }

    And btw: Don't care about performance at all, as long as you have no hard evidence (i.e. measures or customer complaints) about it. During development, you should only care about the correct functioning, behaviour and readability of your code. Use unit tests to reliably assure this. Regards Thomas

    www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    Programmer - an organism that turns coffee into software.

    C# css question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups