Esempio n. 1
0
        public static IXamlMethod GetMethod(this IXamlType type, FindMethodMethodSignature signature)
        {
            var found = FindMethod(type, signature);

            if (found == null)
            {
                throw new XamlTypeSystemException($"Method with signature {signature} is not found on type {type.GetFqn()}");
            }
            return(found);
        }
Esempio n. 2
0
        public static IXamlMethod FindMethod(this IXamlType 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);
        }