I often need to use literal strings throughout my code. But there are some places where I feel like I shouldn't need to. Problems with consistence, readability, and spelling errors.

Case in point, data binding.

Today I type
Grid.TextField=”fieldname”
Grid.ValueField = "id"
Grid.DataSource=datatable

But here's the thing, I have classes (some I have manually created) and the EntityFramwork (with models and classes auto-generated). So I have already typed into Visual Studio the name for the field I want. Then, when referencing that field, I have to type the literal again. And again. and again.


Tomorrow I would like to type
Grid.TextField=object.property
Or perhaps
Grid.TextField= GetNameFunction(object.property)
Or even better
Grid.TextField=object.property.Name

Today, I use classes...
Public class fieldstrings
Public class SomeTable
Public const FooFieldName as string = “foo”
End class
End class
Grid.TextValue = fieldstrings.SomeTable.fooFieldName

I prefer classes over enums becuase I can nest classes, making navigation easier.
I am not thrilled about this approach, because it separates the relevant information from the original class.

I tried to do this
Public Class someobject
Public Property foo
Get...
Set...
public function Name as string
return "Foo"
end function
end property
end class

I thought about reflection, but I can only use GetType on an object, not the property.

So this time I am trying
Public class someobject
public property foo as string
publish shared foo_name as string = "foo"
end class

Anyone with other suggestions?
Thanks!