private IfBuilder CreateUpdateEntityStatement(
            ObjectTypeDescriptor concreteType)
        {
            IfBuilder ifStatement = IfBuilder
                                    .New()
                                    .SetCondition(
                MethodCallBuilder
                .Inline()
                .SetMethodName(_entityId, "Name", nameof(string.Equals))
                .AddArgument(concreteType.Name.AsStringToken())
                .AddArgument(TypeNames.OrdinalStringComparison));

            RuntimeTypeInfo entityTypeName = CreateEntityType(
                concreteType.Name,
                concreteType.RuntimeType.NamespaceWithoutGlobal);

            IfBuilder ifBuilder = BuildTryGetEntityIf(entityTypeName)
                                  .AddCode(CreateEntityConstructorCall(concreteType, false))
                                  .AddElse(CreateEntityConstructorCall(concreteType, true));

            return(ifStatement
                   .AddCode(ifBuilder)
                   .AddEmptyLine());
        }
        private void AddUpdateEntityMethod(
            ClassBuilder classBuilder,
            MethodBuilder methodBuilder,
            INamedTypeDescriptor namedTypeDescriptor,
            HashSet <string> processed)
        {
            methodBuilder.AddCode(
                AssignmentBuilder
                .New()
                .SetLefthandSide($"{TypeNames.EntityId} {_entityId}")
                .SetRighthandSide(
                    MethodCallBuilder
                    .Inline()
                    .SetMethodName(_idSerializer, "Parse")
                    .AddArgument($"{_obj}.Value")));

            methodBuilder.AddCode(
                MethodCallBuilder
                .New()
                .SetMethodName(_entityIds, nameof(List <object> .Add))
                .AddArgument(_entityId));

            methodBuilder.AddEmptyLine();

            if (namedTypeDescriptor is InterfaceTypeDescriptor interfaceTypeDescriptor)
            {
                // If the type is an interface
                foreach (ObjectTypeDescriptor concreteType in interfaceTypeDescriptor.ImplementedBy)
                {
                    IfBuilder ifStatement = IfBuilder
                                            .New()
                                            .SetCondition(
                        MethodCallBuilder
                        .Inline()
                        .SetMethodName(_entityId, "Name", nameof(string.Equals))
                        .AddArgument(concreteType.Name.AsStringToken())
                        .AddArgument(TypeNames.OrdinalStringComparison));

                    var entityTypeName = CreateEntityType(
                        concreteType.Name,
                        concreteType.RuntimeType.NamespaceWithoutGlobal);

                    IfBuilder ifBuilder = BuildTryGetEntityIf(entityTypeName)
                                          .AddCode(CreateEntityConstructorCall(concreteType, false))
                                          .AddElse(CreateEntityConstructorCall(concreteType, true));

                    ifStatement
                    .AddCode(ifBuilder)
                    .AddEmptyLine()
                    .AddCode($"return {_entityId};");

                    methodBuilder
                    .AddEmptyLine()
                    .AddCode(ifStatement);
                }

                methodBuilder.AddEmptyLine();
                methodBuilder.AddCode(ExceptionBuilder.New(TypeNames.NotSupportedException));
            }
            else if (namedTypeDescriptor is ObjectTypeDescriptor objectTypeDescriptor)
            {
                BuildTryGetEntityIf(
                    CreateEntityType(
                        objectTypeDescriptor.Name,
                        objectTypeDescriptor.RuntimeType.NamespaceWithoutGlobal))
                .AddCode(CreateEntityConstructorCall(objectTypeDescriptor, false))
                .AddElse(CreateEntityConstructorCall(objectTypeDescriptor, true));

                methodBuilder.AddEmptyLine();
                methodBuilder.AddCode($"return {_entityId};");
            }

            AddRequiredDeserializeMethods(namedTypeDescriptor, classBuilder, processed);
        }