Пример #1
0
        private static ICollection<IClass> GetTypesNonCached([NotNull] IArgumentsOwner argumentsOwner)
        {
            argumentsOwner.AssertIsValid("argumentsOwner is invalid");
            var invocationExpression = argumentsOwner as IInvocationExpression;
            if (invocationExpression != null)
            {
                var referenceExpression = invocationExpression.InvokedExpression as IReferenceExpression;
                if (referenceExpression != null)
                {
                    var typeofExpression = referenceExpression.QualifierExpression as ITypeofExpression;
                    if (typeofExpression != null)
                    {
                        IType type = typeofExpression.ArgumentType;
                        IClass @class = type.GetClassType();
                        return new[] {@class};
                    }
                    var gettypeExpression = referenceExpression.QualifierExpression as IInvocationExpression;
                    if (gettypeExpression != null && gettypeExpression.Reference != null && gettypeExpression.Reference.GetName() == "GetType")
                    {
                        var method = gettypeExpression.Reference.Resolve().DeclaredElement as IMethod;
                        if (method != null)
                        {
                            var containingType = method.GetContainingType();
                            if (containingType != null)
                            {
                                var containingTypeName = containingType.GetClrName().FullName;
                                if (containingTypeName == "System.Object")
                                {
                                    var typeDeclaration = gettypeExpression.GetContainingNode<ITypeDeclaration>();
                                    if (typeDeclaration != null)
                                    {
                                        return new[] {typeDeclaration.DeclaredElement as IClass};
                                    }
                                }
                                if (containingTypeName == "System.Type" && method.IsStatic)
                                {
                                    if (gettypeExpression.Arguments.Count > 0)
                                    {
                                        var literalExpression = gettypeExpression.Arguments[0].Expression as ICSharpLiteralExpression;
                                        if (literalExpression != null && literalExpression.IsConstantValue() && literalExpression.ConstantValue.IsString())
                                        {
                                            var typeName = new ClrTypeName((string) literalExpression.ConstantValue.Value);

                                            var name = new DeclaredTypeFromCLRName(typeName, gettypeExpression.GetPsiModule(), gettypeExpression.GetResolveContext());
                                            return new[] { name.GetTypeElement() as IClass };
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return EmptyList<IClass>.InstanceList;
        }