public IAnalysisResult GetMember(GetMemberInput input)
 {
     if (MemberDictionary.Count == 0 && MimicTableName != null)
     {
         return(null);
     }
     else
     {
         VariableDef varDef = null;
         MemberDictionary.TryGetValue(input.Name, out varDef);
         return(varDef);
     }
 }
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     definingProject = null;
     projEntry       = null;
     if (MemberDictionary.Count == 0 && MimicTableName != null)
     {
         return(null);
     }
     else
     {
         VariableDef varDef = null;
         MemberDictionary.TryGetValue(name, out varDef);
         return(varDef);
     }
 }
        public bool TryGetCache <TEntity>(Snowflake parentId, out ISynchronizedDictionary <Snowflake, TEntity> cache, bool lookupOnly = false)
            where TEntity : CachedSnowflakeEntity
        {
            lock (this)
            {
                if (!_nestedCaches.TryGetValue(typeof(TEntity), out var nestedCache))
                {
                    cache = default;
                    return(false);
                }

                if (nestedCache.TryGetValue(parentId, out var boxedCache))
                {
                    cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache;
                    return(true);
                }

                if (!lookupOnly && _supportedNestedTypes.Contains(typeof(TEntity)))
                {
                    if (typeof(TEntity) == typeof(CachedUserMessage))
                    {
                        var messageCache = new MessageDictionary(MessagesPerChannel).Synchronized();
                        cache = (ISynchronizedDictionary <Snowflake, TEntity>)messageCache;
                    }
                    else if (typeof(TEntity) == typeof(CachedMember))
                    {
                        var memberCache = new MemberDictionary(this).Synchronized();
                        cache = (ISynchronizedDictionary <Snowflake, TEntity>)memberCache;
                    }
                    else
                    {
                        cache = new SynchronizedDictionary <Snowflake, TEntity>();
                    }

                    nestedCache.Add(parentId, cache);
                    return(true);
                }

                cache = default;
                return(false);
            }
        }
        /// <summary>
        /// Determines whether an extension method is hidden by a member that's already defined on the type being extended.
        /// The extension method is hidden if it has the same name, template params, and parameters as a defined method.
        /// </summary>
        /// <param name="extensionMethod">The extension method to compare.</param>
        /// <param name="members">A dictionary of the members defined on the type being extended.</param>
        /// <returns></returns>
        private bool IsExtensionMethodHidden(Method extensionMethod, MemberDictionary members)
        {
            if (!members.MemberNames.Contains(extensionMethod.Name.Name))
            {
                return(false);
            }

            // get a list of members with the same name as the extension method
            List <Member> membersList = members[extensionMethod.Name.Name];

            foreach (Member member in membersList)
            {
                // the hiding member must be a method
                if (member.NodeType != NodeType.Method)
                {
                    continue;
                }
                Method method = (Method)member;

                // do the generic template parameters of both methods match?
                if (!method.TemplateParametersMatch(extensionMethod.TemplateParameters))
                {
                    continue;
                }

                // do both methods have the same number of parameters?
                // (not counting the extension method's first param, which identifies the extended type)
                if (method.Parameters.Count != (extensionMethod.Parameters.Count - 1))
                {
                    continue;
                }

                // do the parameter types of both methods match?
                if (DoParameterTypesMatch(extensionMethod.Parameters, method.Parameters))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
        public SymbolDefMember FindMember(string name)
        {
            if (MemberDictionary.ContainsKey(name))
            {
                SymbolDefMember member = MemberDictionary.Get(name);
                return(member);
            }
            if (IsStaticClass)
            {
                return(null);
            }
            ZMemberInfo zmember = BaseZType.SearchZMember(name);

            if (zmember == null)
            {
                return(null);
            }
            SymbolDefMember symbol = SymbolDefMember.Create(name, zmember);

            return(symbol);
        }
Exemple #6
0
        /// <summary>
        /// 创建分组字典缓存
        /// </summary>
        /// <typeparam name="keyType">分组字典关键字类型</typeparam>
        /// <typeparam name="targetType">目标表格类型</typeparam>
        /// <typeparam name="targetModelType">目标模型类型</typeparam>
        /// <typeparam name="targetMemberCacheType">目标缓存绑定类型</typeparam>
        /// <typeparam name="valueKeyType">目标数据关键字类型</typeparam>
        /// <param name="targetCache">目标缓存</param>
        /// <param name="getKey">分组字典关键字获取器</param>
        /// <param name="member">缓存字段表达式</param>
        /// <param name="getValueKey">获取数据关键字委托</param>
        /// <param name="isReset">是否绑定事件并重置数据</param>
        /// <param name="isSave">是否保存缓存对象防止被垃圾回收</param>
        /// <returns></returns>
        public MemberDictionary <valueType, modelType, keyType, valueKeyType, targetMemberCacheType> CreateMemberDictionary <keyType, targetType, targetModelType, targetMemberCacheType, valueKeyType>
            (Key <targetType, targetModelType, targetMemberCacheType, keyType> targetCache, Func <modelType, keyType> getKey
            , Expression <Func <targetMemberCacheType, Dictionary <RandomKey <valueKeyType>, valueType> > > member
            , Func <modelType, valueKeyType> getValueKey, bool isReset = true, bool isSave = true)
            where keyType : IEquatable <keyType>
            where targetType : class, targetModelType
            where targetModelType : class
            where targetMemberCacheType : class
            where valueKeyType : IEquatable <valueKeyType>
        {
            MemberDictionary <valueType, modelType, keyType, valueKeyType, targetMemberCacheType> cache = new MemberDictionary <valueType, modelType, keyType, valueKeyType, targetMemberCacheType>(this, getKey, targetCache.GetMemberCacheByKey, member, targetCache.GetAllMemberCache, getValueKey, isReset);

            if (isSave)
            {
                memberCaches.Add(cache);
            }
            return(cache);
        }
        private void AddExtensionMethods(XmlWriter writer, Object info)
        {
            MemberDictionary members = info as MemberDictionary;

            if (members == null)
            {
                return;
            }

            TypeNode type = members.Type;

            InterfaceList contracts = type.Interfaces;

            foreach (Interface contract in contracts)
            {
                List <Method> extensionMethods = null;
                if (index.TryGetValue(contract, out extensionMethods))
                {
                    foreach (Method extensionMethod in extensionMethods)
                    {
                        if (!IsExtensionMethodHidden(extensionMethod, members))
                        {
                            AddExtensionMethod(writer, type, extensionMethod, null);
                        }
                    }
                }

                if (contract.IsGeneric && (contract.TemplateArguments != null) && (contract.TemplateArguments.Count > 0))
                {
                    Interface templateContract = (Interface)ReflectionUtilities.GetTemplateType(contract);
                    TypeNode  specialization   = contract.TemplateArguments[0];
                    if (index.TryGetValue(templateContract, out extensionMethods))
                    {
                        foreach (Method extensionMethod in extensionMethods)
                        {
                            if (IsValidTemplateArgument(specialization, extensionMethod.TemplateParameters[0]))
                            {
                                if (!IsExtensionMethodHidden(extensionMethod, members))
                                {
                                    AddExtensionMethod(writer, type, extensionMethod, specialization);
                                }
                            }
                        }
                    }
                }
            }

            TypeNode comparisonType = type;

            while (comparisonType != null)
            {
                List <Method> extensionMethods = null;
                if (index.TryGetValue(comparisonType, out extensionMethods))
                {
                    foreach (Method extensionMethod in extensionMethods)
                    {
                        if (!IsExtensionMethodHidden(extensionMethod, members))
                        {
                            AddExtensionMethod(writer, type, extensionMethod, null);
                        }
                    }
                }
                if (comparisonType.IsGeneric && (comparisonType.TemplateArguments != null) && (comparisonType.TemplateArguments.Count > 0))
                {
                    TypeNode templateType   = ReflectionUtilities.GetTemplateType(comparisonType);
                    TypeNode specialization = comparisonType.TemplateArguments[0];
                    if (index.TryGetValue(templateType, out extensionMethods))
                    {
                        foreach (Method extensionMethod in extensionMethods)
                        {
                            if (IsValidTemplateArgument(specialization, extensionMethod.TemplateParameters[0]))
                            {
                                if (!IsExtensionMethodHidden(extensionMethod, members))
                                {
                                    AddExtensionMethod(writer, type, extensionMethod, specialization);
                                }
                            }
                        }
                    }
                }

                comparisonType = comparisonType.BaseType;
            }
        }
        private void WriteTypeElements(TypeNode type) {

            // collect members
            MemberDictionary members = new MemberDictionary(type, this.ApiFilter);
            if (members.Count == 0) return;

            writer.WriteStartElement("elements");
            StartElementCallbacks("elements", members);

            foreach (Member member in members) {
                writer.WriteStartElement("element");

                Member template = ReflectionUtilities.GetTemplateMember(member);
                writer.WriteAttributeString("api", namer.GetMemberName(template));

                bool write = false;

                // inherited, specialized generics get a displayed target different from the target
                // we also write out their info, since it can't be looked up anywhere
                if (!member.DeclaringType.IsStructurallyEquivalentTo(template.DeclaringType)) {
                    writer.WriteAttributeString("display-api", namer.GetMemberName(member));
                    write = true;
                }

                // if a member is from a type in a dependency assembly, write out its info, since it can't be looked up in this file
                if (!assemblyNames.ContainsKey(member.DeclaringType.DeclaringModule.ContainingAssembly.StrongName)) write = true;
                // if (Array.BinarySearch(assemblyNames, member.DeclaringType.DeclaringModule.ContainingAssembly.Name) < 0) write = true;

                if (write) WriteMember(member);

                writer.WriteEndElement();
            }

            EndElementCallbacks("elements", members);
            writer.WriteEndElement();

        }
        /// <summary>
        /// Determines whether an extension method is hidden by a member that's already defined on the type being
        /// extended.  The extension method is hidden if it has the same name, template parameters, and
        /// parameters as a defined method.
        /// </summary>
        /// <param name="extensionMethod">The extension method to compare</param>
        /// <param name="members">A dictionary of the members defined on the type being extended</param>
        /// <returns>True if hidden, false if not</returns>
        private static bool IsExtensionMethodHidden(Method extensionMethod, MemberDictionary members)
        {
            if(!members.MemberNames.Contains(extensionMethod.Name.Name))
                return false;

            // Get a list of members with the same name as the extension method
            foreach(Member member in members[extensionMethod.Name.Name])
            {
                // The hiding member must be a method
                if(member.NodeType != NodeType.Method)
                    continue;

                Method method = (Method)member;

                // Do the generic template parameters of both methods match?
                if(!method.TemplateParametersMatch(extensionMethod.TemplateParameters))
                    continue;

                // !EFW - Don't exclude the first parameter, it does need to be included.
                // Do both methods have the same number of parameters?
                if(method.Parameters.Count != extensionMethod.Parameters.Count)
                    continue;

                // Do the parameter types of both methods match?
                if(DoParameterTypesMatch(extensionMethod.Parameters, method.Parameters))
                    return true;
            }
            return false;
        }
        /// <summary>
        /// Determines whether an extension method is hidden by a member that's already defined on the type being
        /// extended.  The extension method is hidden if it has the same name, template parameters, and
        /// parameters as a defined method.
        /// </summary>
        /// <param name="extensionMethod">The extension method to compare</param>
        /// <param name="members">A dictionary of the members defined on the type being extended</param>
        /// <returns>True if hidden, false if not</returns>
        private static bool IsExtensionMethodHidden(Method extensionMethod, MemberDictionary members)
        {
            if(!members.MemberNames.Contains(extensionMethod.Name.Name))
                return false;

            // Get a list of members with the same name as the extension method
            foreach(Member member in members[extensionMethod.Name.Name])
            {
                // The hiding member must be a method
                if(member.NodeType != NodeType.Method)
                    continue;

                Method method = (Method)member;

                // Do the generic template parameters of both methods match?
                if(!method.TemplateParametersMatch(extensionMethod.TemplateParameters))
                    continue;

                // Do both methods have the same number of parameters (not counting the extension method's first
                // parameter which identifies the extended type)?
                if(method.Parameters.Count != extensionMethod.Parameters.Count - 1)
                    continue;

                // Do the parameter types of both methods match?
                if(DoParameterTypesMatch(extensionMethod.Parameters, method.Parameters))
                    return true;
            }
            return false;
        }
Exemple #11
0
        /// <summary>
        /// Write out the elements for a type
        /// </summary>
        /// <param name="type">The type for which to write out elements</param>
        private void WriteTypeElements(TypeNode type)
        {
            MemberDictionary members = new MemberDictionary(type, this.ApiFilter);

            if(members.Count != 0)
            {
                writer.WriteStartElement("elements");
                this.StartElementCallbacks("elements", members);

                foreach(Member member in members)
                {
                    writer.WriteStartElement("element");

                    Member template = member.GetTemplateMember();

                    // !EFW - Change from ComponentOne
                    writer.WriteAttributeString("api", namer.GetMemberName(template).TranslateToValidXmlValue());

                    bool write = false;

                    // Inherited, specialized generics get a displayed target different from the target.  We also
                    // write out their info since it can't be looked up anywhere.
                    if(!member.DeclaringType.IsStructurallyEquivalentTo(template.DeclaringType))
                    {
                        // !EFW - Change from ComponentOne
                        writer.WriteAttributeString("display-api", namer.GetMemberName(member).TranslateToValidXmlValue());
                        write = true;
                    }

                    // If a member is from a type in a dependency assembly, write out its info, since it can't be
                    // looked up in this file.
                    if(!assemblyNames.Contains(member.DeclaringType.DeclaringModule.ContainingAssembly.StrongName))
                        write = true;

                    if(write)
                        this.WriteMember(member);

                    writer.WriteEndElement();
                }

                this.EndElementCallbacks("elements", members);
                writer.WriteEndElement();
            }
        }