Example #1
0
        AstType GuessType(RefactoringContext context, IdentifierExpression identifier)
        {
            var type = CreateField.GuessType(context, identifier);

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

            if (identifier != null && (identifier.Parent is InvocationExpression || identifier.Parent.Parent is InvocationExpression))
            {
                var invocation = (identifier.Parent as InvocationExpression) ?? (identifier.Parent.Parent as InvocationExpression);
                var result     = context.Resolve(invocation).Type.GetDelegateInvokeMethod();
                if (result == null)
                {
                    return(null);
                }
                int i = 0;
                foreach (var arg in invocation.Arguments)
                {
                    if (arg.Contains(identifier.StartLocation))
                    {
                        break;
                    }
                    i++;
                }
                if (result.Parameters.Count < i)
                {
                    return(null);
                }
                return(context.CreateShortType(result.Parameters[i].Type));
            }
            return(null);
        }
Example #2
0
 AstNode GeneratePropertyDeclaration(RefactoringContext context, IdentifierExpression identifier)
 {
     return(new PropertyDeclaration()
     {
         ReturnType = CreateField.GuessType(context, identifier),
         Name = identifier.Identifier,
         Getter = new Accessor(),
         Setter = new Accessor()
     });
 }
Example #3
0
        public bool IsValid(RefactoringContext context)
        {
            var identifier = CreateField.GetIdentifier(context);

            if (identifier == null)
            {
                return(false);
            }
            return(context.Resolve(identifier) == null && CreateField.GuessType(context, identifier) != null);
        }