本文整理汇总了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);
}
示例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;
}