本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper.AddAnonymousDelegateAdded方法的典型用法代码示例。如果您正苦于以下问题:C# CompletionDataWrapper.AddAnonymousDelegateAdded方法的具体用法?C# CompletionDataWrapper.AddAnonymousDelegateAdded怎么用?C# CompletionDataWrapper.AddAnonymousDelegateAdded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper
的用法示例。
在下文中一共展示了CompletionDataWrapper.AddAnonymousDelegateAdded方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 () => )
//.........这里部分代码省略.........
示例2: 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();
//.........这里部分代码省略.........