---
title: "Getting property names at compile time"  
description: "Getting property names at compile time"  
author: "Anonymous User"  
published: 2013-04-10  
updated: 2013-04-15  
canonical: https://www.mindstick.com/forum/752/getting-property-names-at-compile-time  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Getting property names at compile time

Hi Everyone!\
I have a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) with some [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties):\
class Foo{ int Bar { get; set; } [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) Baz { get; set; } bool Quux { get; set; } (...)}For use in some [storage](https://www.mindstick.com/articles/44536/finding-your-self-storage-facility) API, I need to specify a subset of these properties, by name as [strings](https://www.mindstick.com/forum/161912/explain-the-python-strings):\
var props = new string[]{ "Bar", // Don't want this one... "Baz", "Quux", ...};This works, but is [unsafe](https://www.mindstick.com/blog/115/unsafe-code-in-c-sharp) - if I mistype "Quux", I won't get a [compilation error](https://www.mindstick.com/forum/159699/what-is-a-compilation-error-in-dot-net-core-explain-with-an-example), just (hopefully) a runetime error. I tried [reflection](https://www.mindstick.com/articles/13004/how-to-write-a-reflection-paper) - typeof(Foo).GetProperties\
("Bar") - but that would also fail only in runtime.\
Ideally, I'd like to do something like:\
var props = new string[]{ Magic_GetName(Foo.Bar), // Don't want this one... Foo.Baz, Magic_GetName(Foo.Quux), ...};\
How can I achieve that?Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ankit!\
Make the properties public to access them outside the class\

```
class Foo{    public int Bar { get; set; }    public string Baz { get; set; }    public bool Quux { get; set; }    (...)}
```


---

Original Source: https://www.mindstick.com/forum/752/getting-property-names-at-compile-time

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
