Пример #1
0
    protected override void AddMethod(MethodDefinition methodDefinition)
    {
      if (methodDefinition.Name == "Invoke")
      {
        // skip the built-in method but read its signature

        // just temporary create MyMethodInfo instance to simplify obtaining method's signature
        // and return typeDefinition
        MyMethodInfo myMethodInfo = new MyMethodInfo(methodDefinition, this);

        returnTypeFullName = myMethodInfo.ReturnTypeFullName;

        parametersNames = new List<string>();
        parametersNames.AddRange(myMethodInfo.ParametersNames);

        parameters = new Dictionary<string, MyParameterInfo>();
        foreach (string parameterName in myMethodInfo.Parameters.Keys)
        {
          parameters[parameterName] = myMethodInfo.Parameters[parameterName];
        }
      }
    }
Пример #2
0
        protected override void AddMethod(MethodDefinition methodDefinition)
        {
            if (methodDefinition.Name == "Invoke")
            {
                // skip the built-in method but read its signature

                // just temporary create MyMethodInfo instance to simplify obtaining method's signature
                // and return typeDefinition
                MyMethodInfo myMethodInfo = new MyMethodInfo(methodDefinition, this);

                returnTypeFullName = myMethodInfo.ReturnTypeFullName;

                parametersNames = new List <string>();
                parametersNames.AddRange(myMethodInfo.ParametersNames);

                parameters = new Dictionary <string, MyParameterInfo>();
                foreach (string parameterName in myMethodInfo.Parameters.Keys)
                {
                    parameters[parameterName] = myMethodInfo.Parameters[parameterName];
                }
            }
        }
Пример #3
0
 private static MyGenericParameterInfo FindGenericParameter(MyMethodInfo myMethodInfo, string typeParamName)
 {
     return(myMethodInfo.FindGenericParameter(typeParamName));
 }
Пример #4
0
        public MyInvokableMemberInfo FindMethodOrConstructor(string xmlMemberId, bool global)
        {
            string memberName;
            string paramsStr;
            string returnTypeFullName;

            MyClassInfo memberDeclaringType = ExtractTypeMemberInfo(xmlMemberId, global, out memberName, out paramsStr, out returnTypeFullName);

            if (memberDeclaringType == null)
            {
                return(null);
            }

            bool isConstructor = false;

            if (memberName == "#ctor")
            {
                isConstructor = true;
                memberName    = memberDeclaringType.Name;
            }

            ClassMembersGroups[] constructorMembersGroups = new ClassMembersGroups[] { ClassMembersGroups.PublicConstructors, ClassMembersGroups.ProtectedConstructors, ClassMembersGroups.InternalConstructors, ClassMembersGroups.ProtectedInternalConstructors, ClassMembersGroups.PrivateConstructors };
            ClassMembersGroups[] methodMembersGroups      = new ClassMembersGroups[] { ClassMembersGroups.PublicMethodsOverloads, ClassMembersGroups.ProtectedMethodsOverloads, ClassMembersGroups.InternalMethodsOverloads, ClassMembersGroups.ProtectedInternalMethodsOverloads, ClassMembersGroups.PrivateMethodsOverloads };

            Debug.Assert(constructorMembersGroups.Length == methodMembersGroups.Length);

            for (int i = 0; i < constructorMembersGroups.Length; i++)
            {
                ClassMembersGroups classMembersGroup;

                if (isConstructor)
                {
                    classMembersGroup = constructorMembersGroups[i];
                }
                else
                {
                    classMembersGroup = methodMembersGroups[i];

                    if (MyMethodInfo.MethodsNamesMappings.ContainsKey(memberName))
                    {
                        memberName = MyMethodInfo.MethodsNamesMappings[memberName];
                    }
                }

                MyInvokableMembersOverloadsInfo invokableMembers = memberDeclaringType.GetMember(classMembersGroup, memberName) as MyInvokableMembersOverloadsInfo;

                if (invokableMembers == null)
                {
                    continue;
                }

                List <string> paramsTypes = SplitXmlParamsString(paramsStr);
                foreach (MyInvokableMemberInfo myInvokableMember in invokableMembers)
                {
                    List <MyGenericParameterInfo> memberGenericParameters = null;

                    if (!isConstructor)
                    {
                        MyMethodInfo myMethodInfo = (MyMethodInfo)myInvokableMember;

                        if (myMethodInfo.GenericParametersCount > 0)
                        {
                            memberGenericParameters = myMethodInfo.GenericParameters;
                        }
                    }

                    if (SignaturesMatch(myInvokableMember.ParametersNames, myInvokableMember.Parameters, paramsTypes, memberDeclaringType, memberGenericParameters) &&
                        (isConstructor || returnTypeFullName == null ||
                         ReturnTypesMatch(((MyMethodInfo)myInvokableMember).ReturnTypeFullNameWithoutRevArrayStrings, returnTypeFullName, memberDeclaringType, memberGenericParameters)))
                    {
                        return(myInvokableMember);
                    }
                }
            }

            return(null);
        }
