当前位置: 首页>>代码示例>>C#>>正文


C# Signature.Distance方法代码示例

本文整理汇总了C#中Signature.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# Signature.Distance方法的具体用法?C# Signature.Distance怎么用?C# Signature.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Signature的用法示例。


在下文中一共展示了Signature.Distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DistanceTest

        public void DistanceTest()
        {
            Type[] types1 = new Type[] { typeof(object), typeof(int), typeof(float), typeof(Action), typeof(List<int>) };
            Type[] types2 = new Type[] { typeof(object), typeof(int), typeof(float), typeof(Delegate), typeof(IList<int>) };
            Assert.AreEqual(types1.Distance(types2), 2);
            Assert.AreEqual(types2.Distance(types1), 2);
            Assert.AreEqual(types1.Distance(types1), 0);

            Signature s1 = new Signature() { ParameterTypes = types1, ReturnType = typeof(Int16) };
            Signature s2 = new Signature() { ParameterTypes = types2, ReturnType = typeof(object) };

            Assert.AreEqual(s1.Distance(s2), 3);
            Assert.AreEqual(s2.Distance(s1), 3);
            Assert.AreEqual(s1.Distance(s1), 0);

            s1 = new Signature() { ParameterTypes = types1, ReturnType = typeof(Int16) };
            s2 = new Signature() { ParameterTypes = types2, ReturnType = typeof(Int16) };

            Assert.AreEqual(s1.Distance(s2), 2);
            Assert.AreEqual(s2.Distance(s1), 2);
        }
开发者ID:lebaon,项目名称:AEF,代码行数:21,代码来源:ReflectionHelperTests.cs

示例2: GetMethodByParamsAndReturnValueType

        public MethodInfo GetMethodByParamsAndReturnValueType(Type ReturnType, object[] args)
        {
            Signature sig = new Signature();
            if (args == null) args = new object[0];
            if (ReturnType != null)
                sig.ReturnType = ReturnType;
            else
                sig.ReturnType = typeof(void);
            sig.ParameterTypes = args.GetTypes();

            var t1 = MethodsBySignature.Keys.Where(
                (s) => { return s.CanStore(sig); }).Select(
                (s) => { return MethodsBySignature[s]; });
            if (t1.Count() == 0) return null;
            var t5 = t1.Aggregate(
                (a, b) => { return a.Concat(b).ToArray(); });

            var t2 = t5.Where(
                (m) =>
                {
                    var tup = BeRestrictions[m];
                    return tup.Item1.Length == 0 ? true : tup.Item1.Select((b, i) =>
                    {
                        return !b ? true : (RestrPolar[new Tuple<MethodInfo, int>(m, i)] ? Restrictions.ContainsKey(
                            new Tuple<MethodInfo, int, object>(m, i, args[i])) : !Restrictions.ContainsKey(
                            new Tuple<MethodInfo, int, object>(m, i, args[i])));
                    }).Aggregate((a, b) => { return a && b; });
                }).OrderByDescending(
                (m) => { return BeRestrictions[m].Item2; });
            var t3 = t2.GroupBy(
                (m) =>
                {
                    return BeRestrictions[m].Item2;
                });
            var t4 = t3.First().ToArray().
                OrderBy(
                (m) =>
                {
                    int dist = sig.Distance(m.GetSignature());
                    return dist;
                }).
                FirstOrDefault();
            return t4;
        }
开发者ID:lebaon,项目名称:AEF,代码行数:44,代码来源:MethodFinder.cs


注:本文中的Signature.Distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。