Exemple #1
0
            public static string BuildMemberReferenceComment(ICodeTranslationOptions options, IMember member)
            {
                if (options == null)
                {
                    throw new ArgumentNullException("options");
                }
                string parentCref = ((IType)member.ParentTarget).GetTypeName(options, true);

                //If there is a build trail to go by, check to see what kind of scope
                //is available.  If the parent of the field is available, then referencing
                //field should be easier.
                if (options.BuildTrail != null)
                {
                    IDeclarationTarget idt = member.ParentTarget;
                    while (idt != null && !(idt is INameSpaceDeclaration))
                    {
                        idt = idt.ParentTarget;
                    }
                    INameSpaceDeclaration currentNameSpace = null;
                    bool importsContainsNameSpace          = false;
                    if (idt != null && options.ImportList != null)
                    {
                        importsContainsNameSpace = options.ImportList.Contains(((INameSpaceDeclaration)(idt)).FullName);
                    }
                    if (!importsContainsNameSpace)
                    {
                        for (int i = 0; i < options.BuildTrail.Count; i++)
                        {
                            if (Special.GetThisAt(options.BuildTrail, i) is INameSpaceDeclaration)
                            {
                                currentNameSpace = (INameSpaceDeclaration)Special.GetThisAt(options.BuildTrail, i);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (currentNameSpace != null && idt != null && (currentNameSpace.FullName == ((INameSpaceDeclaration)idt).FullName || currentNameSpace.FullName.Contains(((INameSpaceDeclaration)idt).FullName + ".")))
                    {
                        /* *
                         * The build trail's current namespace contains the full name of the
                         * parent namespace.
                         * */
                        parentCref = parentCref.Substring(currentNameSpace.FullName.Length + 1);
                    }
                    else if (importsContainsNameSpace)
                    {
                        /* *
                         * The import list contains the namespace
                         * */
                        parentCref = parentCref.Substring(((INameSpaceDeclaration)idt).FullName.Length + 1);
                    }
                    else
                    {
                        goto _verbose;
                    }
                }
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));

_verbose:
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));
            }