Is there a way in .NET to have a class property have a second name or an alias. I want the alias to show in Visual Studio Intellisense? The reason is for me to know what property maps to what column in a database and if I put the column name somewhere with the corresponding property, I can easily know how the mappings work.
+5
A:
I don't think there is anyway to give it an alias, but you could easily create another property with a different name that just accesses the property you are trying to get to.
class MyClass
{
private int myVal;
public int MyProperty
{
get { return this.myVal; }
set { this.myVal = value; }
}
public int MyDbProperty
{
get { return this.MyProperty; }
set { this.MyProperty = value; }
}
}
heavyd
2009-06-30 16:08:38
This won't help a developer understand which property maps to which column in the database via intellisense.
AdamRalph
2009-06-30 16:30:00
+8
A:
You could put the column name in an XML comment on the property, e.g.
/// <summary>
/// Maps to column 'foo'
/// </summary>
public int Foo { get; set; }
The content of the XML comment will show in the intellisense tooltip for the Foo property.
AdamRalph
2009-06-30 16:11:46
A:
You could simply add another property assigning the one you want an "alias" for.
public String InnerProp { get; set; }
public String AliasProp
{
get { return this.InnerProp; }
set { this.InnerProp = value; }
}
Sani Huttunen
2009-06-30 16:11:57
+1
A:
There is no way to do this at a metadata or even a language level. However you can use simple properties that forward their requests to achieve the same result
public class Student {
private string _name;
public string ColumnName { get { return _name; } set { _name = value; } }
public string Name { get { return ColumnName; } set { ColumnName = value; }}
}
JaredPar
2009-06-30 16:13:05