本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper.AddNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# CompletionDataWrapper.AddNamespace方法的具体用法?C# CompletionDataWrapper.AddNamespace怎么用?C# CompletionDataWrapper.AddNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper
的用法示例。
在下文中一共展示了CompletionDataWrapper.AddNamespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTypeAndNamespaceCompletionData
IEnumerable<ICompletionData> CreateTypeAndNamespaceCompletionData(TextLocation location, ResolveResult resolveResult, AstNode resolvedNode, CSharpResolver state)
{
if (resolveResult == null || resolveResult.IsError) {
return null;
}
var exprParent = resolvedNode.GetParent<Expression>();
var unit = exprParent != null ? exprParent.GetParent<SyntaxTree>() : null;
var astResolver = unit != null ? CompletionContextProvider.GetResolver(state, unit) : null;
IType hintType = exprParent != null && astResolver != null ?
TypeGuessing.GetValidTypes(astResolver, exprParent).FirstOrDefault() :
null;
var result = new CompletionDataWrapper(this);
var lookup = new MemberLookup(
ctx.CurrentTypeDefinition,
Compilation.MainAssembly
);
if (resolveResult is NamespaceResolveResult) {
var nr = (NamespaceResolveResult)resolveResult;
if (!(resolvedNode.Parent is UsingDeclaration || resolvedNode.Parent != null && resolvedNode.Parent.Parent is UsingDeclaration)) {
foreach (var cl in nr.Namespace.Types) {
if (hintType != null && hintType.Kind != TypeKind.Array && cl.Kind == TypeKind.Interface) {
continue;
}
if (!lookup.IsAccessible(cl, false))
continue;
result.AddType(cl, false, IsAttributeContext(resolvedNode));
}
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
result.AddNamespace(lookup, ns);
}
} else if (resolveResult is TypeResolveResult) {
var type = resolveResult.Type;
foreach (var nested in type.GetNestedTypes ()) {
if (hintType != null && hintType.Kind != TypeKind.Array && nested.Kind == TypeKind.Interface) {
continue;
}
var def = nested.GetDefinition();
if (def != null && !lookup.IsAccessible(def, false))
continue;
result.AddType(nested, false);
}
}
return result.Result;
}
示例2: CreateCompletionData
IEnumerable<ICompletionData> CreateCompletionData(TextLocation location, ResolveResult resolveResult, AstNode resolvedNode, CSharpResolver state, Func<IType, IType> typePred = null)
{
if (resolveResult == null /* || resolveResult.IsError*/) {
return null;
}
var lookup = new MemberLookup(
ctx.CurrentTypeDefinition,
Compilation.MainAssembly
);
if (resolveResult is NamespaceResolveResult) {
var nr = (NamespaceResolveResult)resolveResult;
var namespaceContents = new CompletionDataWrapper(this);
foreach (var cl in nr.Namespace.Types) {
if (!lookup.IsAccessible(cl, false))
continue;
IType addType = typePred != null ? typePred(cl) : cl;
if (addType != null)
namespaceContents.AddType(addType, false);
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
namespaceContents.AddNamespace(lookup, ns);
}
return namespaceContents.Result;
}
IType type = resolveResult.Type;
if (type.Namespace == "System" && type.Name == "Void")
return null;
if (resolvedNode.Parent is PointerReferenceExpression && (type is PointerType)) {
resolveResult = new OperatorResolveResult(((PointerType)type).ElementType, System.Linq.Expressions.ExpressionType.Extension, resolveResult);
}
//var typeDef = resolveResult.Type.GetDefinition();
var result = new CompletionDataWrapper(this);
bool includeStaticMembers = false;
if (resolveResult is LocalResolveResult) {
if (resolvedNode is IdentifierExpression) {
var mrr = (LocalResolveResult)resolveResult;
includeStaticMembers = mrr.Variable.Name == mrr.Type.Name;
}
}
if (resolveResult is TypeResolveResult && type.Kind == TypeKind.Enum) {
foreach (var field in type.GetFields ()) {
if (!lookup.IsAccessible(field, false))
continue;
result.AddMember(field);
}
return result.Result;
}
bool isProtectedAllowed = resolveResult is ThisResolveResult ? true : lookup.IsProtectedAccessAllowed(type);
bool skipNonStaticMembers = (resolveResult is TypeResolveResult);
if (resolveResult is MemberResolveResult && resolvedNode is IdentifierExpression) {
var mrr = (MemberResolveResult)resolveResult;
includeStaticMembers = mrr.Member.Name == mrr.Type.Name;
TypeResolveResult trr;
if (state.IsVariableReferenceWithSameType(
resolveResult,
((IdentifierExpression)resolvedNode).Identifier,
out trr
)) {
if (currentMember != null && mrr.Member.IsStatic ^ currentMember.IsStatic) {
skipNonStaticMembers = true;
if (trr.Type.Kind == TypeKind.Enum) {
foreach (var field in trr.Type.GetFields ()) {
if (lookup.IsAccessible(field, false))
result.AddMember(field);
}
return result.Result;
}
}
}
// ADD Aliases
var scope = ctx.CurrentUsingScope;
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
if (pair.Key == mrr.Member.Name) {
foreach (var r in CreateCompletionData (location, pair.Value, resolvedNode, state)) {
if (r is IEntityCompletionData && ((IEntityCompletionData)r).Entity is IMember) {
result.AddMember((IMember)((IEntityCompletionData)r).Entity);
} else {
result.Add(r);
}
}
}
}
}
}
//.........这里部分代码省略.........
示例3: CreateTypeAndNamespaceCompletionData
IEnumerable<ICompletionData> CreateTypeAndNamespaceCompletionData(TextLocation location, ResolveResult resolveResult, AstNode resolvedNode, CSharpResolver state)
{
if (resolveResult == null || resolveResult.IsError) {
return null;
}
var exprParent = resolvedNode.GetParent<Expression>();
var unit = exprParent != null ? exprParent.GetParent<CompilationUnit>() : null;
var astResolver = unit != null ? new CSharpAstResolver(
state,
unit,
CSharpParsedFile
) : null;
IType hintType = exprParent != null && astResolver != null ?
CreateFieldAction.GetValidTypes(astResolver, exprParent) .FirstOrDefault() :
null;
var result = new CompletionDataWrapper(this);
if (resolveResult is NamespaceResolveResult) {
var nr = (NamespaceResolveResult)resolveResult;
if (!(resolvedNode.Parent is UsingDeclaration || resolvedNode.Parent != null && resolvedNode.Parent.Parent is UsingDeclaration)) {
foreach (var cl in nr.Namespace.Types) {
string name = cl.Name;
if (hintType != null && hintType.Kind != TypeKind.Array && cl.Kind == TypeKind.Interface) {
continue;
}
if (IsAttributeContext(resolvedNode) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
name = name.Substring(0, name.Length - "Attribute".Length);
}
result.AddType(cl, name);
}
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
result.AddNamespace(ns.Name);
}
} else if (resolveResult is TypeResolveResult) {
var type = resolveResult.Type;
foreach (var nested in type.GetNestedTypes ()) {
if (hintType != null && hintType.Kind != TypeKind.Array && nested.Kind == TypeKind.Interface) {
continue;
}
result.AddType(nested, nested.Name);
}
}
return result.Result;
}
示例4: AddTypesAndNamespaces
//.........这里部分代码省略.........
continue;
}
if (addType != null) {
var a = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a2 = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
}
for (var n = scope; n != null; n = n.Parent) {
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint && IncludeKeywordsInCompletionList) {
wrapper.AddCustom("new()");
}
if (AutomaticallyAddImports) {
state = GetState();
ICompletionData[] importData;
var namespaces = new List<INamespace>();
for (var n = ctx.CurrentUsingScope; n != null; n = n.Parent) {
namespaces.Add(n.Namespace);
foreach (var u in n.Usings)
namespaces.Add(u);
}
if (this.CompletionEngineCache != null && ListEquals(namespaces, CompletionEngineCache.namespaces)) {
importData = CompletionEngineCache.importCompletion;
} else {
// flatten usings
var importList = new List<ICompletionData>();
var dict = new Dictionary<string, Dictionary<string, ICompletionData>>();
foreach (var type in Compilation.GetAllTypeDefinitions ()) {
if (!lookup.IsAccessible(type, false))
continue;
if (namespaces.Any(n => n.FullName == type.Namespace))
continue;
bool useFullName = false;
foreach (var ns in namespaces) {
if (ns.GetTypeDefinition(type.Name, type.TypeParameterCount) != null) {
示例5: AddTypesAndNamespaces
//.........这里部分代码省略.........
}
if (!lookup.IsAccessible(member, isProtectedAllowed)) {
continue;
}
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
if (ctx.CurrentTypeDefinition != null) {
foreach (var p in ctx.CurrentTypeDefinition.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
}
var scope = ctx.CurrentUsingScope;
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddAlias(pair.Key);
}
foreach (var alias in n.ExternAliases) {
wrapper.AddAlias(alias);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a2 = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint && IncludeKeywordsInCompletionList) {
wrapper.AddCustom ("new()");
}
if (AutomaticallyAddImports) {
state = GetState();
foreach (var type in Compilation.GetAllTypeDefinitions ()) {
if (!lookup.IsAccessible (type, false))
continue;
var resolveResult = state.LookupSimpleNameOrTypeName(type.Name, type.TypeArguments, NameLookupMode.Expression);
if (resolveResult.Type.GetDefinition () == type)
continue;
if (onlyAddConstructors) {
if (!type.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
wrapper.AddTypeImport(type, !resolveResult.IsError, onlyAddConstructors);
}
}
}
示例6: AddTypesAndNamespaces
void AddTypesAndNamespaces(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node, Func<IType, IType> typePred = null, Predicate<IMember> memberPred = null, Action<ICompletionData, IType> callback = null)
{
var lookup = new MemberLookup(
ctx.CurrentTypeDefinition,
Compilation.MainAssembly
);
if (currentType != null) {
for (var ct = currentType; ct != null; ct = ct.DeclaringTypeDefinition) {
foreach (var nestedType in ct.NestedTypes) {
string name = nestedType.Name;
if (IsAttributeContext(node) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
name = name.Substring(0, name.Length - "Attribute".Length);
}
if (typePred == null) {
wrapper.AddType(nestedType, name);
continue;
}
var type = typePred(nestedType.Resolve(ctx));
if (type != null) {
var a2 = wrapper.AddType(type, name);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
continue;
}
}
if (this.currentMember != null && !(node is AstType)) {
var def = ctx.CurrentTypeDefinition ?? Compilation.MainAssembly.GetTypeDefinition(currentType);
if (def != null) {
bool isProtectedAllowed = true;
foreach (var member in def.GetMembers ()) {
if (member is IMethod && ((IMethod)member).FullName == "System.Object.Finalize") {
continue;
}
if (member.EntityType == EntityType.Operator) {
continue;
}
if (member.IsExplicitInterfaceImplementation) {
continue;
}
if (!lookup.IsAccessible(member, isProtectedAllowed)) {
continue;
}
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
foreach (var p in currentType.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
var scope = CSharpParsedFile.GetUsingScope(location).Resolve(Compilation);
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddNamespace(pair.Key);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
string name = type.Name;
if (IsAttributeContext(node) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
name = name.Substring(0, name.Length - "Attribute".Length);
}
var a = wrapper.AddType(addType, name);
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
var a2 = wrapper.AddType(addType, addType.Name);
if (a2 != null && callback != null) {
callback(a2, type);
}
//.........这里部分代码省略.........
示例7: CreateTypeAndNamespaceCompletionData
IEnumerable<ICompletionData> CreateTypeAndNamespaceCompletionData(TextLocation location, ResolveResult resolveResult, AstNode resolvedNode, CSharpResolver state)
{
if (resolveResult == null || resolveResult.IsError) {
return null;
}
var hintType = GuessHintType(resolvedNode);
var result = new CompletionDataWrapper (this);
if (resolveResult is NamespaceResolveResult) {
var nr = (NamespaceResolveResult)resolveResult;
if (!(resolvedNode.Parent is UsingDeclaration || resolvedNode.Parent != null && resolvedNode.Parent.Parent is UsingDeclaration)) {
foreach (var cl in nr.Namespace.Types) {
string name = cl.Name;
if (hintType != null && hintType.Kind != TypeKind.Array && cl.Kind == TypeKind.Interface) {
continue;
}
if (IsAttributeContext(resolvedNode) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
name = name.Substring(0, name.Length - "Attribute".Length);
}
result.AddType(cl, name);
}
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
result.AddNamespace(ns.Name);
}
} else if (resolveResult is TypeResolveResult) {
var type = resolveResult.Type;
foreach (var nested in type.GetNestedTypes ()) {
if (hintType != null && hintType.Kind != TypeKind.Array && nested.Kind == TypeKind.Interface) {
continue;
}
result.AddType(nested, nested.Name);
}
}
return result.Result;
}
示例8: AddTypesAndNamespaces
//.........这里部分代码省略.........
wrapper.AddType(nestedType, false, IsAttributeContext(node));
continue;
}
var type = typePred(nestedType);
if (type != null) {
var a2 = wrapper.AddType(type, false, IsAttributeContext(node));
if (a2 != null && callback != null) {
callback(a2, type);
}
}
continue;
}
}
if (this.currentMember != null && !(node is AstType)) {
var def = ctx.CurrentTypeDefinition;
if (def == null && currentType != null)
def = Compilation.MainAssembly.GetTypeDefinition(currentType.FullTypeName);
if (def != null) {
bool isProtectedAllowed = true;
foreach (var member in def.GetMembers (m => currentMember.IsStatic ? m.IsStatic : true)) {
if (member is IMethod && ((IMethod)member).FullName == "System.Object.Finalize") {
continue;
}
if (member.EntityType == EntityType.Operator) {
continue;
}
if (member.IsExplicitInterfaceImplementation) {
continue;
}
if (!lookup.IsAccessible(member, isProtectedAllowed)) {
continue;
}
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
if (ctx.CurrentTypeDefinition != null) {
foreach (var p in ctx.CurrentTypeDefinition.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
}
var scope = ctx.CurrentUsingScope;
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddAlias(pair.Key);
}
foreach (var alias in n.ExternAliases) {
wrapper.AddAlias(alias);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
var a = wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
var a2 = wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint) {
wrapper.AddCustom ("new()");
}
}