Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class property at run time

Status
Not open for further replies.

hacesol

Programmer
Apr 2, 2007
10
ES
Hi:

Can I create a dynamic Class property at run time?

Thanks
 
No, and why would you want to? There may be a better solution than what you are trying
 
For example:

I have this Class:

public class Class1
{
public string Code;
public string Name;
}

and if I get a null value of Code, add the property:
public Errors Error;

I'm using this class in a web service and the normal response is:

<Class1>
<Code>...</Code>
<Name>...</Name>
</Class1>

If I get a null Code I would like to produce the follow XML

<Class1>
<Error>...</Error>
</Class1>



 
Why not just create a validation function in your class that returns the error formatted the way you want it? You can return the error or just set another "error" property. Then you can check that property for a value and do what you need to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top