ASP.NET Hosting

Archives

Archives / 2004 / June
  • Associating string values to items in code

    In a comment to my previous post about advanced enums, Chris Martin provided code for a custom attribute as a solution.

    In fact I use something similar to associate string values to class or class members. See my StringValueAttribute class.
    This works the same as Chris' implementation, and allows things like:

    enum Colors
    {
      [StringValue("#FF000")]
      Red,

      [StringValue("#00FF00")]
      Green,

      [StringValue("#0000FF")]
      Blue
    }

    Color color = Colors.Red;
    Console.Write(StringValueAttribute.GetValue(color));

    Too bad we can associate only scalar types, as strings or integers, and not objects...

    Read more...

  • C# feature request for Anders

    Hello Anders,

    Could you add to C# support for things like this?

    enum Colors {Red, Green, Blue};
    string[Colors] htmlColors = new string[] {"#FF000", "#00FF00", "#0000FF"};

    This is something we have in Delphi (you remember Delphi, don't you?) that I miss in C#. I don't think it would be difficult to add to the compiler. But if we don't have it yet, maybe there is a problem somewhere?

    Of course, we can find more examples where this syntax would help, and not only with strings.
    If we go a bit further, we can even imagine something like this:

    enum Colors<string> {Red = "#FF0000", Green = "#00FF00", Blue = "#0000FF"};

    Let me know what you think,
    Yours truly,
    Fabrice

    Read more...

  • Patcher: easy assembly patching

    This is an idea I had some time ago. I think this picture speaks by itself:

    The idea is about a tool that would allow easily patching code (remove, add, update).

    Typical scenario: you have this DLL (assembly) you'd like to modify to add some tracing code, but you don't want to (or can't) go back to the source code.
    You can also think of this as Edit&Continue for every assembly...

    Read more...

    Read more...

  • ThinkTank - Patcher: easy assembly patching

    The following picture tells most of the idea:

    The idea is about a tool that would allow easily patching code (remove, add, update).

    Typical scenario: you have this DLL (assembly) you'd like to modify to add some tracing code, but you don't want to (or can't) go back to the source code.

    Compared to Aspect-Oriented Programming, with such a tool you can write code directly in the assembly without having to create an aspect and specify weaving parameters or creating a new project or source files. The tool displays the decompiled code, then you can update the code. The new code gets compiled and inserted in the assembly in place of the old one.

    Technically, two things are needed:

    • a CLR decompiler; many IL readers exist today such as the one integrated in .NET Reflector.
    • a CLR assembly instrumentation tool such as RAIL.

    I think this tool should not be very difficult to create, given that everything required is available.

    The tool could be an add-in to .NET Reflector. You can get more inspiration from this presentation by Lutz Roeder.

    Update: this tool could also support refactoring (eg. rename a method throughout a set of assemblies).


    See other ideas in the ThinkTank

    Read more...

  • lock potential hazards

    As a follow-up to my previous post about the Singleton design pattern potential hazard, I think it is useful to point out another potential hazard in multithreading scenarios.

    Some solutions for the implementation of the Singleton design pattern are using a construct such as the following:

    lock (typeof(MyType))
    {
      ...
    }

    This is not a good idea as it can cause problems, as the .NET Framework SDK documentation explains:

    In multithreading scenarios, do not lock Type objects in order to synchronize access to static (Shared in Visual Basic) data. Other code, over which you have no control, might also lock your class type. This might result in a deadlock. Intead, synchronize access to static data by locking a private static (Shared in Visual Basic) object.

    The bad news is that this is the help for the Type class, and not for the lock keyword. The help for the lock keyword (here and there) does not talk about this.

    Read more...

  • Links about Domain-Specific Languages (DSL)

    In case you need something to read this week-end (I'd like to find some time for that), here are some interesting weblogs, articles and web sites about Domain-Specific Languages (DSL).

    Domain-specific languages are programming languages that are dedicated to specific application domains. They are less comprehensive that general-purpose languages like C or Java, but much more expressive in their domain. As a result, they have properties that are crucial for the software industry:

    • Productivity: programming, maintenance and evolution are much easier (in some cases, development time can be ten times faster); re-use is systematized.
    • Verification: it becomes possible or much easier to automate formal proofs of critical properties of the software: security, safety, real time, etc..

    [Compose project]

    Read more...

  • Design Patterns potential hazards

    As Object Oriented Programming fans, you all know Design Patterns and rely on them for your designs.

    This post by Chris Johnson about a potential hazard with the Singleton pattern is a good reminder that Design Patterns are not magical recipes. They can be sources of problems like any other piece of code if not implemented carefully.

    In the comments, people linked to interesting articles about the correct implementation of the Singleton pattern in C#:

    Better check your implementations accordingly...

    As Mark Townsend says in his article: Design patterns are very useful software design concepts that allow teams to focus on delivering the very best type of applications, whatever they may be. The key is to make proper and effective use of design patterns.

    Read more...

  • How many development tools for .NET?

    Guess how many development tools for .NET, libraries and add-ins, I can list?

    501

    That's right, more than five hundred tools!
    You can find them all in the SharpToolbox, which has become such a huge listing. This is not just a flat list, but a complete directory with categories, description, links and search function.
    And it all started with a small list on this weblog in March last year...

     

    By the way, if you have experience with some of the tools listed at http://SharpToolbox.com you'd like to communicate, please contact me.
    I'd like to conduct small interviews to help people understand how the tools can help them for the development of their applications. I think we need some case studies and best practices to know how to design applications, and what the best tools are for a given context.
    So, help promote the tools or libraries you like, and why not, expose the solutions your are the most proud of.

    Read more...