Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Identifying exactly what your specifications are would help. From what you've said, and from what the code appears to be doing, you just want to take each property on a given type and verify that it's on another type, then set your own type's property with an index value if it is. From that perspective (and perhaps there are additional requirements that I'm unaware of), your code is jumping through a few unnecessary hoops and could be condensed down to something more manageable.</p> <ul> <li>The first loop cycles through each property in tnsType and loads it into a local Dictionary.</li> <li>The second loop checks the existence of a Dictionary value, ignores the PropertyInfo that you're currently working with and reloads it from the type.</li> </ul> <p>This could be consolidated down to a single loop with a get and a set (unless you have other requirements that may impact this). It's also important to note that GetProperties() is not guaranteed to return properties in any particular order, so if your code depends on the order (and I suspect that's true because the code seems to be equating a given index with a given property) you may end up getting unexpected results at some point. </p> <pre><code>private void GenerateFieldIndexes() { Type thisType = GetType(); Type tnsType = typeof(T); int index = 2; foreach (PropertyInfo property in thisType.GetProperties()) { var tnsProperty = GetProperty (tnsType, property.Name); if (tnsProperty == null) throw new FieldNameMissingException(string.Format("{0} Property name {1} missing!", thisType, property.Name)); property.SetValue(this, index, null); FieldNames.Add(property.Name.ToLower()); index++; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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