private MethodCallBuilder BuildUpdateMethodCall(ITypeDescriptor property, string firstArg)
        {
            var deserializeMethodCaller = MethodCallBuilder.New()
                                          .SetDetermineStatement(false)
                                          .SetMethodName(DeserializerMethodNameFromTypeName(property));

            deserializeMethodCaller.AddArgument(firstArg);

            if (property.IsEntityType() || property.ContainsEntity())
            {
                deserializeMethodCaller.AddArgument(_entityIdsParam);
            }

            return(deserializeMethodCaller);
        }
        private MethodCallBuilder BuildUpdateMethodCall(
            ITypeDescriptor property,
            ICode argument)
        {
            MethodCallBuilder deserializeMethodCaller = MethodCallBuilder
                                                        .Inline()
                                                        .SetMethodName(DeserializerMethodNameFromTypeName(property));

            deserializeMethodCaller.AddArgument(argument);

            if (property.IsEntityType() || property.ContainsEntity())
            {
                deserializeMethodCaller.AddArgument(_entityIds);
            }

            return(deserializeMethodCaller);
        }
        private void AddDeserializeMethod(
            ITypeDescriptor typeReference,
            ClassBuilder classBuilder,
            HashSet <string> processed)
        {
            string methodName = DeserializerMethodNameFromTypeName(typeReference);

            if (processed.Add(methodName))
            {
                MethodBuilder methodBuilder = classBuilder
                                              .AddMethod()
                                              .SetPrivate()
                                              .SetReturnType(typeReference.ToEntityIdBuilder())
                                              .SetName(methodName);

                methodBuilder
                .AddParameter(_obj)
                .SetType(TypeNames.JsonElement.MakeNullable());

                if (typeReference.IsEntityType() || typeReference.ContainsEntity())
                {
                    methodBuilder
                    .AddParameter(_entityIds)
                    .SetType(TypeNames.ISet.WithGeneric(TypeNames.EntityId));
                }

                IfBuilder jsonElementNullCheck = IfBuilder
                                                 .New()
                                                 .SetCondition($"!{_obj}.HasValue")
                                                 .AddCode(
                    typeReference.IsNonNullableType()
                            ? ExceptionBuilder.New(TypeNames.ArgumentNullException)
                            : CodeLineBuilder.From("return null;"));

                methodBuilder
                .AddCode(jsonElementNullCheck)
                .AddEmptyLine();

                AddDeserializeMethodBody(classBuilder, methodBuilder, typeReference, processed);
            }
        }
        private void AddDeserializeMethod(
            ITypeDescriptor typeReference,
            ClassBuilder classBuilder,
            HashSet <string> processed)
        {
            string methodName = DeserializerMethodNameFromTypeName(typeReference);

            if (processed.Add(methodName))
            {
                var returnType = typeReference.ToEntityIdBuilder();

                var methodBuilder = MethodBuilder.New()
                                    .SetAccessModifier(AccessModifier.Private)
                                    .SetName(methodName)
                                    .SetReturnType(returnType)
                                    .AddParameter(
                    ParameterBuilder.New()
                    .SetType(_jsonElementParamName)
                    .SetName(_objParamName));
                if (typeReference.IsEntityType() || typeReference.ContainsEntity())
                {
                    methodBuilder.AddParameter(
                        ParameterBuilder.New()
                        .SetType($"{TypeNames.ISet}<{TypeNames.EntityId}>")
                        .SetName(_entityIdsParam));
                }

                methodBuilder.AddCode(
                    EnsureProperNullability(isNonNullType: typeReference.IsNonNullableType()));

                classBuilder.AddMethod(methodBuilder);

                AddDeserializeMethodBody(
                    classBuilder,
                    methodBuilder,
                    typeReference,
                    processed);
            }
        }