Skip to content

Instantly share code, notes, and snippets.

@adrianratnapala
Last active August 29, 2015 14:07
Show Gist options
  • Save adrianratnapala/d4fc0351cd7594f05886 to your computer and use it in GitHub Desktop.
Save adrianratnapala/d4fc0351cd7594f05886 to your computer and use it in GitHub Desktop.
// A table for finding the properties with common names in two C# types.
// the result can reduce boilerplate when you do copies, compares.
// etc between pairs of structurally similar types. E.g. a model -- controller
// transition.
//
// hat tip to http://stackoverflow.com/questions/3057178/linq-join-two-dictionaries-using-a-common-key
static Tuple<PropertyInfo, PropertyInfo>[] piPairs = (
from mPi in typeof(Model.Component).GetProperties()
join pPi in typeof(ComponentRecord).GetProperties()
on mPi.Name equals pPi.Name
select Tuple.Create(mPi, pPi)
).ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment