Custom Attributes

Feb 2 2006 12:59 PM
Hi guys
Let me describe first what i'm trying to do.I have object which has few properties of type string.
I want each property should have MaxLength set.Also i want those property values and MaxLength values should read from XML.
I dont want to parse the XML and assign values. Instead of that i want to deserialize that XML into object that will automatically set those properties and MaxLength for each property.
One way i was trying to achieve this is using CustomAttribute for MaxLength.I created Custom Attribute and attached that CustomAttribute to each of the property.Now the value for that Custom Attribute whcih is nothing but MaxLength should be automatically set when i deserialize.
Which i dont know how to do.Its perfectly fine if i have to take off CustomAttribute and use some .net XmlAttribute.
When i deserialize my XML i get Property Values but not CustomAttribute values.

My Xml Look like this
<?xml version="1.0" encoding="utf-16" ?>
<
FileHeader>
<Property1 MaxLength="10">FirstName</Property1>
<Property2 MaxLength="12">LastName</Property2>
</
FileHeader>


and my object look like

[Serializable]
public class FileHeader
{
private string _property1 = string.Empty;
private string _property2 = string.Empty;

[LengthAttribute()]
public string Property1
{
get{return _property1;}
set{_property1 =value;}
}

[LengthAttribute()]
public string Property2
{
get{return _property2;}
set{_property2 =value;}
}

public FileHeader()
{
//
// TODO: Add constructor logic here
//
}
}

I know here LengthAttribute is not taking any values.but i DONT KNOW  how to fill it up at run time

Answers (1)