예제 #1
0
        static public long ToNumber(Link link)
        {
            if (link == Net.Zero)
            {
                return(0);
            }
            else if (link == Net.One)
            {
                return(1);
            }
            else if (link.IsSum())
            {
                List <Link> numberParts = LinkConverter.ToList(link.Target);

                long number = 0;
                for (int i = 0; i < numberParts.Count; i++)
                {
                    long numberPart;
                    GoDownAndTakeIt(numberParts[i], out numberPart);
                    number += numberPart;
                }

                return(number);
            }
            else
            {
                throw new ArgumentOutOfRangeException("link", "Specified link is not a number.");
            }
        }
예제 #2
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);
                }
            }
        }