Пример #1
0
        public string GetForDeclaredElement([CanBeNull] IDeclaredElement declaredElement)
        {
            switch (declaredElement)
            {
            case null:
                return(null);

            case IMethod method:
                if (method.IsPredefined)
                {
                    return(null);
                }
                return(method.IsExtensionMethod ? ExtensionMethod : Method);

            case ISignOperator signOperator:
                return(signOperator.IsPredefined ? Operator : UserOperator);

            case IConstructor constructor:
                return(GetForTypeElement(constructor.GetContainingType()));

            case IField field:
                return(field.IsField ? Field : Constant);

            case ITypeElement typeElement:
                return(GetForTypeElement(typeElement));

            case IEvent _:
                return(Event);

            case INamespace _:
                return(Namespace);

            case IParameter parameter:
                return(parameter.IsValueVariable ? Identifier : Parameter);

            case ILocalVariable localVariable:
                return(localVariable.IsConstant ? Constant : LocalVariable);

            case ICSharpAnonymousTypeProperty _:
                return(declaredElement is IQueryAnonymousTypeProperty ? LocalVariable : Field);

            case ILocalFunction _:
                return(LocalFunction);

            case IPathDeclaredElement _:
                return(Path);

            case var _ when CSharpDeclaredElementUtil.IsProperty(declaredElement) || declaredElement.IsCSharpIndexedProperty():
                return(Property);

            default:
                return(Identifier);
            }
        }
Пример #2
0
        private static bool IsIndexer([NotNull] IDeclaredElement element)
        {
            var accessor = element as IAccessor;

            if (accessor != null)
            {
                element = accessor.OwnerMember;
            }

            return(element.IsCSharpIndexer() || element.IsCSharpIndexedProperty());
        }
Пример #3
0
        public string GetForDeclaredElement([CanBeNull] IDeclaredElement declaredElement)
        {
            if (declaredElement == null)
            {
                return(null);
            }

            if (declaredElement is IFunction)
            {
                var method = declaredElement as IMethod;
                if (method != null)
                {
                    if (method.IsPredefined)
                    {
                        return(null);
                    }
                    return(method.IsExtensionMethod ? ExtensionMethod : Method);
                }

                var signOperator = declaredElement as ISignOperator;
                if (signOperator != null)
                {
                    return(signOperator.IsPredefined ? Operator : UserOperator);
                }

                var constructor = declaredElement as IConstructor;
                if (constructor != null)
                {
                    return(GetForTypeElement(constructor.GetContainingType()));
                }
            }

            var field = declaredElement as IField;

            if (field != null)
            {
                return(field.IsField ? Field : Constant);
            }

            var typeElement = declaredElement as ITypeElement;

            if (typeElement != null)
            {
                return(GetForTypeElement(typeElement));
            }

            if (CSharpDeclaredElementUtil.IsProperty(declaredElement) || declaredElement.IsCSharpIndexedProperty())
            {
                return(Property);
            }

            if (declaredElement is IEvent)
            {
                return(Event);
            }

            if (declaredElement is INamespace)
            {
                return(Namespace);
            }

            var parameter = declaredElement as IParameter;

            if (parameter != null)
            {
                return(parameter.IsValueVariable ? Identifier : Parameter);
            }

            var localVariable = declaredElement as ILocalVariable;

            if (localVariable != null)
            {
                return(localVariable.IsConstant ? Constant : LocalVariable);
            }

            if (declaredElement is ICSharpAnonymousTypeProperty)
            {
                return(declaredElement is IQueryAnonymousTypeProperty ? LocalVariable : Field);
            }

            if (declaredElement is IPathDeclaredElement)
            {
                return(Path);
            }

            return(Identifier);
        }