﻿using LatticeCodeGenerator.CodeExecution;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LatticeCodeGenerator.Runtime
{
    /// <summary>
    /// Object extensions to allow "dumping" an object to the current code execution session.
    /// </summary>
    public static class ObjectExtensions
    {
        /// <summary>
        /// Dumps the specified object to the current session.  
        /// Code will be generated by a <c>ICodeGenerator</c> for each dumped object.
        /// </summary>
        public static T Dump<T>(this T obj)
        {
            var currentSession = CodeExecutionSession.CurrentSession;
            if (currentSession == null)
            {
                throw new InvalidOperationException("No session has been started");
            }
            currentSession.DumpObject(obj);
            return obj;
        }
    }
}
