예제 #1
0
        public static IXamlIlMethod GetMethod(this IXamlIlType type, FindMethodMethodSignature signature)
        {
            var found = FindMethod(type, signature);

            if (found == null)
            {
                throw new XamlIlTypeSystemException($"Method with signature {signature} is not found on type {type.GetFqn()}");
            }
            return(found);
        }
예제 #2
0
        public static IXamlIlMethod FindMethod(this IXamlIlType type, FindMethodMethodSignature signature)
        {
            foreach (var m in type.Methods)
            {
                if (m.Name == signature.Name &&
                    m.ReturnType.Equals(signature.ReturnType) &&
                    m.Parameters.Count == signature.Parameters.Count &&
                    m.IsStatic == signature.IsStatic
                    )
                {
                    var mismatch = false;
                    for (var c = 0; c < signature.Parameters.Count; c++)
                    {
                        if (!signature.IsExactMatch)
                        {
                            mismatch = !m.Parameters[c].IsAssignableFrom(signature.Parameters[c]);
                        }
                        else
                        {
                            mismatch = !m.Parameters[c].Equals(signature.Parameters[c]);
                        }
                        if (mismatch)
                        {
                            break;
                        }
                    }

                    if (!mismatch)
                    {
                        return(m);
                    }
                }
            }

            if (type.BaseType != null && !signature.DeclaringOnly)
            {
                return(FindMethod(type.BaseType, signature));
            }
            return(null);
        }