#region COPYRIGHT
//
//     THIS IS GENERATED BY TEMPLATE
//     
//     AUTHOR  :     ROYE
//     DATE       :     2010
//
//     COPYRIGHT (C) 2010, TIANXIAHOTEL TECHNOLOGIES CO., LTD. ALL RIGHTS RESERVED.
//
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace System.Text.Template
{
    internal abstract class MethodDefinition
    {
        protected readonly Type _type;
        protected readonly string _methodName;
        protected readonly MethodInfo _methodInfo;

        protected MethodDefinition(MethodInfo methodInfo)
        {
            _methodInfo = methodInfo;
        }

        protected MethodDefinition(Type type, string methodName)
        {
            _type = type;
            _methodName = methodName;
        }

        public abstract object Invoke(Type[] types, object[] parameters, out Type returnType);
        
        public MethodInfo GetMethodInfo(Type[] parameterTypes)
        {
            return _methodInfo ?? _type.GetMethod(_methodName, 
                BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, 
                new LazyBinder(), 
                parameterTypes, 
                null);
        }

        public string MethodName
        {
            get { return _methodName; }
        }

        public Type Type
        {
            get { return _type; }
        }

    }
}
