Exemplo n.º 1
0
		public IList<IFindReferenceSearchScope> GetSearchScopes(IEntity entity)
		{
			if (entity == null)
				throw new ArgumentNullException("entity");
			Accessibility effectiveAccessibility = GetEffectiveAccessibility(entity);
			ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition;
			while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null)
				topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition;
			SearchScope scope;
			SearchScope additionalScope = null;
			switch (entity.EntityType) {
				case EntityType.TypeDefinition:
					scope = new FindTypeDefinitionReferences((ITypeDefinition)entity, this.FindTypeReferencesEvenIfAliased);
					break;
				case EntityType.Field:
					if (entity.DeclaringTypeDefinition != null && entity.DeclaringTypeDefinition.Kind == TypeKind.Enum)
						scope = new FindEnumMemberReferences((IField)entity);
					else
						scope = new FindFieldReferences((IField)entity);
					break;
				case EntityType.Property:
					scope = new FindPropertyReferences((IProperty)entity);
					break;
				case EntityType.Event:
					scope = new FindEventReferences((IEvent)entity);
					break;
				case EntityType.Method:
					scope = GetSearchScopeForMethod((IMethod)entity);
					break;
				case EntityType.Indexer:
					scope = new FindIndexerReferences((IProperty)entity);
					break;
				case EntityType.Operator:
					scope = GetSearchScopeForOperator((IMethod)entity);
					break;
				case EntityType.Constructor:
					IMethod ctor = (IMethod)entity;
					scope = new FindObjectCreateReferences(ctor);
					additionalScope = new FindChainedConstructorReferences(ctor);
					break;
				case EntityType.Destructor:
					return EmptyList<IFindReferenceSearchScope>.Instance;
				default:
					throw new ArgumentException("Unknown entity type " + entity.EntityType);
			}
			if (scope.accessibility == Accessibility.None)
				scope.accessibility = effectiveAccessibility;
			scope.topLevelTypeDefinition = topLevelTypeDefinition;
			if (additionalScope != null) {
				if (additionalScope.accessibility == Accessibility.None)
					additionalScope.accessibility = effectiveAccessibility;
				additionalScope.topLevelTypeDefinition = topLevelTypeDefinition;
				return new[] { scope, additionalScope };
			} else {
				return new[] { scope };
			}
		}
Exemplo n.º 2
0
        public IList <IFindReferenceSearchScope> GetSearchScopes(IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            Accessibility   effectiveAccessibility = GetEffectiveAccessibility(entity);
            ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition;

            while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null)
            {
                topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition;
            }
            SearchScope scope;
            SearchScope additionalScope = null;

            switch (entity.EntityType)
            {
            case EntityType.TypeDefinition:
                scope = new FindTypeDefinitionReferences((ITypeDefinition)entity, this.FindTypeReferencesEvenIfAliased);
                break;

            case EntityType.Field:
                if (entity.DeclaringTypeDefinition != null && entity.DeclaringTypeDefinition.Kind == TypeKind.Enum)
                {
                    scope = new FindEnumMemberReferences((IField)entity);
                }
                else
                {
                    scope = new FindFieldReferences((IField)entity);
                }
                break;

            case EntityType.Property:
                scope = new FindPropertyReferences((IProperty)entity);
                break;

            case EntityType.Event:
                scope = new FindEventReferences((IEvent)entity);
                break;

            case EntityType.Method:
                scope = GetSearchScopeForMethod((IMethod)entity);
                break;

            case EntityType.Indexer:
                scope = new FindIndexerReferences((IProperty)entity);
                break;

            case EntityType.Operator:
                scope = GetSearchScopeForOperator((IMethod)entity);
                break;

            case EntityType.Constructor:
                IMethod ctor = (IMethod)entity;
                scope           = new FindObjectCreateReferences(ctor);
                additionalScope = new FindChainedConstructorReferences(ctor);
                break;

            case EntityType.Destructor:
                return(EmptyList <IFindReferenceSearchScope> .Instance);

            default:
                throw new ArgumentException("Unknown entity type " + entity.EntityType);
            }
            if (scope.accessibility == Accessibility.None)
            {
                scope.accessibility = effectiveAccessibility;
            }
            scope.topLevelTypeDefinition = topLevelTypeDefinition;
            if (additionalScope != null)
            {
                if (additionalScope.accessibility == Accessibility.None)
                {
                    additionalScope.accessibility = effectiveAccessibility;
                }
                additionalScope.topLevelTypeDefinition = topLevelTypeDefinition;
                return(new[] { scope, additionalScope });
            }
            else
            {
                return(new[] { scope });
            }
        }