示例#1
0
        public void StartRelationResolving(ResolverData <T> resolverData)
        {
            foreach (FieldInfo fi in resolverData.FieldsToResolve)
            {
                //ResolveAttribute res = AttributeWorker.GetResolveAttribute(fi);
                //if (res == null)
                //    return;
                RelationalAttribute r = AttributeWorker.GetRelationAttribute(fi);

                if (r is OneToManyAttribute)
                {
                    _handler.HandleOneToMany(resolverData.HandledItem, (OneToManyAttribute)r, fi);
                }
                else if (r is ManyToOneAttribute)
                {
                    _handler.HandleManyToOne(resolverData.HandledItem, (ManyToOneAttribute)r, fi);
                }
                else if (r is OneToOneDefAttribute)
                {
                    Type storedType = fi.FieldType;//.GetGenericArguments()[0];
                    if (((OneToOneDefAttribute)r).Reflexive)
                    {
                        if (storedType == resolverData.HandledItem.GetType())
                        {
                            _handler.HandleOneToOneReflexive(resolverData.HandledItem, (OneToOneDefAttribute)r, fi);
                        }
                        else
                        {
                            throw new SerializerException("Reflexive Relations are only allowed in the same type.");
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }