using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using EHF;

namespace Valg.EVA.Skanning.Scan.Api
{
    public class FillPercentageFieldValueAssigner : IFieldValueAssigner
    {
        public string AssignValue(IEHF_COMField field)
        {
            object classicObject = null;
            try
            {
                classicObject = field.GetClassicObject();
                var result = classicObject.GetType().InvokeMember("GetFill", BindingFlags.InvokeMethod, null, classicObject, null, CultureInfo.InvariantCulture);
                return result.ToString();
            }
            finally
            {
                if (classicObject != null && classicObject.GetType().IsCOMObject) 
                {
                    Marshal.ReleaseComObject(classicObject);
                    classicObject = null;
                }
            }
        }
    }
}
