Ejemplo n.º 1
0
        /// <summary>
        /// Thiashd iahsd haishd iashd ihasih iqwhei hqie hwqih eoqwh eoqwihe oashd
        /// oasihd o oiahsd oihasd oihawoidh aowihd oaihd oiahsoid had asd .as.d as. d
        /// as.d a sd as.
        /// </summary>
        /// <param name="fieldDefinition"></param>
        /// <param name="declaringType"></param>
        public MyFieldInfo(FieldDefinition fieldDefinition, MyClassInfo declaringType)
            : base()
        {
            this.name = fieldDefinition.Name;

            string[] readableForms = Tools.GetHumanReadableForms(fieldDefinition.FieldType);

            this.typeFullName = readableForms[0];
            this.typeFullNameWithoutRevArrayStrings = readableForms[1];
            this.attributes    = GetMyFieldAttributes(fieldDefinition);
            this.declaringType = declaringType;

            if ((fieldDefinition.Attributes & FieldAttributes.HasDefault) != 0)
            {
                try
                {
                    object rawConstant = fieldDefinition.Constant;

                    defaultValue = rawConstant == null ? null : rawConstant.ToString();
                }
                catch (Exception)
                {
                    Logger.Warning("Couldn't obtain default value for field '{0}'.", name);
                }
            }

            this.CheckSupport(fieldDefinition.Attributes);
        }
Ejemplo n.º 2
0
        public MyPropertyInfo(PropertyDefinition propertyDefinition, MyClassInfo declaringType)
            : base()
        {
            this.name = propertyDefinition.Name;

            string[] readableForms = Tools.GetHumanReadableForms(propertyDefinition.PropertyType);

            this.typeFullName = readableForms[0];
            this.typeFullNameWithoutRevArrayStrings = readableForms[1];
            this.declaringType = declaringType;

            MethodDefinition getterInfo = propertyDefinition.GetMethod;
            MethodDefinition setterInfo = propertyDefinition.SetMethod;

            this.hasGetter = getterInfo != null;
            this.hasSetter = setterInfo != null;

            MethodDefinition getterOrSetterInfo = getterInfo != null ? getterInfo : setterInfo;

            Debug.Assert(getterOrSetterInfo != null, "Impossible! Property must have either getter or setter or both.");

            this.attributes = GetMyPropertyAttributes(propertyDefinition);
            this.underlyingMethodsAttributes = GetMyInvokableMemberAttributes(getterOrSetterInfo);

            this.parametersNames = new List <string>();
            this.parameters      = new Dictionary <string, MyParameterInfo>();

            this.exceptionsDescrs = new List <ExceptionDescr>();

            AddParameters(getterInfo, setterInfo);

            this.CheckSupport(propertyDefinition.Attributes, getterOrSetterInfo.Attributes);
        }
Ejemplo n.º 3
0
        public MyEventInfo FindEvent(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);
            }

            MyEventInfo myEventInfo = null;

            foreach (ClassMembersGroups classMembersGroup in new ClassMembersGroups[] { ClassMembersGroups.PublicEvents, ClassMembersGroups.ProtectedEvents, ClassMembersGroups.InternalEvents, ClassMembersGroups.ProtectedInternalEvents, ClassMembersGroups.PrivateEvents })
            {
                myEventInfo = memberDeclaringType.GetMember(classMembersGroup, memberName) as MyEventInfo;

                if (myEventInfo != null)
                {
                    return(myEventInfo);
                }
            }

            return(myEventInfo);
        }
Ejemplo n.º 4
0
        public MyPropertyInfo FindProperty(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);
            }

            foreach (ClassMembersGroups classMembersGroup in new ClassMembersGroups[] { ClassMembersGroups.PublicPropertiesOverloads, ClassMembersGroups.ProtectedPropertiesOverloads, ClassMembersGroups.InternalPropertiesOverloads, ClassMembersGroups.ProtectedInternalPropertiesOverloads, ClassMembersGroups.PrivatePropertiesOverloads })
            {
                MyPropertiesOverloadsInfo properties = memberDeclaringType.GetMember(classMembersGroup, memberName) as MyPropertiesOverloadsInfo;

                if (properties == null)
                {
                    continue;
                }

                List <string> paramsTypes = SplitXmlParamsString(paramsStr);

                foreach (MyPropertyInfo myPropertyInfo in properties)
                {
                    if (SignaturesMatch(myPropertyInfo.ParametersNames, myPropertyInfo.Parameters, paramsTypes, memberDeclaringType, null))
                    {
                        return(myPropertyInfo);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        public MyConstructorInfo(MethodDefinition constructorDefinition, MyClassInfo declaringType)
            : base(constructorDefinition, declaringType)
        {
            this.name = declaringType.Name;

            this.CheckSupport(constructorDefinition.Attributes);

            AddParameters(constructorDefinition.Parameters);
        }
Ejemplo n.º 6
0
        protected MyInvokableMemberInfo(MethodDefinition methodDefinition, MyClassInfo declaringType)
        {
            this.attributes    = GetMyInvokableMemberAttributes(methodDefinition);
            this.declaringType = declaringType;

            this.summary = String.Empty;

            this.parametersNames = new List <string>();
            this.parameters      = new Dictionary <string, MyParameterInfo>();

            this.exceptionsDescrs = new List <ExceptionDescr>();
        }
Ejemplo n.º 7
0
        private void AddGenericNameMappingIfNeeded(MyClassInfo myClassInfo, NamespaceMembersGroups namespaceMembersGroupType)
        {
            if (!myClassInfo.Name.Contains("<"))
            {
                return;
            }

            Dictionary <string, string> genericNamesMappingsForGroup = GetGenericNamesMappingsForGroup(namespaceMembersGroupType);
            string xmlName = Utils.ConvertNameToXmlDocForm(myClassInfo.Name);

            genericNamesMappingsForGroup[xmlName] = myClassInfo.Name;
        }
Ejemplo n.º 8
0
        public ExceptionDescr(string exceptionCref, string condition)
        {
            if (exceptionCref == null)
            {
                throw new ArgumentNullException("exceptionCref");
            }

            if (condition == null)
            {
                throw new ArgumentNullException("condition");
            }

            this.exceptionClassInfo = null;
            this.typeFullName       = exceptionCref;
            this.condition          = condition;
        }
Ejemplo n.º 9
0
        private static string GetAlmostCSRepresentation(string xmlParamType, MyClassInfo memberDeclaringType, List <MyGenericParameterInfo> memberGenericParameters)
        {
            string result;

            if (xmlParamType.Contains("`"))
            {
                // resolve generic parameters

                result = new MatchEvaluatorWrapper(memberDeclaringType, memberGenericParameters).Process(xmlParamType);
            }
            else
            {
                result = xmlParamType;
            }

            return(result.Replace('{', '<').Replace('}', '>'));
        }
Ejemplo n.º 10
0
        public MyEventInfo(EventDefinition eventDefinition, MyClassInfo declaringType)
            : base()
        {
            this.name = eventDefinition.Name;

            string[] readableForms = Tools.GetHumanReadableForms(eventDefinition.EventType);
            this.typeFullName = readableForms[0];
            this.typeFullNameWithoutRevArrayStrings = readableForms[1];

            this.declaringType = declaringType;

            MethodDefinition adderInfo = eventDefinition.AddMethod;

            Debug.Assert(adderInfo != null, "Impossible! add_Event() must have been generated.");

            this.attributes = GetMyEventAttributes(eventDefinition);
            this.underlyingMethodsAttributes = GetMyInvokableMemberAttributes(adderInfo);

            this.CheckSupport(eventDefinition, adderInfo.Attributes);
        }
Ejemplo n.º 11
0
        public ExceptionDescr(MyClassInfo exceptionClassInfo, string condition)
        {
            if (exceptionClassInfo == null)
            {
                throw new ArgumentNullException("exceptionClassInfo");
            }

            if (condition == null)
            {
                throw new ArgumentNullException("condition");
            }

            if (exceptionClassInfo.Namespace == null || exceptionClassInfo.Namespace == "")
            {
                this.typeFullName = exceptionClassInfo.Name;
            }
            else
            {
                this.typeFullName = exceptionClassInfo.Namespace + "." + exceptionClassInfo.Name;
            }

            this.exceptionClassInfo = exceptionClassInfo;
            this.condition          = condition;
        }
Ejemplo n.º 12
0
        public MyMethodInfo(MethodDefinition methodDefinition, MyClassInfo declaringType)
            : base(methodDefinition, declaringType)
        {
            this.name = null;

            if ((methodDefinition.Attributes & MethodAttributes.SpecialName) != 0)
            {
                if (MethodsNamesMappings.ContainsKey(methodDefinition.Name))
                {
                    this.name = MethodsNamesMappings[methodDefinition.Name];
                }
            }

            if (this.name == null)
            {
                this.name = methodDefinition.Name;
            }

            if (Utils.IsGenericMethod(methodDefinition))
            {
                Tools.ExamineGenericParameters(methodDefinition.GenericParameters, null, out genericParameters);
            }

            if (genericParameters != null && genericParameters.Count > 0)
            {
                this.name += Tools.CreateFormalGenericParametersString(genericParameters);
            }

            string[] readableForms = Tools.GetHumanReadableForms(methodDefinition.ReturnType.ReturnType);
            this.returnTypeFullName = readableForms[0];
            this.returnTypeFullNameWithoutRevArrayStrings = readableForms[1];

            this.CheckSupport(methodDefinition.Attributes);

            AddParameters(methodDefinition.Parameters);
        }
Ejemplo n.º 13
0
        public MyNestedTypeInfo(TypeDefinition typeDefinition, MyClassInfo declaringType)
            : base()
        {
            Debug.Assert(Utils.IsTypeNested(typeDefinition), "Impossible! Given type is not a nested type.");

            string[] readableForms = Tools.GetHumanReadableForms(typeDefinition);
            this.name = readableForms[0];

            int indexOfLastSlash = this.name.LastIndexOf('/');

            Debug.Assert(indexOfLastSlash != -1 && indexOfLastSlash + 1 < this.Name.Length, "Impossible! This is a nested type.");

            this.name = this.name.Substring(indexOfLastSlash + 1);

            this.attributes    = MyClassInfo.GetMyClassAttributes(typeDefinition);
            this.declaringType = declaringType;

            this.metaType = GetMetaType(typeDefinition);

            if (metaType == NestedTypes.Unknown)
            {
                Logger.Warning("Unrecognized meta type of '{0}'", typeDefinition.FullName);
            }
        }
Ejemplo n.º 14
0
        public void AddType(TypeDefinition typeDefinition)
        {
            if (typeDefinition.IsClass && !Utils.IsDelegate(typeDefinition))
            {
                MyClassInfo myClassInfo = new MyClassInfo(typeDefinition, assemblyName);
                Dictionary <string, MetaClass> membersGroup;
                NamespaceMembersGroups         namespaceMembersGroupType;

                if (myClassInfo.IsPublic)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PublicClasses;
                }
                else if (myClassInfo.IsProtectedInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInternalClasses;
                }
                else if (myClassInfo.IsProtected)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedClasses;
                }
                else if (myClassInfo.IsInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.InternalClasses;
                }
                else if (myClassInfo.IsPrivate)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PrivateClasses;
                }
                else
                {
                    Debug.Assert(false, "Impossible! Visibility of a type is not supported.");
                    return;
                }

                membersGroup = GetMembersGroup(namespaceMembersGroupType);

                if (!membersGroup.ContainsKey(myClassInfo.Name))
                {
                    membersGroup.Add(myClassInfo.Name, myClassInfo);

                    AddGenericNameMappingIfNeeded(myClassInfo, namespaceMembersGroupType);
                }
                else
                {
                    Logger.Warning("Class named '{0}' has already been added to namespace {1}.", myClassInfo.Name, name);
                }
            }
            else if (typeDefinition.IsValueType && !typeDefinition.IsEnum)
            {
                MyStructureInfo myStructureInfo = new MyStructureInfo(typeDefinition, assemblyName);
                Dictionary <string, MetaClass> membersGroup;
                NamespaceMembersGroups         namespaceMembersGroupType;

                if (myStructureInfo.IsPublic)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PublicStructures;
                }
                else if (myStructureInfo.IsProtectedInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInternalStructures;
                }
                else if (myStructureInfo.IsProtected)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedStructures;
                }
                else if (myStructureInfo.IsInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.InternalStructures;
                }
                else if (myStructureInfo.IsPrivate)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PrivateStructures;
                }
                else
                {
                    Debug.Assert(false, "Impossible! Visibility of a type is not supported.");
                    return;
                }

                membersGroup = GetMembersGroup(namespaceMembersGroupType);

                if (!membersGroup.ContainsKey(myStructureInfo.Name))
                {
                    membersGroup.Add(myStructureInfo.Name, myStructureInfo);

                    AddGenericNameMappingIfNeeded(myStructureInfo, namespaceMembersGroupType);
                }
                else
                {
                    Logger.Warning("Structure named '{0}' has already been added to namespace {1}.", myStructureInfo.Name, name);
                }
            }
            else if (typeDefinition.IsInterface)
            {
                MyInterfaceInfo myInterfaceInfo = new MyInterfaceInfo(typeDefinition, assemblyName);
                Dictionary <string, MetaClass> membersGroup;
                NamespaceMembersGroups         namespaceMembersGroupType;

                if (myInterfaceInfo.IsPublic)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PublicInterfaces;
                }
                else if (myInterfaceInfo.IsProtectedInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInternalInterfaces;
                }
                else if (myInterfaceInfo.IsProtected)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInterfaces;
                }
                else if (myInterfaceInfo.IsInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.InternalInterfaces;
                }
                else if (myInterfaceInfo.IsPrivate)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PrivateInterfaces;
                }
                else
                {
                    Debug.Assert(false, "Impossible! Visibility of a type is not supported.");
                    return;
                }

                membersGroup = GetMembersGroup(namespaceMembersGroupType);

                if (!membersGroup.ContainsKey(myInterfaceInfo.Name))
                {
                    membersGroup.Add(myInterfaceInfo.Name, myInterfaceInfo);

                    AddGenericNameMappingIfNeeded(myInterfaceInfo, namespaceMembersGroupType);
                }
                else
                {
                    Logger.Warning("Interface named '{0}' has already been added to namespace {1}.", myInterfaceInfo.Name, name);
                }
            }
            else if (typeDefinition.IsEnum)
            {
                MyEnumerationInfo myEnumerationInfo = new MyEnumerationInfo(typeDefinition, assemblyName);
                Dictionary <string, MetaClass> membersGroup;
                NamespaceMembersGroups         namespaceMembersGroupType;

                if (myEnumerationInfo.IsPublic)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PublicEnumerations;
                }
                else if (myEnumerationInfo.IsProtectedInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInternalEnumerations;
                }
                else if (myEnumerationInfo.IsProtected)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedEnumerations;
                }
                else if (myEnumerationInfo.IsInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.InternalEnumerations;
                }
                else if (myEnumerationInfo.IsPrivate)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PrivateEnumerations;
                }
                else
                {
                    Debug.Assert(false, "Impossible! Visibility of a type is not supported.");
                    return;
                }

                membersGroup = GetMembersGroup(namespaceMembersGroupType);

                if (!membersGroup.ContainsKey(myEnumerationInfo.Name))
                {
                    membersGroup.Add(myEnumerationInfo.Name, myEnumerationInfo);

                    AddGenericNameMappingIfNeeded(myEnumerationInfo, namespaceMembersGroupType);
                }
                else
                {
                    Logger.Warning("Enumeration named '{0}' has already been added to namespace {1}.", myEnumerationInfo.Name, name);
                }
            }
            else if (Utils.IsDelegate(typeDefinition))
            {
                MyDelegateInfo myDelegateInfo = new MyDelegateInfo(typeDefinition, assemblyName);
                Dictionary <string, MetaClass> membersGroup;
                NamespaceMembersGroups         namespaceMembersGroupType;

                if (myDelegateInfo.IsPublic)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PublicDelegates;
                }
                else if (myDelegateInfo.IsProtectedInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedInternalDelegates;
                }
                else if (myDelegateInfo.IsProtected)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.ProtectedDelegates;
                }
                else if (myDelegateInfo.IsInternal)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.InternalDelegates;
                }
                else if (myDelegateInfo.IsPrivate)
                {
                    namespaceMembersGroupType = NamespaceMembersGroups.PrivateDelegates;
                }
                else
                {
                    Debug.Assert(false, "Impossible! Visibility of a type is not supported.");
                    return;
                }

                membersGroup = GetMembersGroup(namespaceMembersGroupType);

                if (!membersGroup.ContainsKey(myDelegateInfo.Name))
                {
                    membersGroup.Add(myDelegateInfo.Name, myDelegateInfo);

                    AddGenericNameMappingIfNeeded(myDelegateInfo, namespaceMembersGroupType);
                }
                else
                {
                    Logger.Warning("Delegate named '{0}' has already been added to namespace {1}.", myDelegateInfo.Name, name);
                }
            }
            else
            {
                Logger.Warning("Unrecognized type: {0}.", typeDefinition.FullName);
            }
        }
Ejemplo n.º 15
0
        private static bool SignaturesMatch(List <String> memberParametersNames, Dictionary <string, MyParameterInfo> memberParameters, List <string> xmlParamsTypes, MyClassInfo memberDeclaringType, List <MyGenericParameterInfo> memberGenericParameters)
        {
            if (memberParametersNames.Count != xmlParamsTypes.Count)
            {
                return(false);
            }

            bool signaturesMatch = true;
            int  i = 0;

            foreach (string paramName in memberParametersNames)
            {
                MyParameterInfo myParameterInfo = memberParameters[paramName];

                string almostXmlRepresentation = myParameterInfo.GetXMLCompatibleRepresentation();
                string almostCSRepresentation  = GetAlmostCSRepresentation(xmlParamsTypes[i], memberDeclaringType, memberGenericParameters);

                if (almostXmlRepresentation != almostCSRepresentation)
                {
                    signaturesMatch = false;
                    break;
                }

                i++;
            }

            return(signaturesMatch);
        }
Ejemplo n.º 16
0
        private MyClassInfo ExtractTypeMemberInfo(string xmlMemberId, bool global, out string memberName, out string paramsStr, out string returnTypeFullName)
        {
            memberName         = null;
            paramsStr          = null;
            returnTypeFullName = null;

            string fullMemberName;

            int indexOfLastTilde = xmlMemberId.LastIndexOf('~');

            if (indexOfLastTilde != -1)
            {
                if (indexOfLastTilde + 1 >= xmlMemberId.Length)
                {
                    Logger.Warning("(XML) Malformed member ID: '{0}'.", xmlMemberId);
                    return(null);
                }

                returnTypeFullName = xmlMemberId.Substring(indexOfLastTilde + 1);
                xmlMemberId        = xmlMemberId.Substring(0, indexOfLastTilde);
            }

            int indexOfOpeningBrace = xmlMemberId.IndexOf('(');

            if (indexOfOpeningBrace != -1)
            {
                if (indexOfOpeningBrace + 1 >= xmlMemberId.Length)
                {
                    Logger.Warning("(XML) Malformed member ID: '{0}'.", xmlMemberId);
                    return(null);
                }

                paramsStr      = xmlMemberId.Substring(indexOfOpeningBrace + 1, xmlMemberId.Length - indexOfOpeningBrace - 2);
                fullMemberName = xmlMemberId.Substring(0, indexOfOpeningBrace);
            }
            else // no params
            {
                fullMemberName = xmlMemberId;
            }

            int indexOfLastDot = fullMemberName.LastIndexOf('.');

            if (indexOfLastDot == -1 || indexOfLastDot + 1 >= fullMemberName.Length)
            {
                Logger.Warning("(XML) Malformed member ID: '{0}'.", xmlMemberId);
                return(null);
            }

            string      declaringTypeXmlId = fullMemberName.Substring(0, indexOfLastDot);
            MyClassInfo declaringType      = null;

            if (global)
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assembliesInfo.Assemblies)
                {
                    declaringType = myAssemblyInfo.FindNamespaceMember(declaringTypeXmlId);
                    if (declaringType != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                declaringType = FindNamespaceMember(declaringTypeXmlId);
            }

            if (declaringType == null)
            {
                Logger.Warning("(XML) Couldn't find declaring type of a member with id '{0}'.", xmlMemberId);
                return(null);
            }

            memberName = fullMemberName.Substring(indexOfLastDot + 1);

            return(declaringType);
        }
Ejemplo n.º 17
0
 private static MyGenericParameterInfo FindGenericParameter(MyClassInfo myClassInfo, string typeParamName)
 {
     return(myClassInfo.FindGenericParameter(typeParamName));
 }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        private MyClassInfo FindGlobalNamespaceMember(string xmlMemberId)
        {
            int indexOfDot = -1;

            while (true)
            {
                string potentialNamespace;
                string potentialMemberName;

                indexOfDot = xmlMemberId.IndexOf('.', indexOfDot + 1);
                if (indexOfDot == -1)
                {
                    potentialNamespace = MyNamespaceInfo.GLOBAL_NAMESPACE_NAME;
                }
                else
                {
                    potentialNamespace = xmlMemberId.Substring(0, indexOfDot);
                }

                List <MyNamespaceInfo> namespacesInfos = assembliesInfo.FindNamespaces(potentialNamespace);
                if (namespacesInfos.Count == 0)
                {
                    if (indexOfDot == -1)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                if (indexOfDot + 1 < xmlMemberId.Length)
                {
                    potentialMemberName = xmlMemberId.Substring(indexOfDot + 1).Replace('.', '/');
                }
                else
                {
                    Logger.Warning("(XML) Malformed member ID: '{0}'.", xmlMemberId);
                    continue;
                }

                foreach (MyNamespaceInfo myNamespaceInfo in namespacesInfos)
                {
                    int namespaceMembersGroupTypeIndex = 0;
                    while (Enum.IsDefined(typeof(NamespaceMembersGroups), namespaceMembersGroupTypeIndex))
                    {
                        NamespaceMembersGroups namespaceMembersGroupType = (NamespaceMembersGroups)namespaceMembersGroupTypeIndex;
                        MyClassInfo            namespaceMember           = myNamespaceInfo.FindMember(namespaceMembersGroupType, potentialMemberName);

                        if (namespaceMember != null)
                        {
                            return(namespaceMember);
                        }

                        namespaceMembersGroupTypeIndex++;
                    }
                }

                if (indexOfDot == -1)
                {
                    break;
                }
            }

            return(null);
        }
Ejemplo n.º 20
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;
            }
            }
        }
Ejemplo n.º 21
0
        private static bool ReturnTypesMatch(string csTypeFullName, string xmlTypeFullName, MyClassInfo memberDeclaringType, List <MyGenericParameterInfo> memberGenericParameters)
        {
            string almostXmlRepresentation = MyParameterInfo.GetXMLCompatibleRepresentation(csTypeFullName, false, false);
            string almostCSRepresentation  = GetAlmostCSRepresentation(xmlTypeFullName, memberDeclaringType, memberGenericParameters);

            return(almostXmlRepresentation == almostCSRepresentation);
        }
Ejemplo n.º 22
0
        internal MetaClass FindMember(string xmlMemberId)
        {
            char memberType = xmlMemberId[0];

            xmlMemberId = xmlMemberId.Substring(2);

            switch (memberType)
            {
            case 'T':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyClassInfo myClassInfo = myAssemblyInfo.FindNamespaceMember(xmlMemberId);

                    if (myClassInfo != null)
                    {
                        return(myClassInfo);
                    }
                }

                break;
            }

            case 'M':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyInvokableMemberInfo myInvokableMemberInfo = myAssemblyInfo.FindMethodOrConstructor(xmlMemberId, true);

                    if (myInvokableMemberInfo != null)
                    {
                        return(myInvokableMemberInfo);
                    }
                }

                break;
            }

            case 'F':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyFieldInfo myFieldInfo = myAssemblyInfo.FindField(xmlMemberId, true);

                    if (myFieldInfo != null)
                    {
                        return(myFieldInfo);
                    }
                }

                break;
            }

            case 'P':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyPropertyInfo myPropertyInfo = myAssemblyInfo.FindProperty(xmlMemberId, true);

                    if (myPropertyInfo != null)
                    {
                        return(myPropertyInfo);
                    }
                }

                break;
            }

            case 'E':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyEventInfo myEventInfo = myAssemblyInfo.FindEvent(xmlMemberId, true);

                    if (myEventInfo != null)
                    {
                        return(myEventInfo);
                    }
                }

                break;
            }

            case 'N':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyNamespaceInfo myNamespaceInfo = myAssemblyInfo.FindNamespace(xmlMemberId);

                    if (myNamespaceInfo != null)
                    {
                        return(myNamespaceInfo);
                    }
                }

                break;
            }
            }

            return(null);
        }
Ejemplo n.º 23
0
 public MatchEvaluatorWrapper(MyClassInfo memberDeclaringType, List <MyGenericParameterInfo> memberGenericParameters)
 {
     _memberDeclaringType     = memberDeclaringType;
     _memberGenericParameters = memberGenericParameters;
 }