Пример #5
0
        private void ProcessMemberNode(XPathNavigator memberNodeNavigator, XPathNavigator docNavigator)
        {
            string nameAttribValue = memberNodeNavigator.GetAttribute("name", "");
            string xmlMemberId     = nameAttribValue.Substring(2);
            char   memberType      = nameAttribValue[0];

            switch (memberType)
            {
            case 'T':
            {
                MyClassInfo myClassInfo = FindNamespaceMember(xmlMemberId);
                if (myClassInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate namespace member '{0}'.", xmlMemberId);

                    break;
                }

                myClassInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");
                myClassInfo.Remarks = ReadXmlNodes(memberNodeNavigator, "remarks");

                if (myClassInfo.IsNested)
                {
                    // the class/struct/etc. is a nested typeDefinition
                    int indexOfLastDot = xmlMemberId.LastIndexOf('.');
                    Debug.Assert(indexOfLastDot != -1, "There must be dot because this type is nested.");

                    string      declaringTypeFullName = xmlMemberId.Substring(0, indexOfLastDot);
                    MyClassInfo declaringType         = FindNamespaceMember(declaringTypeFullName);
                    Debug.Assert(declaringType != null, "Declaring type of a nested type must be present.");

                    MyNestedTypeInfo myNestedTypeInfo = declaringType.GetNestedTypeMember(myClassInfo);
                    Debug.Assert(myNestedTypeInfo != null, "Impossible! This nested type must be there.");

                    myNestedTypeInfo.Summary = myClassInfo.Summary;
                }

                if (myClassInfo is MyDelegateInfo)
                {
                    MyDelegateInfo myDelegateInfo = (MyDelegateInfo)myClassInfo;

                    // returns node
                    string returnValueSummary = ReadXmlNodes(memberNodeNavigator, "returns");

                    if (myDelegateInfo.ReturnTypeFullName.ToLower() != "system.void")
                    {
                        myDelegateInfo.ReturnValueSummary = returnValueSummary;
                    }
                    else if (returnValueSummary != "")
                    {
                        Logger.Warning("(XML) There's a description of return value for delegate '{0}' but this delegate returns nothing.", xmlMemberId);
                    }

                    // param nodes
                    XPathNodeIterator paramNodes = memberNodeNavigator.Select("param");
                    while (paramNodes.MoveNext())
                    {
                        string paramName = paramNodes.Current.GetAttribute("name", "");
                        if (paramName == null)
                        {
                            Logger.Warning("(XML) Node 'param' doesn't have required attribute 'name'.");
                            continue;
                        }

                        MyParameterInfo myParameterInfo = FindParameter(myDelegateInfo, paramName);
                        if (myParameterInfo == null)
                        {
                            Logger.Warning("(XML) Node 'param' with name '{0}' referenced in XML documentation couldn't be found in method/constructor '{1}'.", paramName, xmlMemberId);
                            continue;
                        }

                        myParameterInfo.Summary = paramNodes.Current.InnerXml;
                    }
                }

                // typeparam nodes
                XPathNodeIterator typeParamNodes = memberNodeNavigator.Select("typeparam");
                while (typeParamNodes.MoveNext())
                {
                    string typeParamName = typeParamNodes.Current.GetAttribute("name", "");
                    if (typeParamName == null)
                    {
                        Logger.Warning("(XML) Node 'typeparam' doesn't have required attribute 'name'.");
                        continue;
                    }

                    MyGenericParameterInfo myGenericParameterInfo = FindGenericParameter(myClassInfo, typeParamName);
                    if (myGenericParameterInfo == null)
                    {
                        Logger.Warning("(XML) Node 'typeparam' with name '{0}' referenced in XML documentation couldn't be found in type '{1}'.", typeParamName, xmlMemberId);
                        continue;
                    }

                    myGenericParameterInfo.Summary = typeParamNodes.Current.InnerXml;
                }

                myClassInfo.Example = ReadXmlNodes(memberNodeNavigator, "example");

                break;
            }

            case 'M':
            {
                MyInvokableMemberInfo myInvokableMemberInfo = FindMethodOrConstructor(xmlMemberId);
                if (myInvokableMemberInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate invokable member '{0}'.", xmlMemberId);

                    break;
                }

                myInvokableMemberInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");
                myInvokableMemberInfo.Remarks = ReadXmlNodes(memberNodeNavigator, "remarks");

                if (myInvokableMemberInfo is MyMethodInfo)
                {
                    MyMethodInfo myMethodInfo = (MyMethodInfo)myInvokableMemberInfo;

                    // returns node
                    string returnValueSummary = ReadXmlNodes(memberNodeNavigator, "returns");

                    if (myMethodInfo.ReturnTypeFullName.ToLower() != "system.void")
                    {
                        myMethodInfo.ReturnValueSummary = returnValueSummary;
                    }
                    else if (returnValueSummary != "")
                    {
                        Logger.Warning("(XML) There's a description of return value for method '{0}' but this method/constructor returns nothing.", xmlMemberId);
                    }

                    // typeparam nodes
                    XPathNodeIterator typeParamNodes = memberNodeNavigator.Select("typeparam");
                    while (typeParamNodes.MoveNext())
                    {
                        string typeParamName = typeParamNodes.Current.GetAttribute("name", "");
                        if (typeParamName == null)
                        {
                            Logger.Warning("(XML) Node 'typeparam' doesn't have required attribute 'name'.");
                            continue;
                        }

                        MyGenericParameterInfo myGenericParameterInfo = FindGenericParameter(myMethodInfo, typeParamName);
                        if (myGenericParameterInfo == null)
                        {
                            Logger.Warning("(XML) Node 'typeparam' with name '{0}' referenced in XML documentation couldn't be found in type '{1}'.", typeParamName, xmlMemberId);
                            continue;
                        }

                        myGenericParameterInfo.Summary = typeParamNodes.Current.InnerXml;
                    }
                }

                // param nodes
                XPathNodeIterator paramNodes = memberNodeNavigator.Select("param");
                while (paramNodes.MoveNext())
                {
                    string paramName = paramNodes.Current.GetAttribute("name", "");
                    if (paramName == null)
                    {
                        Logger.Warning("(XML) Node 'param' doesn't have required attribute 'name'.");
                        continue;
                    }

                    MyParameterInfo myParameterInfo = FindParameter(myInvokableMemberInfo, paramName);
                    if (myParameterInfo == null)
                    {
                        Logger.Warning("(XML) Node 'param' with name '{0}' referenced in XML documentation couldn't be found in method/constructor '{1}'.", paramName, xmlMemberId);
                        continue;
                    }

                    myParameterInfo.Summary = paramNodes.Current.InnerXml;
                }

                // exception nodes
                XPathNodeIterator exceptionNodes = memberNodeNavigator.Select("exception");
                while (exceptionNodes.MoveNext())
                {
                    string exceptionCref = exceptionNodes.Current.GetAttribute("cref", "");
                    if (exceptionCref == null)
                    {
                        Logger.Warning("(XML) Node 'exception' doesn't have required attribute 'cref'.");
                        continue;
                    }

                    int indexOfColon = exceptionCref.IndexOf(':');
                    if (indexOfColon != -1 && indexOfColon + 1 < exceptionCref.Length)
                    {
                        exceptionCref = exceptionCref.Substring(indexOfColon + 1);
                    }

                    MyClassInfo exceptionClassInfo = FindGlobalNamespaceMember(exceptionCref);
                    if (exceptionClassInfo != null)
                    {
                        myInvokableMemberInfo.ExceptionsDescrs.Add(new ExceptionDescr(exceptionClassInfo, exceptionNodes.Current.InnerXml));
                    }
                    else
                    {
                        myInvokableMemberInfo.ExceptionsDescrs.Add(new ExceptionDescr(exceptionCref, exceptionNodes.Current.InnerXml));
                    }
                }

                // example nodes
                myInvokableMemberInfo.Example = ReadXmlNodes(memberNodeNavigator, "example");

                break;
            }

            case 'F':
            {
                MyFieldInfo myFieldInfo = FindField(xmlMemberId);
                if (myFieldInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate field '{0}'.", xmlMemberId);

                    break;
                }

                myFieldInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");
                myFieldInfo.Remarks = ReadXmlNodes(memberNodeNavigator, "remarks");
                myFieldInfo.Example = ReadXmlNodes(memberNodeNavigator, "example");

                break;
            }

            case 'P':
            {
                MyPropertyInfo myPropertyInfo = FindProperty(xmlMemberId);
                if (myPropertyInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate property '{0}'.", xmlMemberId);

                    break;
                }

                myPropertyInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");
                myPropertyInfo.Remarks = ReadXmlNodes(memberNodeNavigator, "remarks");

                string returnValueSummary = ReadXmlNodes(memberNodeNavigator, "value");
                myPropertyInfo.ReturnValueSummary = returnValueSummary;

                // param nodes
                XPathNodeIterator paramNodes = memberNodeNavigator.Select("param");
                while (paramNodes.MoveNext())
                {
                    string paramName = paramNodes.Current.GetAttribute("name", "");
                    if (paramName == null)
                    {
                        Logger.Warning("(XML) Node 'param' doesn't have required attribute 'name'.");
                        continue;
                    }

                    MyParameterInfo myParameterInfo = FindParameter(myPropertyInfo, paramName);
                    if (myParameterInfo == null)
                    {
                        Logger.Warning("(XML) Node 'param' with name '{0}' referenced in XML documentation couldn't be found in method/constructor '{1}'.", paramName, xmlMemberId);
                        continue;
                    }

                    myParameterInfo.Summary = paramNodes.Current.InnerXml;
                }

                // exception nodes
                XPathNodeIterator exceptionNodes = memberNodeNavigator.Select("exception");
                while (exceptionNodes.MoveNext())
                {
                    string exceptionCref = exceptionNodes.Current.GetAttribute("cref", "");
                    if (exceptionCref == null)
                    {
                        Logger.Warning("(XML) Node 'exception' doesn't have required attribute 'cref'.");
                        continue;
                    }

                    int indexOfColon = exceptionCref.IndexOf(':');
                    if (indexOfColon != -1 && indexOfColon + 1 < exceptionCref.Length)
                    {
                        exceptionCref = exceptionCref.Substring(indexOfColon + 1);
                    }

                    MyClassInfo exceptionClassInfo = FindGlobalNamespaceMember(exceptionCref);
                    if (exceptionClassInfo != null)
                    {
                        myPropertyInfo.ExceptionsDescrs.Add(new ExceptionDescr(exceptionClassInfo, exceptionNodes.Current.InnerXml));
                    }
                    else
                    {
                        myPropertyInfo.ExceptionsDescrs.Add(new ExceptionDescr(exceptionCref, exceptionNodes.Current.InnerXml));
                    }
                }

                myPropertyInfo.Example = ReadXmlNodes(memberNodeNavigator, "example");

                break;
            }

            case 'E':
            {
                MyEventInfo myEventInfo = FindEvent(xmlMemberId);
                if (myEventInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate event '{0}'.", xmlMemberId);

                    break;
                }

                myEventInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");
                myEventInfo.Remarks = ReadXmlNodes(memberNodeNavigator, "remarks");
                myEventInfo.Example = ReadXmlNodes(memberNodeNavigator, "example");

                break;
            }

            case '!':
            {
                // shouldn't normally happen; exclamation mark is not used in members
                // but for example in crefs

                Logger.Warning("(XML) There is a member which couldn't be resolved by Visual Studio: '{0}'.", xmlMemberId);

                break;
            }

            case 'N':
            {
                // shouldn't normally happen; namespaces can't normally have comments
                // but for example documentation files for .NET Framework contain such members (sic!)

                MyNamespaceInfo myNamespaceInfo = FindNamespace(xmlMemberId);
                if (myNamespaceInfo == null)
                {
                    Logger.Warning("(XML) Couldn't locate namespace '{0}'.", xmlMemberId);

                    break;
                }

                myNamespaceInfo.Summary = ReadXmlNodes(memberNodeNavigator, "summary");

                break;
            }

            default:
            {
                Logger.Warning("Couldn't recognize type of a member ('{0}').", memberType);

                break;
            }
            }
        }
