本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper.AddVariable方法的典型用法代码示例。如果您正苦于以下问题:C# CompletionDataWrapper.AddVariable方法的具体用法?C# CompletionDataWrapper.AddVariable怎么用?C# CompletionDataWrapper.AddVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper
的用法示例。
在下文中一共展示了CompletionDataWrapper.AddVariable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MagicKeyCompletion
//.........这里部分代码省略.........
if (arg == n) {
break;
}
idx++;
}
foreach (var method in mgr.Methods) {
if (idx < method.Parameters.Count && method.Parameters [idx].Type.Kind == TypeKind.Delegate) {
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
foreach (var p in method.Parameters) {
contextList.AddNamedParameterVariable(p);
}
}
idx++;
foreach (var list in mgr.GetEligibleExtensionMethods (true)) {
foreach (var method in list) {
if (idx < method.Parameters.Count && method.Parameters [idx].Type.Kind == TypeKind.Delegate) {
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
}
}
}
}
if (n != null && n.Parent is ObjectCreateExpression) {
var invokeResult = ResolveExpression(n.Parent);
var mgr = invokeResult != null ? invokeResult.Result as ResolveResult : null;
if (mgr != null) {
foreach (var constructor in mgr.Type.GetConstructors ()) {
foreach (var p in constructor.Parameters) {
contextList.AddVariable(p);
}
}
}
}
if (n is IdentifierExpression) {
var bop = n.Parent as BinaryOperatorExpression;
Expression evaluationExpr = null;
if (bop != null && bop.Right == n && (bop.Operator == BinaryOperatorType.Equality || bop.Operator == BinaryOperatorType.InEquality)) {
evaluationExpr = bop.Left;
}
// check for compare to enum case
if (evaluationExpr != null) {
resolveResult = ResolveExpression(evaluationExpr);
if (resolveResult != null && resolveResult.Result.Type.Kind == TypeKind.Enum) {
var wrapper = new CompletionDataWrapper(this);
AddContextCompletion(
wrapper,
resolveResult.Resolver,
evaluationExpr
);
AddEnumMembers(wrapper, resolveResult.Result.Type, resolveResult.Resolver);
AutoCompleteEmptyMatch = false;
return wrapper.Result;
}
}
}
if (n is Identifier && n.Parent is ForeachStatement) {
if (controlSpace) {
return DefaultControlSpaceItems(ref isComplete);
示例2: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node)
{
int i = offset - 1;
var isInGlobalDelegate = node == null && state.CurrentTypeDefinition == null && GetPreviousToken(ref i, true) == "delegate";
if (state != null && !(node is AstType)) {
foreach (var variable in state.LocalVariables) {
if (variable.Region.IsInside(location.Line, location.Column - 1)) {
continue;
}
wrapper.AddVariable(variable);
}
}
if (state.CurrentMember is IParameterizedMember && !(node is AstType)) {
var param = (IParameterizedMember)state.CurrentMember;
foreach (var p in param.Parameters) {
wrapper.AddVariable(p);
}
}
if (state.CurrentMember is IMethod) {
var method = (IMethod)state.CurrentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
Func<IType, IType> typePred = null;
if (IsAttributeContext(node)) {
var attribute = Compilation.FindType(KnownTypeCode.Attribute);
typePred = t => t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null;
}
if (node != null && node.Role == Roles.BaseType) {
typePred = t => {
var def = t.GetDefinition();
if (def != null && t.Kind != TypeKind.Interface && (def.IsSealed || def.IsStatic))
return null;
return t;
};
}
if (node != null && !(node is NamespaceDeclaration) || state.CurrentTypeDefinition != null || isInGlobalDelegate) {
AddTypesAndNamespaces(wrapper, state, node, typePred);
wrapper.Result.Add(factory.CreateLiteralCompletionData("global"));
}
if (!(node is AstType)) {
if (currentMember != null || node is Expression) {
AddKeywords(wrapper, statementStartKeywords);
if (LanguageVersion.Major >= 5)
AddKeywords(wrapper, new [] { "await" });
AddKeywords(wrapper, expressionLevelKeywords);
if (node == null || node is TypeDeclaration)
AddKeywords(wrapper, typeLevelKeywords);
} else if (currentType != null) {
AddKeywords(wrapper, typeLevelKeywords);
} else {
if (!isInGlobalDelegate && !(node is Attribute))
AddKeywords(wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside(location)) {
wrapper.AddCustom("value");
}
if (currentMember is IUnresolvedEvent) {
wrapper.AddCustom("value");
}
if (IsInSwitchContext(node)) {
if (IncludeKeywordsInCompletionList)
wrapper.AddCustom("case");
}
} else {
if (((AstType)node).Parent is ParameterDeclaration) {
AddKeywords(wrapper, parameterTypePredecessorKeywords);
}
}
if (node != null || state.CurrentTypeDefinition != null || isInGlobalDelegate)
AddKeywords(wrapper, primitiveTypesKeywords);
if (currentMember != null && (node is IdentifierExpression || node is SimpleType) && (node.Parent is ExpressionStatement || node.Parent is ForeachStatement || node.Parent is UsingStatement)) {
if (IncludeKeywordsInCompletionList) {
wrapper.AddCustom("var");
wrapper.AddCustom("dynamic");
}
}
wrapper.Result.AddRange(factory.CreateCodeTemplateCompletionData());
if (node != null && node.Role == Roles.Argument) {
var resolved = ResolveExpression(node.Parent);
var invokeResult = resolved != null ? resolved.Result as CSharpInvocationResolveResult : null;
if (invokeResult != null) {
int argNum = 0;
foreach (var arg in node.Parent.Children.Where (c => c.Role == Roles.Argument)) {
if (arg == node) {
break;
}
argNum++;
}
//.........这里部分代码省略.........
示例3: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node, CompilationUnit unit)
{
if (state != null && !(node is AstType)) {
foreach (var variable in state.LocalVariables) {
if (variable.Region.IsInside(location.Line, location.Column - 1)) {
continue;
}
wrapper.AddVariable(variable);
}
}
if (currentMember is IUnresolvedParameterizedMember && !(node is AstType)) {
var param = (IParameterizedMember)currentMember.CreateResolved(ctx);
foreach (var p in param.Parameters) {
wrapper.AddVariable(p);
}
}
if (currentMember is IUnresolvedMethod) {
var method = (IUnresolvedMethod)currentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
Func<IType, IType> typePred = null;
if (IsAttributeContext(node)) {
var attribute = Compilation.FindType(KnownTypeCode.Attribute);
typePred = t => {
return t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null;
};
}
AddTypesAndNamespaces(wrapper, state, node, typePred);
wrapper.Result.Add(factory.CreateLiteralCompletionData("global"));
if (!(node is AstType)) {
if (currentMember != null || node is Expression) {
AddKeywords(wrapper, statementStartKeywords);
AddKeywords(wrapper, expressionLevelKeywords);
if (node is TypeDeclaration)
AddKeywords(wrapper, typeLevelKeywords);
} else if (currentType != null) {
AddKeywords(wrapper, typeLevelKeywords);
} else {
AddKeywords(wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside(location)) {
wrapper.AddCustom("value");
}
if (currentMember is IUnresolvedEvent) {
wrapper.AddCustom("value");
}
if (IsInSwitchContext(node)) {
wrapper.AddCustom("case");
}
} else {
if (((AstType)node).Parent is ParameterDeclaration) {
AddKeywords(wrapper, parameterTypePredecessorKeywords);
}
}
AddKeywords(wrapper, primitiveTypesKeywords);
if (currentMember != null) {
wrapper.AddCustom("var");
}
wrapper.Result.AddRange(factory.CreateCodeTemplateCompletionData());
if (node != null && node.Role == Roles.Argument) {
var resolved = ResolveExpression(node.Parent, unit);
var invokeResult = resolved != null ? resolved.Item1 as CSharpInvocationResolveResult : null;
if (invokeResult != null) {
int argNum = 0;
foreach (var arg in node.Parent.Children.Where (c => c.Role == Roles.Argument)) {
if (arg == node) {
break;
}
argNum++;
}
var param = argNum < invokeResult.Member.Parameters.Count ? invokeResult.Member.Parameters [argNum] : null;
if (param != null && param.Type.Kind == TypeKind.Enum) {
AddEnumMembers(wrapper, param.Type, state);
}
}
}
if (node is Expression) {
var astResolver = new CSharpAstResolver(state, unit, CSharpParsedFile);
foreach (var type in CreateFieldAction.GetValidTypes(astResolver, (Expression)node)) {
if (type.Kind == TypeKind.Enum) {
AddEnumMembers(wrapper, type, state);
} else if (type.Kind == TypeKind.Delegate) {
AddDelegateHandlers(wrapper, type, true, true);
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
}
}
//.........这里部分代码省略.........
示例4: MagicKeyCompletion
//.........这里部分代码省略.........
if (n != null && n.Parent is AnonymousTypeCreateExpression) {
AutoSelect = false;
}
// Handle foreach (type name _
if (n is IdentifierExpression) {
var prev = n.GetPrevNode () as ForeachStatement;
if (prev != null && prev.InExpression.IsNull) {
if (controlSpace) {
contextList.AddCustom ("in");
return contextList.Result;
}
return null;
}
}
if (n != null && n.Parent is InvocationExpression) {
var invokeParent = (InvocationExpression)n.Parent;
var invokeResult = ResolveExpression (identifierStart.Item1, invokeParent.Target, identifierStart.Item3);
var mgr = invokeResult != null ? invokeResult.Item1 as MethodGroupResolveResult : null;
if (mgr != null) {
int idx = 0;
foreach (var arg in invokeParent.Arguments) {
if (arg == n)
break;
idx++;
}
foreach (var method in mgr.Methods) {
if (idx < method.Parameters.Count && method.Parameters[idx].Type.Kind == TypeKind.Delegate) {
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
foreach (var p in method.Parameters) {
contextList.AddVariable (p);
}
}
idx++;
foreach (var list in mgr.GetExtensionMethods ()) {
foreach (var method in list) {
if (idx < method.Parameters.Count && method.Parameters[idx].Type.Kind == TypeKind.Delegate) {
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
}
}
}
}
if (n != null && n.Parent is ObjectCreateExpression) {
var invokeResult = ResolveExpression (identifierStart.Item1, n.Parent, identifierStart.Item3);
var mgr = invokeResult != null ? invokeResult.Item1 as ResolveResult : null;
if (mgr != null) {
foreach (var constructor in mgr.Type.GetConstructors ()) {
foreach (var p in constructor.Parameters) {
contextList.AddVariable (p);
}
}
}
}
if (n is IdentifierExpression) {
var bop = n.Parent as BinaryOperatorExpression;
Expression evaluationExpr = null;
示例5: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node)
{
if (state != null) {
foreach (var variable in state.LocalVariables) {
wrapper.AddVariable (variable);
}
}
if (ctx.CurrentMember is IParameterizedMember) {
var param = (IParameterizedMember)ctx.CurrentMember;
foreach (var p in param.Parameters) {
wrapper.AddVariable (p);
}
}
if (currentMember is IUnresolvedMethod) {
var method = (IUnresolvedMethod)currentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter (p);
}
}
Predicate<IType> typePred = null;
if (node is Attribute) {
var attribute = Compilation.FindType (typeof (System.Attribute));
typePred = t => {
return t.GetAllBaseTypeDefinitions ().Any (bt => bt.Equals (attribute));
};
}
AddTypesAndNamespaces (wrapper, state, node, typePred);
wrapper.Result.Add (factory.CreateLiteralCompletionData ("global"));
if (state.CurrentMember != null) {
AddKeywords (wrapper, statementStartKeywords);
AddKeywords (wrapper, expressionLevelKeywords);
} else if (state.CurrentTypeDefinition != null) {
AddKeywords (wrapper, typeLevelKeywords);
} else {
AddKeywords (wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter.Region.IsInside (location))
wrapper.AddCustom ("value");
if (currentMember is IUnresolvedEvent)
wrapper.AddCustom ("value");
if (IsInSwitchContext (node)) {
wrapper.AddCustom ("case");
wrapper.AddCustom ("default");
}
AddKeywords (wrapper, primitiveTypesKeywords);
wrapper.Result.AddRange (factory.CreateCodeTemplateCompletionData ());
}