public void RegisterType(Type type) { FieldInfo[] fis = AttributeWorker.RetrieveAllFields(type); foreach (FieldInfo fi in fis) { RelationalAttribute r = AttributeWorker.GetRelationAttribute(fi); if (r != null) { VirtualKey template; if (r is OneToManyAttribute) { template = RegisterOneToManyVKey(type, fi); } else if (r is ManyToOneAttribute) { template = RegisterManyToOneVKey(type, fi); } else if (r is OneToOneDefAttribute) { if (((OneToOneDefAttribute)r).Reflexive) { template = RegisteReflexiveOneToOneDefVKey(ref type, fi); } else { throw new NotImplementedException(); } } } } }
private VirtualKey RegisterManyToOneVKey(Type type, FieldInfo fi) { VirtualKey template; MappedByAttribute a = AttributeWorker.GetMappedByAttribute(fi); if (a != null) { Type fType = fi.FieldType; FieldInfo tmp = _worker.RetrieveField(fType, a.MappedBy, true); if (tmp == null) { throw new Serializer.SerializerException(); } RelationalAttribute rTmp = AttributeWorker.GetRelationAttribute(tmp); if (rTmp == null || !(rTmp is OneToManyAttribute)) { throw new Serializer.SerializerException(); } if (AttributeWorker.GetJoinColumnsAttributes(fi).Length > 0) { throw new Serializer.SerializerException(); } template = CreateTemplateEntry(type, fType); template.TargetField = fi; } else { Type navigatedType = fi.FieldType; template = CreateTemplateEntry(type, navigatedType); JoinColumsAttribute[] jcs = AttributeWorker.GetJoinColumnsAttributes(fi); if (jcs.Length <= 0) { throw new Serializer.SerializerException(); } foreach (JoinColumsAttribute jc in jcs) { Console.WriteLine(type + ":" + _worker.RetrieveField(type, jc.JoinColumn, false)); Console.WriteLine(navigatedType + ":" + _worker.RetrieveField(navigatedType, jc.DefColumn, false)); FieldInfo tmp = _worker.RetrieveField(type, jc.JoinColumn, false); if (tmp == null) { throw new Serializer.SerializerException(); } template.AddJoinKeyField(jc.JoinColumn, tmp); template.TargetType = type; List <String> tmpList; try { tmpList = _foreignKeys[type]; } catch (KeyNotFoundException) { tmpList = new List <String>(); _foreignKeys[type] = tmpList; } tmpList.Add(jc.JoinColumn); tmp = _worker.RetrieveField(navigatedType, jc.DefColumn, false); if (tmp == null) { throw new Serializer.SerializerException(); } template.AddDefKeyField(jc.DefColumn, tmp); template.SourceType = navigatedType; template.AddKeyTranslation(jc.DefColumn, jc.JoinColumn); template.TargetField = fi; } } return(template); }