
Conditional Using
April 9, 2009Today I found myself writing the following code:
private void DoSomething(String userName)
{
using(var userEntry = GetUserEntryFor(userName))
if(CouldBeFound(userEntry))
{
// Do something with userEntry
}
}
private DirectoryEntry GetUserEntryFor(String userName)
{
// ...
}
private static Boolean CouldBeFound(DirectoryEntry entry)
{
return null != entry;
}
Notice the combination of the if statement with the using statement. I thought this was kind of neat. What do you think?
Is the style of this code bonafide?
If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or checkout the books section. Feel free to reach out at info. @ principal-it .be

Jan Van Ryswyck
Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.
Comments


Writing Maintainable
Unit Tests
Watch The Videos
Latest articles
-
Tales Of TDD: The Big Refactoring
February 2, 2022
-
Implementing Approval Tests For PDF Document Generation
December 15, 2021
-
Approval Tests For PDF Document Generation
October 7, 2021
-
Ignoring Tests
June 22, 2021
-
Writing Maintainable Unit Tests In Print
April 23, 2021
Tags
- .NET
- ALT.NET
- ASP.NET
- Agile
- Announcement
- Architecture
- Behavior-Driven Development
- C++
- CQRS
- Clojure
- CoffeeScript
- Community
- Concurrent Programming
- Conferences
- Continuous Integration
- Core Skills
- CouchDB
- Database
- Design Patterns
- Domain-Driven Design
- Event Sourcing
- F#
- Fluent Interfaces
- Functional Programming
- Hacking
- Humor
- Java
- JavaScript
- Linux
- Microsoft
- NHibernate
- NoSQL
- Node.js
- Object-Relational Mapping
- Open Source
- Reading
- Ruby
- Software Design
- SourceControl
- Test-Driven Development
- Tools
- Visual Studio
- Web
- Windows
Disclaimer
The opinions expressed on this blog are my own personal opinions. These do NOT represent anyone else’s view on the world in any way whatsoever.
About
Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.
Latest articles
Tales Of TDD: The Big Refactoring
Implementing Approval Tests For PDF Document Generation
Approval Tests For PDF Document Generation
Ignoring Tests
Contact information
(+32) 496 38 00 82
info @ principal-it .be