private static void GenerateRequestCreateEntity(ICodeBlock codeBlock)
        {
            var requestCreateMethod = codeBlock.Function(
                "public RedGrin.INetworkEntity", "RequestCreateEntity", "long ownerId, object entityData");

            requestCreateMethod.Line("RedGrin.INetworkEntity entity = null;");

            bool needsElseIf = false;

            var netEntities = GlueState.Self.CurrentGlueProject.Entities
                              .Where(item => NetworkEntityViewModel.IsNetworked(item));

            foreach (var entitySave in netEntities)
            {
                ICodeBlock ifBlock;

                var    fullNetStateType = CodeGeneratorCommonLogic.GetNetStateFullName(entitySave);
                var    fullEntityType   = CodeGeneratorCommonLogic.GetElementFullName(entitySave);
                string ifcontents       = $"entityData is {fullNetStateType}";

                if (needsElseIf == false)
                {
                    ifBlock = requestCreateMethod.If(ifcontents);
                }
                else
                {
                    ifBlock = requestCreateMethod.ElseIf(ifcontents);
                }

                var hasFactory = entitySave.CreatedByOtherEntities;

                if (hasFactory)
                {
                    var factoryName = $"{GlueState.Self.ProjectNamespace}.Factories.{entitySave.GetStrippedName()}Factory";
                    ifBlock.Line($"entity = {factoryName}.CreateNew();");
                }
                else
                {
                    ifBlock.Line($"entity = new {fullEntityType}();");
                }

                // Even though the NetworkManager assigns the owner ID, we're going to do it here
                // to before calling UpdateFromState, so that any custom code that gets triggered from
                // UpdateFromState are guaranteed to have the right ID:

                ifBlock.Line("entity.OwnerId = ownerId;");

                ifBlock.Line("entity.UpdateFromState(entityData, 0);");

                needsElseIf = true;
            }

            // At first I thought to have the CustomRequestCreateNetworkEntity
            // inside the if/else if so that the created entity could be modified
            // but it's possible the user may want to have their own totally custom
            // network entities and network entity states, in which case they will need
            // to instantiate the object fully in custom code. Therefore, we'll call the
            // method no matter what, even if the entity is null
            requestCreateMethod.Line("CustomRequestCreateNetworkEntity(ref entity, entityData);");

            requestCreateMethod.Line("return entity;");
        }