本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CompletionDataWrapper.Add方法的具体用法?C# CompletionDataWrapper.Add怎么用?C# CompletionDataWrapper.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper
的用法示例。
在下文中一共展示了CompletionDataWrapper.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddVirtuals
protected override void AddVirtuals (List<IMember> alreadyInserted, CompletionDataWrapper col, string modifiers, IType curType, int declarationBegin)
{
base.AddVirtuals (alreadyInserted, col, modifiers, curType, declarationBegin);
foreach (var member in GetProtocolMembers (curType)) {
if (alreadyInserted.Contains (member))
continue;
if (BaseExportCodeGenerator.IsImplemented (curType, member))
continue;
alreadyInserted.Add (member);
var data = new ProtocolCompletionData (this, declarationBegin, member);
col.Add (data);
}
}
示例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: AddDelegateHandlers
string AddDelegateHandlers(CompletionDataWrapper completionList, IType delegateType, bool addSemicolon = true, bool addDefault = true, string optDelegateName = null)
{
IMethod delegateMethod = delegateType.GetDelegateInvokeMethod();
PossibleDelegates.Add(delegateMethod);
var thisLineIndent = GetLineIndent(location.Line);
string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : "");
//bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate("));
if (addDefault && !completionList.AnonymousDelegateAdded) {
completionList.AnonymousDelegateAdded = true;
var oldDelegate = completionList.Result.FirstOrDefault(cd => cd.DisplayText == "delegate");
if (oldDelegate != null)
completionList.Result.Remove(oldDelegate);
completionList.AddCustom(
"delegate",
"Creates anonymous delegate.",
"delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate",
"Creates anonymous async delegate.",
"async delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
}
}
var sb = new StringBuilder("(");
var sbWithoutTypes = new StringBuilder("(");
var state = GetState();
var builder = new TypeSystemAstBuilder(state);
for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
if (k > 0) {
sb.Append(", ");
sbWithoutTypes.Append(", ");
}
var convertedParameter = builder.ConvertParameter(delegateMethod.Parameters [k]);
if (convertedParameter.ParameterModifier == ParameterModifier.Params)
convertedParameter.ParameterModifier = ParameterModifier.None;
sb.Append(convertedParameter.ToString(FormattingPolicy));
sbWithoutTypes.Append(delegateMethod.Parameters [k].Name);
}
sb.Append(")");
sbWithoutTypes.Append(")");
var signature = sb.ToString();
if (!completionList.HasAnonymousDelegateAdded(signature)) {
completionList.AddAnonymousDelegateAdded(signature);
completionList.AddCustom(
"delegate" + signature,
"Creates anonymous delegate.",
"delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate" + signature,
"Creates anonymous async delegate.",
"async delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
}
if (!completionList.Result.Any(data => data.DisplayText == sb.ToString())) {
completionList.AddCustom(
signature,
"Creates typed lambda expression.",
signature + " => |" + (addSemicolon ? ";" : "")
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + signature,
"Creates typed async lambda expression.",
"async " + signature + " => |" + (addSemicolon ? ";" : "")
);
}
if (!delegateMethod.Parameters.Any(p => p.IsOut || p.IsRef) && !completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) {
completionList.AddCustom(
sbWithoutTypes.ToString(),
"Creates lambda expression.",
sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + sbWithoutTypes,
"Creates async lambda expression.",
"async " + sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
);
}
}
}
}
string varName = "Handle" + delegateType.Name + optDelegateName;
completionList.Add(factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType));
/* TODO:Make factory method out of it.
// It's needed to temporarly disable inserting auto matching bracket because the anonymous delegates are selectable with '('
// otherwise we would end up with () => )
//.........这里部分代码省略.........
示例4: AddVirtuals
protected virtual void AddVirtuals(List<IMember> alreadyInserted, CompletionDataWrapper col, string modifiers, IType curType, int declarationBegin)
{
if (curType == null) {
return;
}
foreach (var m in curType.GetMembers ().Reverse ()) {
if (curType.Kind != TypeKind.Interface && !m.IsOverridable) {
continue;
}
// filter out the "Finalize" methods, because finalizers should be done with destructors.
if (m is IMethod && m.Name == "Finalize") {
continue;
}
var data = factory.CreateNewOverrideCompletionData(
declarationBegin,
currentType,
m
);
// check if the member is already implemented
bool foundMember = curType.GetMembers().Any(cm => SignatureComparer.Ordinal.Equals(
cm,
m
) && cm.DeclaringTypeDefinition == curType.GetDefinition()
);
if (foundMember) {
continue;
}
if (alreadyInserted.Any(cm => SignatureComparer.Ordinal.Equals(cm, m)))
continue;
alreadyInserted.Add(m);
data.CompletionCategory = col.GetCompletionCategory(m.DeclaringTypeDefinition);
col.Add(data);
}
}
示例5: GetPartialCompletionData
IEnumerable<ICompletionData> GetPartialCompletionData(ITypeDefinition type, string modifiers)
{
var wrapper = new CompletionDataWrapper(this);
int declarationBegin = offset;
int j = declarationBegin;
for (int i = 0; i < 3; i++) {
switch (GetPreviousToken(ref j, true)) {
case "public":
case "protected":
case "private":
case "internal":
case "sealed":
case "override":
case "partial":
case "async":
declarationBegin = j;
break;
case "static":
return null; // don't add override completion for static members
}
}
var methods = new List<IUnresolvedMethod>();
foreach (var part in type.Parts) {
foreach (var method in part.Methods) {
if (method.BodyRegion.IsEmpty) {
if (GetImplementation(type, method) != null) {
continue;
}
methods.Add(method);
}
}
}
foreach (var method in methods) {
wrapper.Add(factory.CreateNewPartialCompletionData(
declarationBegin,
method.DeclaringTypeDefinition,
method
)
);
}
return wrapper.Result;
}
示例6: AddDelegateHandlers
string AddDelegateHandlers(CompletionDataWrapper completionList, IType delegateType, bool addSemicolon = true, bool addDefault = true, string optDelegateName = null)
{
IMethod delegateMethod = delegateType.GetDelegateInvokeMethod();
PossibleDelegates.Add(delegateMethod);
var thisLineIndent = GetLineIndent(location.Line);
string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : "");
//bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate("));
if (addDefault && !completionList.AnonymousDelegateAdded) {
completionList.AnonymousDelegateAdded = true;
var oldDelegate = completionList.Result.FirstOrDefault(cd => cd.DisplayText == "delegate");
if (oldDelegate != null)
completionList.Result.Remove(oldDelegate);
completionList.AddCustom(
"delegate",
"Creates anonymous delegate.",
"delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate",
"Creates anonymous async delegate.",
"async delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
}
}
var sb = new StringBuilder("(");
var sbWithoutTypes = new StringBuilder("(");
var state = GetState();
var builder = new TypeSystemAstBuilder(state);
for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
if (k > 0) {
sb.Append(", ");
sbWithoutTypes.Append(", ");
}
var convertedParameter = builder.ConvertParameter(delegateMethod.Parameters [k]);
if (convertedParameter.ParameterModifier == ParameterModifier.Params)
convertedParameter.ParameterModifier = ParameterModifier.None;
sb.Append(convertedParameter.ToString(FormattingPolicy));
sbWithoutTypes.Append(delegateMethod.Parameters [k].Name);
}
sb.Append(")");
sbWithoutTypes.Append(")");
var signature = sb.ToString();
if (!completionList.HasAnonymousDelegateAdded(signature)) {
completionList.AddAnonymousDelegateAdded(signature);
completionList.AddCustom(
"delegate" + signature,
"Creates anonymous delegate.",
"delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate" + signature,
"Creates anonymous async delegate.",
"async delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
}
if (!completionList.Result.Any(data => data.DisplayText == sb.ToString())) {
completionList.AddCustom(
signature,
"Creates typed lambda expression.",
signature + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + signature,
"Creates typed async lambda expression.",
"async " + signature + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
}
if (!delegateMethod.Parameters.Any(p => p.IsOut || p.IsRef) && !completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) {
completionList.AddCustom(
sbWithoutTypes.ToString(),
"Creates lambda expression.",
sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + sbWithoutTypes,
"Creates async lambda expression.",
"async " + sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
}
}
}
}
string varName = optDelegateName ?? "Handle" + delegateType.Name;
var ecd = factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType);
ecd.DisplayFlags |= DisplayFlags.MarkedBold;
completionList.Add(ecd);
return sb.ToString();
//.........这里部分代码省略.........
示例7: AddVirtuals
void AddVirtuals (Dictionary<string, bool> alreadyInserted, CompletionDataWrapper col, string modifiers, IType curType, int declarationBegin)
{
if (curType == null)
return;
foreach (var m in curType.GetMethods (m => !m.IsConstructor && !m.IsDestructor).Cast<IMember> ().Concat (curType.GetProperties ().Cast<IMember> ()).Reverse ()) {
if (m.IsSynthetic || curType.Kind != TypeKind.Interface && !m.IsOverridable)
continue;
// filter out the "Finalize" methods, because finalizers should be done with destructors.
if (m is IMethod && m.Name == "Finalize")
continue;
var data = factory.CreateNewOverrideCompletionData (declarationBegin, currentType, m);
string text = GetNameWithParamCount (m);
// check if the member is already implemented
bool foundMember = curType.GetMembers ().Any (cm => GetNameWithParamCount (cm) == text && cm.DeclaringTypeDefinition == curType.GetDefinition ());
if (foundMember)
continue;
if (alreadyInserted.ContainsKey (text))
continue;
alreadyInserted [text] = true;
data.CompletionCategory = col.GetCompletionCategory (curType);
col.Add (data);
}
}