private void ReflectOnTypeInfo()
{
ClassType = Type.GetType(TypeName);
if (ClassType == null)
{
throw new NullReferenceException("No class type found for data mapping: " + TypeName);
}
// Get the constructor that takes no parameters (default constructor).
Constructor = ClassType.GetConstructor(new Type[0]);
foreach (MemberInfo info in ClassType.GetMembers())
{
if ((info.MemberType == MemberTypes.Field) ||
(info.MemberType == MemberTypes.Property))
{
string memberName = info.Name;
AllObjMemberInfosByObjAttr[memberName] = info;
if (IdDataColsByObjAttrs.ContainsKey(memberName))
{
string colName = IdDataColsByObjAttrs[memberName];
AllObjMemberInfosByDataCol[colName] = info;
IdDataColsByObjMemberInfo[info] = colName;
AllDataColsByObjMemberInfo[info] = colName;
}
else
{
if (NonIdDataColsByObjAttrs.ContainsKey(memberName))
{
string colName = NonIdDataColsByObjAttrs[memberName];
AllObjMemberInfosByDataCol[colName] = info;
NonIdDataColsByObjMemberInfo[info] = colName;
AllDataColsByObjMemberInfo[info] = colName;
}
else
{
// This isn't necessarily wrong, but it might be if the configuration is
// messed up.
log.Debug("Member " + memberName + " of type " + TypeName +
" is not mapped to a database column.");
}
}
}
}
// Sanity check, make sure all cols in the xml mapping actually found object attributes.
foreach (KeyValuePair<string, string> colByAttr in AllDataColsByObjAttrs)
{
string colName = colByAttr.Value;
bool found = false;
foreach (string colByMember in AllDataColsByObjMemberInfo.Values)
{
if (colName.Equals(colByMember))
{
found = true;
break;
}
}
if (!found)
{
throw new BadDaoConfigurationException("Column " + colName +
" was mapped in the mapping file for type " + TypeName +
" to field " + colByAttr.Key +
", but the class doesn't have that field. It does have: " +
StringHelper.Join(ClassType.GetMembers()));
}
}
}