• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 45
  • Last Modified:

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 VB.net. Can someone familiar with VB.net 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
 Get
    Return m_strCITY_STATE
 End Get
Set(ByVal strVal AS String)
   m_strCITY_STATE = strVal
End Set
End Property
0
brgdotnet
Asked:
brgdotnet
2 Solutions
 
Chris StanyonCommented:
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
0
 
it_saigeDeveloperCommented:
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}")
			Next
		Next
		Console.ReadLine()
	End Sub
End Module

Module Extensions
	<Extension()>
	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) y.properties.ToList())
	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
-saige-
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now