/// <summary>
        /// Given a set of types (e.g. Person), resolve a name that could be a field name, or a relationship name.
        /// Does not consider inheritance, which is presumed to already be resolved.
        /// </summary>
        private static IEnumerable <MemberInfo> GetMemberOfTypes(string memberName, IEnumerable <EntityType> types, MemberType findMembers)
        {
            bool findFields = findMembers.HasFlag(MemberType.Field);
            bool findRels   = findMembers.HasFlag(MemberType.Relationship);

            foreach (var type in types)
            {
                if (findFields)
                {
                    // Test fields
                    foreach (var field in type.Fields)
                    {
                        if (CompareNames(field.FieldScriptName, field.Name, memberName))
                        {
                            var result = new MemberInfo
                            {
                                MemberId   = field.Id,
                                MemberType = MemberType.Field
                            };
                            yield return(result);
                        }
                    }
                }

                if (findRels)
                {
                    // Test relationships
                    foreach (var rel in type.Relationships)
                    {
                        if (CompareNames(rel.ToScriptName, rel.ToName ?? rel.Name, memberName))
                        {
                            var result = new MemberInfo
                            {
                                MemberId   = rel.Id,
                                MemberType = MemberType.Relationship,
                                Direction  = Direction.Forward
                            };
                            yield return(result);
                        }
                    }

                    // Test reverse relationships
                    foreach (var rel in type.ReverseRelationships)
                    {
                        if (CompareNames(rel.FromScriptName, rel.FromName ?? rel.Name, memberName))
                        {
                            var result = new MemberInfo
                            {
                                MemberId   = rel.Id,
                                MemberType = MemberType.Relationship,
                                Direction  = Direction.Reverse
                            };
                            yield return(result);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        // Gets all members of the specified member kinds of the containing type, with
        // mathing name, arity, and signature at the current index (for methods and properties).
        // This will also resolve types from the given module if no containing type is given.
        public static void GetMatchingMembers(string id, ref int index, ModuleDesc module, TypeDesc containingType, string memberName, int arity, MemberType memberTypes, List <TypeSystemEntity> results, bool acceptName = false)
        {
            if (memberTypes.HasFlag(MemberType.Type))
            {
                GetMatchingTypes(module, containingType, memberName, arity, results);
            }

            if (containingType == null)
            {
                return;
            }

            int startIndex = index;
            int endIndex   = index;

            if (memberTypes.HasFlag(MemberType.Method))
            {
                GetMatchingMethods(id, ref index, containingType, memberName, arity, results, acceptName);
                endIndex = index;
                index    = startIndex;
            }

#if false
            if (memberTypes.HasFlag(MemberType.Property))
            {
                GetMatchingProperties(id, ref index, containingType, memberName, results, acceptName);
                endIndex = index;
                index    = startIndex;
            }
#endif

            index = endIndex;

#if false
            if (memberTypes.HasFlag(MemberType.Event))
            {
                GetMatchingEvents(containingType, memberName, results);
            }
#endif

            if (memberTypes.HasFlag(MemberType.Field))
            {
                GetMatchingFields(containingType, memberName, results);
            }
        }
Esempio n. 3
0
        private string GenerateValues(DocumentationType type, DocumentationCategory category)
        {
            var binding = GetBindingFlags();
            var builder = new StringBuilder();

            if (IncludedMemberTypes.HasFlag(MemberType.EnumValue))
            {
                var values = type.Type.GetFields(binding);

                if (values.Length > 0)
                {
                    var content = GetMembers(values, GenerateField, category, category.Templates.MemberSeparator);
                    builder.Append(content);
                }
            }

            return(builder.ToString());
        }
Esempio n. 4
0
        public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
        {
            string projNamespace        = string.Format("{0}", this.Name);
            List <MemberResult> members = new List <MemberResult>();

            foreach (var projEntry in ProjectEntries)
            {
                if (projEntry.Value.Analysis != null &&
                    projEntry.Value.Analysis.Body != null)
                {
                    projEntry.Value.Analysis.Body.SetNamespace(projNamespace);
                    IModuleResult modRes = projEntry.Value.Analysis.Body as IModuleResult;
                    if (modRes != null)
                    {
                        if (memberType.HasFlag(MemberType.Variables))
                        {
                            members.AddRange(modRes.GlobalVariables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, ast)));
                            members.AddRange(modRes.Variables.Where(x => x.Value.IsPublic).Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, ast)));
                        }

                        if (memberType.HasFlag(MemberType.Types))
                        {
                            members.AddRange(modRes.GlobalTypes.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, ast)));
                            members.AddRange(modRes.Types.Where(x => x.Value.IsPublic).Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, ast)));
                        }

                        if (memberType.HasFlag(MemberType.Constants))
                        {
                            members.AddRange(modRes.GlobalConstants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, ast)));
                            members.AddRange(modRes.Constants.Where(x => x.Value.IsPublic).Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, ast)));
                        }

                        if (memberType.HasFlag(MemberType.Functions))
                        {
                            members.AddRange(modRes.Functions.Where(x => x.Value.IsPublic).Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Method, ast)));
                        }
                    }
                }
            }

            return(members);
        }
        private void FindMemberProxy(MemberInfo member)
        {
            if (!MemberType.HasFlag(member.MemberType) ||
                !MatchesBindingFlags(member) ||
                !AggregateFilter(member, null))
            {
                return;
            }

            WriteObject(member);
        }
        public BindingFlags GetFieldBindingFlags()
        {
            BindingFlags flags = 0;

            if (_memberType.HasFlag(MemberType.PublicFields))
            {
                flags |= BindingFlags.Public | BindingFlags.Instance;
            }

            return(flags);
        }
Esempio n. 7
0
        public static void GetMatchingMembers(string id, ref int index, ModuleDefinition module, TypeDefinition?containingType, string memberName, int arity, MemberType memberTypes, List <IMemberDefinition> results)
        {
            if (memberTypes.HasFlag(MemberType.Type))
            {
                GetMatchingTypes(module, containingType, memberName, results);
            }

            if (containingType == null)
            {
                return;
            }

            int startIndex = index;
            int endIndex   = index;

            if (memberTypes.HasFlag(MemberType.Method))
            {
                GetMatchingMethods(id, ref index, containingType, memberName, arity, results);
                endIndex = index;
                index    = startIndex;
            }

            if (memberTypes.HasFlag(MemberType.Property))
            {
                GetMatchingProperties(id, ref index, containingType, memberName, results);
                endIndex = index;
                index    = startIndex;
            }

            index = endIndex;

            if (memberTypes.HasFlag(MemberType.Event))
            {
                GetMatchingEvents(containingType, memberName, results);
            }

            if (memberTypes.HasFlag(MemberType.Field))
            {
                GetMatchingFields(containingType, memberName, results);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Determines whether a type, specified by a Mono.Cecil's type definition, matches a filter.
        /// </summary>
        /// <param name="typeDefinition">The Mono.Cecil's type definition of a type.</param>
        /// <param name="filter">The filter which indicates which types should match.</param>
        /// <returns><see langword="true"/> if the type matches the filter; otherwise, <see langword="false"/>.</returns>
        private bool MatchTypeFilter(Mono.Cecil.TypeDefinition typeDefinition, MemberType filter)
        {
            Contract.Requires(typeDefinition != null);

            return filter.HasFlag(this.IsTypeStatic(typeDefinition) ? MemberType.Static : MemberType.Instance);
        }