Пример #1
0
        static public bool TryGetName(this Link link, out string str)
        {
            if (!LinksWithNamesGatheringProcess.Add(link))
            {
                str = "...";
                return(true);
            }
            else
            {
                try
                {
                    if (link != null)
                    {
                        if (link.Linker == Net.And)
                        {
                            str = SequenceHelpers.FormatSequence(link);
                            return(true);
                        }
                        else if (link.IsGroup())
                        {
                            str = LinkConverter.ToString(LinkConverter.ToList(link.Target));
                            return(true);
                        }
                        else if (link.IsChar())
                        {
                            str = LinkConverter.ToChar(link).ToString();
                            return(true);
                        }
                        else if (TryGetSpecificName(link, out str))
                        {
                            return(true);
                        }

                        if (link.Source == link || link.Linker == link || link.Target == link)
                        {
                            return(false);
                        }

                        string sourceName, linkerName, targetName;
                        if (TryGetName(link.Source, out sourceName) && TryGetName(link.Linker, out linkerName) && TryGetName(link.Target, out targetName))
                        {
                            var sb = new StringBuilder();
                            sb.Append(sourceName).Append(' ').Append(linkerName).Append(' ').Append(targetName);
                            str = sb.ToString();
                            return(true);
                        }
                    }
                    str = null;
                    return(false);
                }
                finally
                {
                    LinksWithNamesGatheringProcess.Remove(link);
                }
            }
        }
Пример #2
0
        static public bool TryGetSpecificName(this Link link, out string name)
        {
            string nameLocal = null;

            if (Net.Name.ReferersBySourceCount < link.ReferersBySourceCount)
            {
                Net.Name.WalkThroughReferersBySource(referer =>
                {
                    if (referer.Linker == Net.ThatIsRepresentedBy)
                    {
                        if (Link.Exists(link, Net.Has, referer))
                        {
                            nameLocal = LinkConverter.ToString(referer.Target);
                            return(false);                            // Останавливаем проход
                        }
                    }
                    return(true);
                });
            }
            else
            {
                link.WalkThroughReferersBySource(referer =>
                {
                    if (referer.Linker == Net.Has)
                    {
                        Link nameLink = referer.Target;
                        if (nameLink.Source == Net.Name && nameLink.Linker == Net.ThatIsRepresentedBy)
                        {
                            nameLocal = LinkConverter.ToString(nameLink.Target);
                            return(false);                            // Останавливаем проход
                        }
                    }
                    return(true);
                });
            }

            name = nameLocal;
            return(nameLocal != null);
        }