Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns News Feed 

It is said that a framework is not a framework until a developer uses it.

It seems my CodeDom Patterns library now has its first users, Justin Dunlap and Marc Clifton, as featured in their article Object Mapping Part II - Schema Code Generator (part 1) over at The Code Project. Go check it out.

Wednesday, November 01, 2006  |  From Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns

The latest update (1.8) of my article Commonly Used .NET Coding Patterns in CodeDom is now out.
Changes made since 1.7:

  1. The Code Access Security Decorator Patterns have been added.
  2. The Assembly Information Pattern has been added.
  3. Security demand added to GetObjectData in the Serializable Type Pattern.
  4. Xml Comment Patterns moved to .Xml namespace and had their CodeXmlComment prefix removed (too long).
  5. Binaries now target .NET 2.0 instead of .NET 1.1, but they are still mostly backwards compatible.

The project is now hosted on CodePlex, complete with forums, an rss feed, an issue tracker and the whole nine yards. As always, suggestions are more than welcome.


Thursday, October 26, 2006  |  From Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns

Because CodeDom is so verbose and uses a massive grid of objects to represent code structures, it also has many small reusable objects, such as CodeTypeReference objects. Many people overlook this fact because there are so many object being created anyway, but sometimes a certain object will be used over and over. Since both the creation of these objects takes time and they also take up memory as unnecessary copies, consider creating a cache.

For example, for the next release of the CodeDom Patterns library, I've created a cache for CodeTypeReference objects:

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->using System; using System.Collections.Generic; using System.CodeDom; namespace DotNetZen.CodeDom { /// <summary> /// Acts as a cache for <see cref="CodeTypeReference"/> objects. /// </summary> public static class CodeTypeReferenceStore { private static Dictionary<RuntimeTypeHandle, CodeTypeReference> typeReferences = new Dictionary<RuntimeTypeHandle, CodeTypeReference>(); private static Dictionary<string, CodeTypeReference> nameReferences = new Dictionary<string, CodeTypeReference>(); /// <summary> /// Gets a <see cref="CodeTypeReference"/> by the <see cref="Type"/> it should reference. /// </summary> /// <param name="type">The type being referenced.</param> /// <returns>A <see cref="CodeTypeReference"/> object.</returns> public static CodeTypeReference Get(Type type) { RuntimeTypeHandle handle = type.TypeHandle; if (!typeReferences.ContainsKey(handle)) { typeReferences.Add(handle, new CodeTypeReference(type)); } return typeReferences[handle]; } /// <summary> /// Gets a <see cref="CodeTypeReference"/> by the name of the <see cref="Type"/> it should reference. /// </summary> /// <param name="type">The name of the type being referenced.</param> /// <returns>A <see cref="CodeTypeReference"/> object.</returns> public static CodeTypeReference Get(string typeName) { if (!nameReferences.ContainsKey(typeName)) { nameReferences.Add(typeName, new CodeTypeReference(typeName)); } return nameReferences[typeName]; } } }

 

It's been a while, but the latest update (1.7) of my article Commonly Used .NET Coding Patterns in CodeDom is now out.
Changes made since 1.6:

  1. The Nullable Value Type Property Pattern has been added.
  2. The Enum.IsDefined and String.IsNullOrEmpty assertions have been added.
  3. The Serializable Type Pattern has been added.
  4. The Disposable Type Pattern is now a part of CodePatternTypeDeclaration.

I'd love to hear any and all opinions.


The latest update (1.6) of my article Commonly Used .NET Coding Patterns in CodeDom is now out.
Major changes made since 1.5:

    1. The Asynchronous Operation pattern has been added.
    2. The Disposable Type pattern has been added.
    3. The XML Comment patterns have been added.
    4. Automatic documentation of the Begin/End Process, Custom Attribute, Custom Exception, Delegate, Event, Observer, Singleton, and Typed Collection patterns.
    5. The Unary operators IsNull and NotNull have been added.
    6. Several bug fixes.
    7. The work is now licensed under the Creative Commons Attribution 2.5 License: You can copy, freely distribute, derive, and even use the code in a commercial product, but you must attribute it to the author (that is, me).
As always, I'm looking for new ideas to add, so let me know if you think of anything else you'd like to add to the package.
The formatting is a little screwey, especially in the code samples, but it's ok.

Please note that the new license now permits free use of this code in commercial products. If you decide to use the library, I'd love to know about it. :)

I have uploaded another update (1.5) to my article: Commonly Used .NET Coding Patterns in CodeDom.
Major changes made since 1.4:

  1. The Typed Collection pattern has been added.
  2. The Argument Assertion patterns have been added.
  3. Assembly and all types are now CLSCompliant.
  4. All types are now marked as serializable.
  5. The Custom Attribute pattern now produces sealed attributes, to increase the efficiency of generated code.
  6. Several overload additions and bug fixes.
Upcoming features:
  1. Automatic documentation of members.
  2. Async patterns.
  3. Dispose pattern.
  4. Serialization pattern.
  5. And more...

Saturday, February 11, 2006  |  From Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns

I have uploaded another update (1.4) to my article: Commonly Used .NET Coding Patterns in CodeDom.
Major changes made since 1.2:

    1. Now compatible with generation for Visual Basic. Sorry about that.
    2. The Custom Attribute pattern has been added.
    3. The Custom Exception pattern has been added.
    4. The For Each pattern now works according to the C# specifications.
    5. Interface more intuitive.
    6. Lots of bug fixes.
I'm always looking for new ideas to add, so let me know if you think of anything else you'd like to add to the package.

Also, there's a conversation in the comments on how to add these as macros for Visual Studio.NET 2003 (to act as code snippets).

Tuesday, January 17, 2006  |  From Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns

I have uploaded another update to my article: Commonly Used .NET Coding Patterns in CodeDom.
I can't seem to find a way to subscribe to articles on The CodeProject, so I'll just put the update here.
Changes made since 1.0:

    1. Binary and unary operator patterns have been added.
    2. Compound assignment patterns have been added.
    3. The Cursor Lock pattern now changes the cursor back to its original icon, rather than Cursors.Default.
    4. The For Each pattern has been added.
    5. The Is Instance Of pattern has been added.
    6. Boolean flags for scope are now implemented using the Scope enumeration.
    7. Boolean flags for the resource type on the Using pattern are now implemented using the ResourceType enumeration.
    8. Boolean flags for the load type on the Singleton pattern are now implemented using the LoadType enumeration.

Wednesday, November 02, 2005  |  From Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns

My first article, Commonly Used .NET Coding Patterns in CodeDom, has just been published on The Code Project.

The CLR and other .NET code contain many recurring patterns. As these patterns appear in code, they may also appear in CodeDom, yet generating those patterns takes much work, which is quite repetitive. This library contains several pattern implementations for use in your CodeDom code.
  • The BeginProcess/EndProcess Pattern
  • The Cursor Lock Pattern
  • The Delegate Pattern
  • The Event Pattern
  • The Flags Pattern
  • The Get Property/Field Pattern
  • The Lock Pattern
  • The Observer Pattern
  • The Singleton Pattern
  • The Using Pattern History
...

 Omer van Kloeten's .NET Zen : Tools: CodeDom Patterns News Feed 

Last edited Dec 7, 2006 at 11:16 PM by codeplexadmin, version 1

Comments

No comments yet.