Posts Tagged ‘.NET 2008’

Linq and Reflection

Wednesday, April 2nd, 2008

I’ve been using Linq to do queries on Reflection objects recently and I’ve found that it works quite well.  An example: –

From pi In Me.GetType.GetProperties Select pi Where pi.CanRead And pi.CanWrite And Not pi.Name Like “*_Display” And pi.GetGetMethod.GetParameters.Length = 0 And (pi.PropertyType Is GetType(String) Or pi.PropertyType Is GetType(Boolean) Or pi.PropertyType Is GetType(Date) Or pi.PropertyType Is GetType(Integer) Or pi.PropertyType Is GetType(Boolean?) Or pi.PropertyType Is GetType(Date?) Or pi.PropertyType Is GetType(Integer?) Or pi.PropertyType.IsEnum)

String Processing With Linq

Wednesday, March 26th, 2008

It just occurred to me that since a String can be treated as an array of characters, you should be able to do a Linq query on it, so I tried it, and it seems to work quite well…

Dim Test = “The cat sat on the mat”
Dim Test2 = (From c In Test Select c Where c <> ” “).ToArray()
Console.Write(Test2)

Personally, I much prefer string processing this way than with Regular Expressions.  Granted, it isn’t so versatile and is undoubtedly more processor intensive, but if you aren’t bothered about the clock cycles and it will do what you want, it is much easier to code and read!

Type Inference in .NET 2008 Part 2: Turning Type Inference On and Off

Friday, March 14th, 2008
This entry is part of a series, Type Inference in .NET»

To turn on/off Type Inference in a normal .NET project (apart from a website), go into My Project, select the Compile tab, and you can choose Option infer from the drop down list.

To control it per file in VB.NET, you can write at the top Option Infer On or Option Infer Off.

In an ASP.NET website, there is a problem setting it – see this Microsoft Feedback Report. If anyone has any information on how to work around this, please post a comment.

Entries in this series:
  1. Type Inference in .NET 2008 Part 1: What is Type Inference?
  2. Type Inference in .NET 2008 Part 2: Turning Type Inference On and Off
Powered by Hackadelic Sliding Notes 1.6.5

Type Inference in .NET 2008 Part 1: What is Type Inference?

Friday, March 14th, 2008
This entry is part of a series, Type Inference in .NET»

I’ve just been playing with type inference.  This is a new feature in VB.NET 9 and C# 3 (I think it is v3) where you can get the compiler to assign a type to a new variable automatically by using “common sense”.  Note that this looks just the same as weak typing, but it actually isn’t – the variables will be forced to the correct type by the compiler automatically, and intellisense even works!

For example, if you have type inference turned on, you can do this…

Dim i = 0 ‘i is automatically of type Integer
Dim Numbers = {1,3,5,7,9}’Numbers is automatically of type Array(of Integer)

For Each Num in Numbers ‘Num is automatically of type Integer

Next

It might seem lazy, but isn’t that the whole point?

Entries in this series:
  1. Type Inference in .NET 2008 Part 1: What is Type Inference?
  2. Type Inference in .NET 2008 Part 2: Turning Type Inference On and Off
Powered by Hackadelic Sliding Notes 1.6.5