Property Attributes

Hello Experts,

I am working with a VB .net project, and am looking at some of the defined properties. There are several items above the property that are labeled "AttributeColumnName" AttributeDBColumnName. I have never seen that before in Can someone familiar with explain it to me? Why are these attributes above the property name? Can someone point me to some online documentation on this?

<AttributeColumnName("CITY_STATE"), AtributeDBColumnName("CITY_STATE"), AttributeDataType("char"),AttributeKeywordField("pCITY_STATE"),AttributeFieldLen(8),AttributeColumnIndex(12)>
Public Property CITY_STATE() AS String
    Return m_strCITY_STATE
 End Get
Set(ByVal strVal AS String)
   m_strCITY_STATE = strVal
End Set
End Property
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
You can use attributes on your properties and classes to add additional information to them. Looking at the attributes you've posted they're probably something to do with a database, or datagrid.

They look like they're custom attributes, so there''s not likely to be any documentation specifically for those ones, but there' plenty of docs about for custom attributes in general.

Try searching through your codebase for AttributeColumnName - that might point you in the direction of what is using them. Could be custom code inside your app, or it could be a referenced library
Attributes provide additional metadata or declarative information to your codebase.  This metadata can be queried at run-time/design-time, using reflection, in order to control logic flow, provide additional descriptive information or define additional behaviour when considering special circumstances; to name a few.

In your specific case, the attributes are being used to associated the property with a database column.  In this way, the Entity Framework (assumption) has all the information it needs in order to maintain a cohesive relationship between the CITY_STATE property and the CITY_STATE column in the defined table of the defined database.

A small example -
Imports System.Reflection
Imports System.Runtime.CompilerServices

Module Module1
	Sub Main()
		For Each pair In Assembly.GetEntryAssembly().EntryAssemblyMetaData()
			For Each value In pair.Value
				Console.WriteLine($"{pair.Key}: {value}")
	End Sub
End Module

Module Extensions
	Public Function EntryAssemblyMetaData([assembly] As Assembly) As Dictionary(Of String, List(Of String))
		Return (From [attribute] In assembly.GetCustomAttributes(False).Cast(Of Attribute)
				From [property] In attribute.GetType().GetProperties()
				Where Not [property].Name.Equals("TypeId", StringComparison.OrdinalIgnoreCase)
				Group CType([property].GetValue(attribute, Nothing), String) By [Key] = attribute.GetType().Name Into properties = Group
				Select New With {[Key], properties}).ToDictionary(Function(x) x.Key, Function(y)
	End Function
End Module

Open in new window

Which produces the following output -Capture.PNGMost of the metadata that I queried, originates from the AssemblyInfo.vb file -Capture.PNG

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.