---
title: "The [Conditional] Attribute"
url: "https://osherove.com/blog/2003/9/1/the-conditional-attribute.md"
canonical: "https://osherove.com/blog/2003/9/1/the-conditional-attribute.html"
published: "2003-09-01T03:35:00"
updated: "2003-09-01T03:35:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "If you want to write methods that are only available with conditional compiler arguments you can use an attribute just for that purpose: < Conditional(\"DEBUG\")> _ Private Sub MyMethod() End Sub [Conditional(\"DEBUG\")]…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# The \[Conditional\] Attribute

By Roy Osherove September 1, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published September 1, 2003; technical details may be outdated.

If you want to write methods that are only available with conditional compiler arguments you can use an attribute just for that purpose:

<

Conditional("DEBUG")> \_ Private Sub MyMethod() End Sub \[Conditional("DEBUG")\] Private void MyMethod()

{}

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Sep 3, 2003

    ### [Israel Visual Basic User Group today - on ADO.Net](https://osherove.com/blog/2003/9/3/israel-visual-basic-user-group-today-on-adonet.html)

- Sep 1, 2003

    ### [Hosting the CLR - the native approach](https://osherove.com/blog/2003/9/1/hosting-the-clr-the-native-approach.html)

- Sep 1, 2003

    ### [Asynchronous ASP.Net actions suck?](https://osherove.com/blog/2003/9/1/asynchronous-aspnet-actions-suck.html)

- Aug 25, 2003

    ### [Loading Winform UI controls from a different AppDomain is problematic](https://osherove.com/blog/2003/8/25/loading-winform-ui-controls-from-a-different-appdomain-is-pr.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
