Scala to C# port: part 2

Well have definitely found my C# paint point. Or maybe it’s just me not knowing C# well enough yet, but the biggest thing I’m missing so far from Scala is the brilliant pattern matching I’ve got used too. In particular pattern matching with regexes.

While trying to parse a SQL ‘like’ language, I’ve got various chunks of code such as:

 

statement match {

      case orTermNotEnd( field, value, rest ) =>

      {

        returnRest = rest

        nodes ::= processOrStatement( field, value )

      }

 

      case orTermEnd( field, value ) =>

      {

        nodes ::= processOrStatement( field, value )

      }

 

      case greaterRegexEnd( field, value ) =>

      {

 

        var node = createNode( field, gtOp, value )

        nodes ::= node

 

      }

 

 

etc…

 

which is very very useful.  But so far for C# I’ve had to put in a lot of nested if statements. Which at best is ugly…  but has many other down sides.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s