Class creation questions

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have a project that im maintaining. I have come across the following class

VB.NET:
<MetadataType(GetType(Customer.CustomerMeta))> _
Partial Public Class Customer

Friend Class CustomerMeta
<Required(), StringLength(20)> Public FirstName As String
End Class

Questions are:

1. Is this the 'standard' or preferred way of creating a class or is it a slightly modern/outdated technique?

2. Why have this line and what does it do?
VB.NET:
<MetadataType(GetType(Customer.CustomerMeta))>

3. FirstName is declared as a public variable. Wouldnt it have been better to have this as a property i.e. (
VB.NET:
<Required(), StringLength(20)> Public Property FirstName As String)
?

4. Is the Required attribute needed in the class? Many times developers would go to the page itself and write something similar to:

VB.NET:
If myCustomer.FirstName.Length < 0 then msgbox "Please enter a customer name"

Thanks
 
1. Attributes is used to add meta descriptions, they may have various purpose. They are especially common in tool generated code, and when designing components.
2. MetadataTypeAttribute attribute associate a class with a data-model partial class.
3. Normally yes, but this is for mapping a field in a data model.
4. Required attribute is used for required fields in data model.
 
1. Attributes is used to add meta descriptions, they may have various purpose. They are especially common in tool generated code, and when designing components.
2. MetadataTypeAttribute attribute associate a class with a data-model partial class.
3. Normally yes, but this is for mapping a field in a data model.
4. Required attribute is used for required fields in data model.

Where could i find this tool if one has been used? I don't think it has as most tools would have a comment stating a tool has been used but i could be wrong?

Are there any links/tutorials where i could read up how this class has integrated with the data model? Or even a book?

Thanks again
 
Back
Top