ForEachMember() public méthode

public ForEachMember ( bool inherited, RubyMethodAttributes attributes, Action action ) : void
inherited bool
attributes RubyMethodAttributes
action Action
Résultat void
Exemple #1
0
        internal static RubyArray /*!*/ GetMethods(RubyModule /*!*/ self, bool inherited, RubyMethodAttributes attributes)
        {
            var result = new RubyArray();

            self.ForEachMember(inherited, attributes, delegate(string /*!*/ name, RubyMemberInfo /*!*/ member) {
                result.Add(MutableString.Create(name));
            });
            return(result);
        }
            public override IEnumerable <string> GetDynamicMemberNames()
            {
                var self = (IRubyObject)Value;
                RubyInstanceData instanceData = self.GetInstanceData();
                RubyModule       theClass     = (instanceData != null ? instanceData.ImmediateClass : null);

                theClass = theClass ?? self.Class;
                var names = new List <string>();

                theClass.ForEachMember(true, RubyMethodAttributes.DefaultVisibility, delegate(string /*!*/ name, RubyMemberInfo /*!*/ member) {
                    names.Add(name);
                });
                return(names);
            }
Exemple #3
0
        internal static RubyArray /*!*/ GetMethods(RubyModule /*!*/ self, bool inherited, RubyMethodAttributes attributes,
                                                   IEnumerable <string> foreignMembers)
        {
            var result = new RubyArray();

            using (self.Context.ClassHierarchyLocker()) {
                self.ForEachMember(inherited, attributes, foreignMembers, (name, module, member) => {
                    if (member.IsInteropMember && (module.Restrictions & ModuleRestrictions.NoNameMapping) == 0 && RubyUtils.HasMangledName(name))
                    {
                        if (Tokenizer.IsMethodName(name) || Tokenizer.IsOperatorName(name))
                        {
                            result.Add(new ClrName(name));
                        }
                    }
                    else
                    {
                        result.Add(self.Context.StringifyIdentifier(name));
                    }
                });
            }
            return(result);
        }
Exemple #4
0
 internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes) {
     var result = new RubyArray();
     var symbolicNames = self.Context.RubyOptions.Compatibility > RubyCompatibility.Ruby18;
     self.ForEachMember(inherited, attributes, delegate(string/*!*/ name, RubyMemberInfo/*!*/ member) {
         if (symbolicNames) {
             result.Add(SymbolTable.StringToId(name));
         } else {
             result.Add(MutableString.Create(name));
         }
     });
     return result;
 }
