コード例 #1
0
ファイル: GenericMethodHolder.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Invokes generic method
        /// </summary>
        /// <param name="instance">Object to invoke generic method on</param>
        /// <param name="typeList">Generic parameter list</param>
        /// <param name="parameters">Method parameters</param>
        public object Invoke(object instance, GenericParameterList typeList, params object[] parameters)
        {
            if (!GenericMethodCache.ContainsKey(typeList))
            {
                lock (GenericMethodCache)
                {
                    if (!GenericMethodCache.ContainsKey(typeList))
                    {
                        GenericMethodCache[typeList] = GenericMethod.MakeGenericMethod(typeList.Types);
                    }
                }
            }

            var method = GenericMethodCache[typeList];
            return method.FastInvoke(instance, parameters);
        }
コード例 #2
0
        /// <summary>
        /// Invokes generic method
        /// </summary>
        /// <param name="instance">Object to invoke generic method on</param>
        /// <param name="typeList">Generic parameter list</param>
        /// <param name="parameters">Method parameters</param>
        public object Invoke(object instance, GenericParameterList typeList, params object[] parameters)
        {
            if (!GenericMethodCache.ContainsKey(typeList))
            {
                lock (GenericMethodCache)
                {
                    if (!GenericMethodCache.ContainsKey(typeList))
                    {
                        GenericMethodCache[typeList] = GenericMethod.MakeGenericMethod(typeList.Types);
                    }
                }
            }

            var method = GenericMethodCache[typeList];

            return(method.FastInvoke(instance, parameters));
        }
コード例 #3
0
        /// <summary>
        /// Invokes generic method
        /// </summary>
        /// <param name="instance">Object to invoke generic method on</param>
        /// <param name="typeParameters">Generic parameters</param>
        /// <param name="parameters">Method parameters</param>
        public object Invoke(object instance, Type[] typeParameters, params object[] parameters)
        {
            var typeList = new GenericParameterList(typeParameters);

            return(Invoke(instance, typeList, parameters));
        }
コード例 #4
0
ファイル: GenericMethodHolder.cs プロジェクト: yallie/zyan
 /// <summary>
 /// Invokes generic method
 /// </summary>
 /// <param name="instance">Object to invoke generic method on</param>
 /// <param name="typeParameters">Generic parameters</param>
 /// <param name="parameters">Method parameters</param>
 public object Invoke(object instance, Type[] typeParameters, params object[] parameters)
 {
     var typeList = new GenericParameterList(typeParameters);
     return Invoke(instance, typeList, parameters);
 }
コード例 #5
0
 public void NonEqualityTest()
 {
     var pl1 = new GenericParameterList(typeof(int), typeof(string));
     var pl2 = new GenericParameterList(typeof(Dictionary<,>));
     Assert.AreNotEqual(pl1, pl2);
 }
コード例 #6
0
 public void HashCodeTest()
 {
     var pl1 = new GenericParameterList(typeof(bool));
     var pl2 = new GenericParameterList(typeof(bool));
     Assert.AreEqual(pl1.GetHashCode(), pl2.GetHashCode());
 }
コード例 #7
0
 public void EqualityTest()
 {
     var pl1 = new GenericParameterList(typeof(int), typeof(string));
     var pl2 = new GenericParameterList(typeof(int), typeof(string));
     Assert.AreEqual(pl1, pl2);
 }
コード例 #8
0
 public void CoverageRelatedTest()
 {
     var pl1 = new GenericParameterList(typeof(int), typeof(string));
     var pl2 = new object();
     Assert.AreNotEqual(pl1, pl2);
 }