October 7th, 2013, 04:27 PM
I hate using literal strings. Options?
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.ValueField = "id"
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
Or even better
Today, I use classes...
Public class fieldstrings
Public class SomeTable
Public const FooFieldName as string = “foo”
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
public function Name as string
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"
Anyone with other suggestions?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!