Exemple #5
0
 internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes) {
     var result = new RubyArray();
     self.ForEachMember(inherited, attributes, delegate(string/*!*/ name, RubyMemberInfo/*!*/ member) {
         result.Add(MutableString.Create(name));
     });
     return result;
 }
        /// <summary>
        /// メソッド定義情報を取得する。
        /// </summary>
        /// <param name="constant">モジュールまたはクラスのRubyオブジェクト。</param>
        /// <param name="attributes">メソッド取得対象を表すスイッチ。</param>
        /// <param name="objectDefinition">オブジェクト定義のインスタンス。</param>
        /// <param name="singleton">シングルトンメソッドか?</param>
        private static void GetMethodDefinitions(
            RubyModule constant,
            RubyMethodAttributes attributes,
            RubyObjectDefinition objectDefinition,
            bool singleton)
        {
            constant.ForEachMember(false, attributes | RubyMethodAttributes.VisibilityMask, (methodName, module, memberInfo) =>
            {
                if (memberInfo is RubyAttributeAccessorInfo)
                {
                    var accessorInfo = (RubyAttributeAccessorInfo)memberInfo;
                    var accessorName = methodName;

                    if (accessorInfo is RubyAttributeWriterInfo)
                    {
                        accessorName = accessorName.Substring(0, accessorName.Length - 1);
                    }

                    var accessorDefinition = (
                        from a in objectDefinition.Accessors
                        where a.Name == accessorName
                        select a
                    ).FirstOrDefault();

                    if (accessorDefinition == null)
                    {
                        accessorDefinition = new RubyAccessorDefinition()
                        {
                            Name = accessorName
                        };

                        objectDefinition.Accessors.Add(accessorDefinition);
                    }

                    if (accessorInfo is RubyAttributeWriterInfo)
                    {
                        accessorDefinition.Writable = true;
                    }
                    else if (accessorInfo is RubyAttributeReaderInfo)
                    {
                        accessorDefinition.Readable = true;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else if (memberInfo is RubyMethodInfo)
                {
                    var methodInfo = (RubyMethodInfo)memberInfo;

                    var methodDefinition = new RubyMethodDefinition()
                    {
                        Name = methodName,
                        Singleton = singleton
                    };

                    foreach (LocalVariable argument in methodInfo.Parameters.Mandatory)
                    {
                        methodDefinition.Arguments.Add(
                            new RubyMethodArgumentDefinition()
                            {
                                Name = argument.Name,
                                Optional = false
                            }
                        );
                    }
                    foreach (SimpleAssignmentExpression argument in methodInfo.Parameters.Optional)
                    {
                        var argumentDefinition = new RubyMethodArgumentDefinition()
                        {
                            Name = ((LocalVariable)argument.Left).Name,
                            Optional = true
                        };

                        if (argument.Right is Literal)
                        {
                            argumentDefinition.DefaultValue = ((Literal)argument.Right).Value;
                        }
                        else if (argument.Right is ClassVariable)
                        {
                            argumentDefinition.DefaultValue = ((ClassVariable)argument.Right).Name;
                            argumentDefinition.ClassVariable = true;
                        }

                        methodDefinition.Arguments.Add(argumentDefinition);
                    }

                    objectDefinition.Methods.Add(methodDefinition);
                }
                else
                {
                    throw new NotImplementedException();
                }
            });
        }
Exemple #7
0
        internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes,
            IEnumerable<string> foreignMembers) {

            var result = new RubyArray();
            var symbolicNames = self.Context.RubyOptions.Compatibility > RubyCompatibility.Ruby18;

            using (self.Context.ClassHierarchyLocker()) {
                self.ForEachMember(inherited, attributes, foreignMembers, (name, module, member) => {
                    if (member.IsInteropMember && (module.Restrictions & ModuleRestrictions.NoNameMapping) == 0 && RubyUtils.HasMangledName(name)) {
                        result.Add(new ClrName(name));
                    } else {
                        result.Add(CreateMethodName(name, symbolicNames));
                    }
                });
            }
            return result;
        }
Exemple #8
0
        internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes,
            IEnumerable<string> foreignMembers) {

            var result = new RubyArray();
            var symbolicNames = self.Context.RubyOptions.Compatibility > RubyCompatibility.Ruby18;

            using (self.Context.ClassHierarchyLocker()) {
                self.ForEachMember(inherited, attributes, foreignMembers, delegate(string/*!*/ name, RubyMemberInfo member) {
                    result.Add(CreateMethodName(name, symbolicNames));
                });
            }
            return result;
        }
Exemple #9
0
        internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes,
            IEnumerable<string> foreignMembers) {

            var result = new RubyArray();
            using (self.Context.ClassHierarchyLocker()) {
                self.ForEachMember(inherited, attributes, foreignMembers, (name, module, member) => {
                    if (member.IsInteropMember && (module.Restrictions & ModuleRestrictions.NoNameMapping) == 0 && RubyUtils.HasMangledName(name)) {
                        if (Tokenizer.IsMethodName(name) || Tokenizer.IsOperatorName(name)) {
                            result.Add(new ClrName(name));
                        }
                    } else {
                        result.Add(self.Context.StringifyIdentifier(name));
                    }
                });
            }
            return result;
        }