Пример #6
0
    protected virtual void AddMethod(MethodDefinition methodDefinition)
    {
      Debug.Assert(!methodDefinition.IsConstructor);

      MyMethodInfo myMethodInfo = new MyMethodInfo(methodDefinition, this);
      Dictionary<string, MetaClass> membersGroup;
      ClassMembersGroups classMembersGroupType;

      if (myMethodInfo.IsPublic)
      {
        classMembersGroupType = ClassMembersGroups.PublicMethodsOverloads;
      }
      else if (myMethodInfo.IsProtectedInternal)
      {
        classMembersGroupType = ClassMembersGroups.ProtectedInternalMethodsOverloads;
      }
      else if (myMethodInfo.IsProtected)
      {
        classMembersGroupType = ClassMembersGroups.ProtectedMethodsOverloads;
      }
      else if (myMethodInfo.IsInternal)
      {
        classMembersGroupType = ClassMembersGroups.InternalMethodsOverloads;
      }
      else if (myMethodInfo.IsPrivate)
      {
        classMembersGroupType = ClassMembersGroups.PrivateMethodsOverloads;
      }
      else
      {
        Debug.Assert(false, "Impossible! Visibility of a member is not supported.");
        return;
      }

      membersGroup = CreateAndGetMembersGroup(classMembersGroupType);

      MyInvokableMembersOverloadsInfo methodsOverloads;
      string overloadName = myMethodInfo.Name;
      bool overloadExists = false;

      if (myMethodInfo.GenericParametersCount > 0)
      {
        overloadName = Utils.ConvertNameToXmlDocForm(myMethodInfo.Name, true);
      }

      if (membersGroup.ContainsKey(overloadName))
      {
        var tmpMethodsOverloads = (MyInvokableMembersOverloadsInfo)membersGroup[overloadName];

        overloadExists = tmpMethodsOverloads.Count > 0
                      && tmpMethodsOverloads[0] is MyMethodInfo
                      && ((MyMethodInfo)tmpMethodsOverloads[0]).GenericParametersCount == myMethodInfo.GenericParametersCount;
      }

      if (!overloadExists)
      {
        methodsOverloads = new MyInvokableMembersOverloadsInfo(myMethodInfo.Name);
        membersGroup[overloadName] = methodsOverloads;

        AddGenericNameMappingIfNeeded(myMethodInfo, classMembersGroupType);
      }
      else
      {
        methodsOverloads = (MyInvokableMembersOverloadsInfo)membersGroup[overloadName];
      }

      methodsOverloads.AddInvokableMember(myMethodInfo);
    }
Пример #7
0
 private static MyGenericParameterInfo FindGenericParameter(MyMethodInfo myMethodInfo, string typeParamName)
 {
   return myMethodInfo.FindGenericParameter(typeParamName);
 }