Jonas Bush

Blog.blog.blog.blog
posts - 16, comments - 161, trackbacks - 17

My Links

News

Archives

Post Categories

Image Galleries

General

.Net

Posts about .Net in general.
Creating generic classes at runtime
Hey there! So recently I was struggling with something for the new job, and was able to figure it out, and thought I'd share it with you, dear readers. I have a generic class I use for parsing data. Inside that class, I ran across the need to create another instance of the generic class to parse more data, but I didn't know the type at compile time. So I have this class: public class MyClass<T> where T: class { public void DoSomething() { } } In the course of DoSomething, I need to create a...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, July 15, 2010 3:45 PM | Feedback (1) | Filed Under [ .Net ]

Curly braces and string.Format()
Recently I was trying to use StringBuilder.AppendFormat to build some javascript, and was hit with an exception when trying to do this: sb.AppendFormat("function {0}(args) { return false; }", someVariable); The problem is that you can't have { or } inside an input string for string.Format(). The solution is actually fairly straightforward: sb.AppendFormat("function {0}(args) {{ return false; }}", someVariable); Instead of using "\" as an escape character, you would use { or } (depending on what you...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, March 05, 2007 2:08 PM | Feedback (14) | Filed Under [ .Net ]

Powered by: