public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility visibility = MethodVisibility.Public;

            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethodReference = propertyDeclaration.SetMethod;
                IMethodDeclaration setMethod          = (setMethodReference == null) ? null : setMethodReference.Resolve();

                IMethodReference   getMethodReference = propertyDeclaration.GetMethod;
                IMethodDeclaration getMethod          = (getMethodReference == null) ? null : getMethodReference.Resolve();

                if ((setMethod != null) && (getMethod != null))
                {
                    if (getMethod.Visibility == setMethod.Visibility)
                    {
                        visibility = getMethod.Visibility;
                    }
                }
                else if (setMethod != null)
                {
                    visibility = setMethod.Visibility;
                }
                else if (getMethod != null)
                {
                    visibility = getMethod.Visibility;
                }
            }

            return(visibility);
        }
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility     result = MethodVisibility.Public;
            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethod          = propertyDeclaration.SetMethod;
                IMethodDeclaration methodDeclaration  = setMethod?.Resolve();
                IMethodReference   getMethod          = propertyDeclaration.GetMethod;
                IMethodDeclaration methodDeclaration2 = getMethod?.Resolve();
                if (methodDeclaration != null && methodDeclaration2 != null)
                {
                    if (methodDeclaration2.Visibility == methodDeclaration.Visibility)
                    {
                        result = methodDeclaration2.Visibility;
                    }
                }
                else if (methodDeclaration != null)
                {
                    result = methodDeclaration.Visibility;
                }
                else if (methodDeclaration2 != null)
                {
                    result = methodDeclaration2.Visibility;
                }
            }
            return(result);
        }
Esempio n. 3
0
        public static IMethodDeclaration GetGetMethod(IPropertyReference value)
        {
            IPropertyDeclaration declaration2 = value.Resolve();

            if (declaration2.GetMethod != null)
            {
                return(declaration2.GetMethod.Resolve());
            }
            return(null);
        }
        public static IMethodDeclaration GetSetMethod(IPropertyReference value)
        {
            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration.SetMethod != null)
            {
                return(propertyDeclaration.SetMethod.Resolve());
            }

            return(null);
        }
Esempio n. 5
0
        public static IMethodDeclaration GetGetMethod(IPropertyReference value)
        {
            IPropertyDeclaration propertyDeclaration = value.Resolve();
            if (propertyDeclaration.GetMethod != null)
            {
                return propertyDeclaration.GetMethod.Resolve();
            }

            return null;
        }
Esempio n. 6
0
        private TreeNode FindNode(IMemberReference memberReference)
        {
            if (memberReference is IAssemblyReference)
            {
                foreach (TreeNode node in _assembliesTree.Nodes)
                {
                    if (node.Tag == memberReference)
                    {
                        return(node);
                    }
                }

                return(null);
            }

            if (memberReference is IResourceReference)
            {
                IResourceReference resourceReference = (IResourceReference)memberReference;
                TreeNode           assemblyNode      = FindNode(resourceReference.Resolve().Assembly);
                TreeNode           resourcesNode     = null;
                foreach (TreeNode childNode in assemblyNode.Nodes)
                {
                    if (childNode.Text == "Resources")
                    {
                        resourcesNode = childNode;
                    }
                }

                return(FindNode(memberReference, resourcesNode));
            }

            if (memberReference is IModuleReference)
            {
                IModuleReference moduleReference = (IModuleReference)memberReference;
                return(FindNode(memberReference, FindNode(moduleReference.Resolve().Assembly)));
            }

            if (memberReference is ITypeReference)
            {
                ITypeReference typeReference = (ITypeReference)memberReference;


                if (typeReference.Resolve().DeclaringType != null)
                {
                    TreeNode declaringTypeNode = FindNode(typeReference.Resolve().DeclaringType);
                    return(FindNode(memberReference, declaringTypeNode));
                }
                else
                {
                    TreeNode moduleNode = FindNode(typeReference.Resolve().Module);

                    foreach (TreeNode namespaceNode in moduleNode.Nodes)
                    {
                        if (((namespaceNode.Text == "-") && (typeReference.Namespace == null)) ||
                            (namespaceNode.Text == typeReference.Namespace))
                        {
                            return(FindNode(memberReference, namespaceNode));
                        }
                    }
                }

                return(null);
            }

            if (memberReference is IMethodReference)
            {
                IMethodReference methodReference = (IMethodReference)memberReference;
                TreeNode         typeNode        = FindNode(methodReference.Resolve().DeclaringType);

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

                foreach (TreeNode node in typeNode.Nodes)
                {
                    if (node.Tag == memberReference)
                    {
                        return(node);
                    }

                    if ((node.Tag is IPropertyReference) || (node.Tag is IEventReference))
                    {
                        TreeNode nestedEventNode = FindNode(memberReference, node);
                        if (nestedEventNode != null)
                        {
                            return(nestedEventNode);
                        }
                    }
                }

                return(null);
            }

            if (memberReference is IFieldReference)
            {
                IFieldReference fieldReference = (IFieldReference)memberReference;
                return(FindNode(memberReference, FindNode(fieldReference.Resolve().DeclaringType)));
            }

            if (memberReference is IPropertyReference)
            {
                IPropertyReference propertyReference = (IPropertyReference)memberReference;
                return(FindNode(memberReference, FindNode(propertyReference.Resolve().DeclaringType)));
            }

            if (memberReference is IEventReference)
            {
                IEventReference eventReference = (IEventReference)memberReference;
                return(FindNode(memberReference, FindNode(eventReference.Resolve().DeclaringType)));
            }

            return(null);
        }
Esempio n. 7
0
        internal static int GetImageIndex(IMemberReference memberReference)
        {
            IFieldReference fieldReference = memberReference as IFieldReference;

            if (fieldReference != null)
            {
                IFieldDeclaration fieldDeclaration = fieldReference.Resolve();
                if (fieldDeclaration == null)
                {
                    return(BrowserResource.Error);
                }

                int icon = BrowserResource.Field;

                if (IsEnumerationElement(fieldReference))
                {
                    icon = BrowserResource.EnumerationElement;
                }
                else
                {
                    if (fieldDeclaration.Static)
                    {
                        icon += 6;
                    }
                }

                switch (fieldDeclaration.Visibility)
                {
                case FieldVisibility.Public:
                    return(icon);

                case FieldVisibility.Assembly:
                    return(icon + 1);

                case FieldVisibility.FamilyOrAssembly:
                    return(icon + 2);

                case FieldVisibility.Family:
                    return(icon + 3);

                case FieldVisibility.Private:
                case FieldVisibility.PrivateScope:
                    return(icon + 4);

                case FieldVisibility.FamilyAndAssembly:
                    return(icon + 5);
                }
            }

            IMethodReference methodReference = memberReference as IMethodReference;

            if (methodReference != null)
            {
                IArrayType arrayType = methodReference.DeclaringType as IArrayType;
                if (arrayType != null)
                {
                    return(BrowserResource.Method);
                }

                IMethodDeclaration methodDeclaration = methodReference.Resolve();
                if (methodDeclaration == null)
                {
                    return(BrowserResource.Error);
                }

                int icon = BrowserResource.Method;

                string methodName = methodReference.Name;
                if ((methodName == ".ctor") || (methodName == ".cctor"))
                {
                    icon = BrowserResource.Constructor;
                }
                else if ((methodDeclaration.Virtual) && (!methodDeclaration.Abstract))
                {
                    icon += 12;
                }

                if (methodDeclaration.Static)
                {
                    icon += 6;
                }

                switch (methodDeclaration.Visibility)
                {
                case MethodVisibility.Public:
                    return(icon);

                case MethodVisibility.Assembly:
                    return(icon + 1);

                case MethodVisibility.FamilyOrAssembly:
                    return(icon + 2);

                case MethodVisibility.Family:
                    return(icon + 3);

                case MethodVisibility.Private:
                case MethodVisibility.PrivateScope:
                    return(icon + 4);

                case MethodVisibility.FamilyAndAssembly:
                    return(icon + 5);
                }
            }

            IPropertyReference propertyReference = memberReference as IPropertyReference;

            if (propertyReference != null)
            {
                IPropertyDeclaration propertyDeclaration = propertyReference.Resolve();
                if (propertyDeclaration != null)
                {
                    IMethodReference   getMethodReference = propertyDeclaration.GetMethod;
                    IMethodDeclaration getMethod          = (getMethodReference == null) ? null : getMethodReference.Resolve();

                    IMethodReference   setMethodReference = propertyDeclaration.SetMethod;
                    IMethodDeclaration setMethod          = (setMethodReference == null) ? null : setMethodReference.Resolve();

                    int index = BrowserResource.Property;

                    if ((setMethod != null) && (getMethod != null))
                    {
                        index = BrowserResource.Property;
                    }
                    else if (setMethod != null)
                    {
                        index = BrowserResource.PropertyWrite;
                    }
                    else if (getMethod != null)
                    {
                        index = BrowserResource.PropertyRead;
                    }

                    if (Helper.IsStatic(propertyReference))
                    {
                        index += 6;
                    }

                    switch (Helper.GetVisibility(propertyReference))
                    {
                    case MethodVisibility.Public:
                        return(index + 0);

                    case MethodVisibility.Assembly:
                        return(index + 1);

                    case MethodVisibility.FamilyOrAssembly:
                        return(index + 2);

                    case MethodVisibility.Family:
                        return(index + 3);

                    case MethodVisibility.Private:
                    case MethodVisibility.PrivateScope:
                        return(index + 4);

                    case MethodVisibility.FamilyAndAssembly:
                        return(index + 5);
                    }
                }
            }

            IEventReference eventReference = memberReference as IEventReference;

            if (eventReference != null)
            {
                int index = BrowserResource.Event;

                if (Helper.IsStatic(eventReference))
                {
                    index += 6;
                }

                switch (Helper.GetVisibility(eventReference))
                {
                case MethodVisibility.Public:
                    return(index + 0);

                case MethodVisibility.Assembly:
                    return(index + 1);

                case MethodVisibility.FamilyOrAssembly:
                    return(index + 2);

                case MethodVisibility.Family:
                    return(index + 3);

                case MethodVisibility.Private:
                case MethodVisibility.PrivateScope:
                    return(index + 4);

                case MethodVisibility.FamilyAndAssembly:
                    return(index + 5);
                }
            }

            throw new NotSupportedException();
        }