Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure I understand the question. But there's two toolboxes suitable for writing generic code. It's generics, and it's reflection - typically in combination. </p> <p>I don't think I really understand what you're trying to do, but a method using relfection to identify all the properties of an object might look like this:</p> <pre><code>using System.Reflection; (...) public void VisitProperties(object subject) { Type subjectType = subject.GetType(); foreach (PropertyInfo info in subjectType.GetProperties() { object value = info.GetValue(subject, null); Console.WriteLine("The name of the property is " + info.Name); Console.WriteLine("The value is " + value.ToString()); } } </code></pre> <p>You can also check out an entry on my blog where I discuss using attributes on objects in conjunction with reflection. It's actually discussing how this can be utilized to write generic UI. Not exactly what you want, but at least the same principles could be used. </p> <p><a href="http://codepatrol.wordpress.com/2011/08/19/129/" rel="nofollow">http://codepatrol.wordpress.com/2011/08/19/129/</a></p> <p>This means that you could create your own custom attributes, or use those that already exists within the .NET framework already, to describe your types. Attributes to specify rules for validation, field label, even field placement could be used. </p> <pre><code>public class Person { [FieldLabel("First name")] [ValidationRules(Rules.NotEmpty | Rules.OnlyCharacters)] [FormColumn(1)] [FormRow(1)] public string FirstName{get;set;} [FieldLabel("Last name")] [ValidationRules(Rules.NotEmpty | Rules.OnlyCharacters)] [FormColumn(2)] [FormRow(1)] public string LastName{get;set;} } </code></pre> <p>Then you'd use the method described in my blog to identify these attributes and take the apropriate action - e.g. placing them in the proper row, giving the correct label, and so forth. I won't propose how to solve these things, but at least reflection is a great and simple tool to get descriptive information about an unknown type.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload