示例#1
0
        private string GetMethodDefinitionName(MethodReference method, string name)
        {
            StringBuilder buf = new StringBuilder();

            buf.Append(GetTypeName(method.DeclaringType));
            buf.Append('.');
            buf.Append(name.Replace(".", "#"));
            if (method.IsGenericMethod())
            {
                IList <GenericParameter> genArgs = method.GenericParameters;
                if (genArgs.Count > 0)
                {
                    buf.Append("``").Append(genArgs.Count);
                }
            }
            IList <ParameterDefinition> parameters = method.Parameters;

            try
            {
                genDeclType   = method.DeclaringType;
                genDeclMethod = method;
                AppendParameters(buf, method.DeclaringType.GenericParameters, parameters);
            }
            finally
            {
                genDeclType   = null;
                genDeclMethod = null;
            }
            return(buf.ToString());
        }
 protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
 {
     if (type is GenericParameter)
     {
         int l = buf.Length;
         if (genDeclType != null)
         {
             IList <GenericParameter> genArgs = genDeclType.GenericParameters;
             for (int i = 0; i < genArgs.Count; ++i)
             {
                 if (genArgs[i].Name == type.Name)
                 {
                     buf.Append('`').Append(i);
                     break;
                 }
             }
         }
         if (genDeclMethod != null)
         {
             IList <GenericParameter> genArgs = null;
             if (genDeclMethod.IsGenericMethod())
             {
                 genArgs = genDeclMethod.GenericParameters;
                 for (int i = 0; i < genArgs.Count; ++i)
                 {
                     if (genArgs[i].Name == type.Name)
                     {
                         buf.Append("``").Append(i);
                         break;
                     }
                 }
             }
         }
         if ((genDeclType == null && genDeclMethod == null) || buf.Length == l)
         {
             // Probably from within an explicitly implemented interface member,
             // where CSC uses parameter names instead of indices (why?), e.g.
             // MyList`2.Mono#DocTest#Generic#IFoo{A}#Method``1(`0,``0) instead of
             // MyList`2.Mono#DocTest#Generic#IFoo{`0}#Method``1(`0,``0).
             buf.Append(type.Name);
         }
     }
     else
     {
         base.AppendTypeName(buf, type, context);
         if (AddTypeCount)
         {
             int numArgs = type.GenericParameters.Count;
             if (type.DeclaringType != null)
             {
                 numArgs -= type.GenericParameters.Count;
             }
             if (numArgs > 0)
             {
                 buf.Append('`').Append(numArgs);
             }
         }
     }
     return(buf);
 }
示例#3
0
        void SetMemberInfo(MemberReference member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }
            ReturnIsReturn = true;
            AddRemarks     = true;
            Member         = member;

            if (member is MethodReference)
            {
                MethodReference mr = (MethodReference)member;
                Parameters = mr.Parameters;
                if (mr.IsGenericMethod())
                {
                    GenericParameters = new List <GenericParameter> (mr.GenericParameters);
                }
            }
            else if (member is PropertyDefinition)
            {
                Parameters = ((PropertyDefinition)member).Parameters;
            }

            if (member is MethodDefinition)
            {
                ReturnType = ((MethodDefinition)member).ReturnType;
            }
            else if (member is PropertyDefinition)
            {
                ReturnType     = ((PropertyDefinition)member).PropertyType;
                ReturnIsReturn = false;
            }

            // no remarks section for enum members
            if (member.DeclaringType != null && ((TypeDefinition)member.DeclaringType).IsEnum)
            {
                AddRemarks = false;
            }
        }