If you want to limit the parameters that a method receives in compile time you will always have to have an enum (at least so far C# doesn't have a way to get the list of properties at compile time.
However, if you are okay with limiting the input in run time, you could use reflection to get the list of properties and check the input to see whether it should return or throw and exception/return error code. It is worth mentioning that reflection is slow so be sure you really need it or performance isn't a problem.
If, on the other hand, you need the compile time check, but would like to be able to query the object for the property values (not the database as your Get method seems to be doing), you could use an enum as you have already done and use reflection to get property values via the enum so you know which property's value to get, but I would recommend in that case to use a Dictionary
to store the values and use type-safe properties that use the enum so you have "the best of both worlds". You still have the enum, but if you need the compile time check it's the best you can do.
Here is an example implementation (without sanity checks) of this method:
public class myTest
{
public class Person
{
protected Dictionary<string, object> _properties;
public Person()
{
_properties = new Dictionary<string, object>();
}
public Int32 Id
{
get
{
return (int)_properties[EPerson.Id];
}
set
{
_properties[EPerson.Id] = value;
}
}
public String Fname
{
get
{
return _properties[EPerson.FName] as String;
}
set
{
_properties[EPerson.FName] = value;
}
}
public string Lname
{
get
{
return _properties[EPerson.LName] as String;
}
set
{
_properties[EPerson.LName] = value;
}
}
}
public enum EPerson
{
Id = 0,
Fname = 1,
Lname = 2
}
public static void Get(EPerson SearchBy, dynamic Value)
{
var Sql = "select from dbo.bobo where " + SearchBy.ToString() + "='" + Value + "'";
}
public static void testget()
{
Get(EPerson.Fname, "Bob");
}
}