PHP routine representing class methods.
Inheritance: RoutineInfo
示例#1
0
        internal TypeMethods(Type type)
        {
            // collect available methods
            foreach (var m in type.GetTypeInfo().DeclaredMethods.ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (_methods == null)
                {
                    _methods = new Dictionary <string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
                }

                var info = new PhpMethodInfo(_methods.Count + 1, m.Key, m.ToArray());

                _methods[info.Name] = info;

                // resolve special methods
                var magic = MagicMethodByName(info.Name);
                if (magic != MagicMethods.undefined)
                {
                    if (_magicMethods == null)
                    {
                        _magicMethods = new Dictionary <MagicMethods, PhpMethodInfo>();
                    }

                    _magicMethods[magic] = info;
                }
            }
        }
示例#2
0
        internal TypeMethods(TypeInfo type)
        {
            // collect available methods (including methods on base classes)
            foreach (var m in type
                     .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)
                     .ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (!ReflectionUtils.IsAllowedPhpName(m.Key))   // .ctor, .phpnew, implicit interface implementation
                {
                    continue;
                }

                if (_methods == null)
                {
                    _methods = new Dictionary <string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
                }

                var info = new PhpMethodInfo(_methods.Count + 1, m.Key, m.ToArray());

                _methods[info.Name] = info;

                // resolve special methods
                var magic = MagicMethodByName(info.Name);
                if (magic != MagicMethods.undefined)
                {
                    if (_magicMethods == null)
                    {
                        _magicMethods = new Dictionary <MagicMethods, PhpMethodInfo>();
                    }

                    _magicMethods[magic] = info;
                }
            }
        }
示例#3
0
        internal TypeMethods(PhpTypeInfo type)
        {
            // note: GetMethods() ignores "private" members on subclasses
            IEnumerable <MethodInfo> methods = type.Type
                                               .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            // skip members of {System.Object} if we are in a PHP type
            if (type.Type.AsType() != typeof(object))
            {
                methods = methods.Where(s_notObjectMember);
            }

            // skip [PhpHidden] methods
            methods = methods.Where(s_notPhpHidden);

            // collect available methods (including methods on base classes)
            foreach (var m in methods.ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (!ReflectionUtils.IsAllowedPhpName(m.Key))   // .ctor, .phpnew, implicit interface implementation
                {
                    continue;
                }

                var overrides = m.ToList();

                // ignore methods in base classes that has been "overriden" in current class
                // in PHP we do override even if signature does not match (e.g. __construct)
                SelectVisibleOverrides(overrides);

                //
                if (_methods == null)
                {
                    _methods = new Dictionary <string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
                }

                var info = PhpMethodInfo.Create(_methods.Count + 1, m.Key, overrides.ToArray(), type);

                _methods[info.Name] = info;

                // resolve special methods
                var magic = MagicMethodByName(info.Name);
                if (magic != MagicMethods.undefined)
                {
                    if (_magicMethods == null)
                    {
                        _magicMethods = new Dictionary <MagicMethods, PhpMethodInfo>();
                    }

                    _magicMethods[magic] = info;
                }
            }
        }
示例#4
0
        internal TypeMethods(PhpTypeInfo type)
        {
            IEnumerable <MethodInfo> methods = type.Type
                                               .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            // skip members of {System.Object} if we are in a PHP type
            if (type.Type.AsType() != typeof(object))
            {
                methods = methods.Where(s_notObjectMember);
            }

            // skip [PhpHidden] methods
            methods = methods.Where(s_notPhpHidden);

            // collect available methods (including methods on base classes)
            foreach (var m in methods.ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (!ReflectionUtils.IsAllowedPhpName(m.Key))   // .ctor, .phpnew, implicit interface implementation
                {
                    continue;
                }

                if (_methods == null)
                {
                    _methods = new Dictionary <string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
                }

                var info = PhpMethodInfo.Create(_methods.Count + 1, m.Key, m.ToArray(), type);

                _methods[info.Name] = info;

                // resolve special methods
                var magic = MagicMethodByName(info.Name);
                if (magic != MagicMethods.undefined)
                {
                    if (_magicMethods == null)
                    {
                        _magicMethods = new Dictionary <MagicMethods, PhpMethodInfo>();
                    }

                    _magicMethods[magic] = info;
                }
            }
        }
示例#5
0
        internal TypeMethods(Type type)
        {
            // collect available methods
            foreach (var m in type.GetTypeInfo().DeclaredMethods.ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (_methods == null)
                    _methods = new Dictionary<string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);

                var info = new PhpMethodInfo(_methods.Count + 1, m.Key, m.ToArray());

                _methods[info.Name] = info;

                // resolve special methods
                var magic = MagicMethodByName(info.Name);
                if (magic != MagicMethods.undefined)
                {
                    if (_magicMethods == null)
                        _magicMethods = new Dictionary<MagicMethods, PhpMethodInfo>();

                    _magicMethods[magic] = info;
                }
            }
        }
示例#6
0
 /// <summary>
 /// Creates instance of <see cref="RoutineInfo"/> representing a CLR methods (handling ovberloads).
 /// </summary>
 /// <param name="name">Function name.</param>
 /// <param name="handles">CLR methods.</param>
 /// <returns>Instance of routine info with uninitialized slot index and unbound delegate.</returns>
 public static RoutineInfo CreateUserRoutine(string name, MethodInfo[] handles) => PhpMethodInfo.Create(0, name, handles);
示例#7
0
        internal TypeMethods(PhpTypeInfo type)
        {
            // note: GetMethods() ignores "private" members on subclasses
            IEnumerable <MethodInfo> methods = type.Type
                                               .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            int index = 0;

            // skip members of {System.Object} if we are in a PHP type
            if (type.Type != typeof(object))
            {
                methods = methods.Where(s_notObjectMember);
            }

            // skip [PhpHidden] methods and hidden methods (internal, private protected)
            methods = methods.Where(s_phpvisible);

            // collect available methods (including methods on base classes)
            foreach (var m in methods.ToLookup(_MethodName, StringComparer.OrdinalIgnoreCase))
            {
                if (!ReflectionUtils.IsAllowedPhpName(m.Key))   // .ctor, implicit interface implementation
                {
                    continue;
                }

                var overrides = m.ToArray();

                // ignore methods in base classes that has been "overriden" in current class
                // in PHP we do override even if signature does not match (e.g. __construct)
                SelectVisibleOverrides(ref overrides);

                var magic = MagicMethods.undefined;

                if (IsSpecialName(overrides))
                {
                    // 'specialname' methods,
                    // get_Item, set_Item
                    if (!Enum.TryParse <MagicMethods>(m.Key.ToLowerInvariant(), out magic))
                    {
                        continue;
                    }
                }

                // TODO: negative {index} in case of non-user method

                var info = PhpMethodInfo.Create(++index, m.Key, overrides, type);

                if (magic == MagicMethods.undefined)
                {
                    _methods ??= new Dictionary <string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
                    _methods[info.Name] = info;

                    // resolve magic methods
                    magic = MagicMethodByName(info.Name);
                }

                if (magic != MagicMethods.undefined)
                {
                    _magicMethods ??= new Dictionary <MagicMethods, PhpMethodInfo>();
                    _magicMethods[magic] = info;
                }
            }
        }