本文整理汇总了C#中ISymbol.IsIndexer方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.IsIndexer方法的具体用法?C# ISymbol.IsIndexer怎么用?C# ISymbol.IsIndexer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.IsIndexer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetPropertyAccessorReferences
public bool TryGetPropertyAccessorReferences(ISymbol semanticProperty, out IMethodReference getter, out IMethodReference setter) {
Contract.Requires(semanticProperty == null || semanticProperty.Kind == SymbolKind.Property);
getter = setter = null;
#region Check input
if (semanticProperty == null) {
return false;
}
#endregion
#region Check cache
Tuple<IMethodReference, IMethodReference> cacheOutput;
if (_semanticPropertiesToCCIAccessorMethods.TryGetValue(semanticProperty, out cacheOutput)) {
Contract.Assume(cacheOutput != null, "Non-null only dictionary");
getter = cacheOutput.Item1;
setter = cacheOutput.Item2;
return (getter != null && getter != Dummy.MethodReference) || (setter != null && setter != Dummy.MethodReference);
}
#endregion
#region Get calling conventions
var callingConventions = CSharpToCCIHelper.GetCallingConventionFor(semanticProperty);
#endregion
#region get containing type
ITypeReference containingType;
if (!TryGetTypeReference(semanticProperty.ContainingType, out containingType))
goto ReturnFalse;
#endregion
#region Get return type
ITypeReference returnType;
if (!TryGetTypeReference(semanticProperty.ReturnType(), out returnType))
goto ReturnFalse;
#endregion
#region Get the property's name
string propertyName;
if (semanticProperty.IsIndexer())
propertyName = "Item";
else
{
if (semanticProperty.Name == null) goto ReturnFalse;
propertyName = semanticProperty.Name;
}
#endregion
#region Get the parameters
List<IParameterTypeInformation> getterParams;
if (!semanticProperty.Parameters().IsDefault) {
if (!TryGetParametersList(semanticProperty.Parameters(), out getterParams))
goto ReturnFalse;
} else
getterParams = new List<IParameterTypeInformation>();
List<IParameterTypeInformation> setterParams;
if (!semanticProperty.Parameters().IsDefault) {
if (!TryGetParametersList(semanticProperty.Parameters(), out setterParams, 1))
goto ReturnFalse;
#region Append the "value" param
var valParam = new Microsoft.Cci.MutableCodeModel.ParameterTypeInformation() {
Type = returnType,
Index = 0,
IsByReference = false
};
setterParams.Insert(0, valParam);
#endregion
} else
setterParams = new List<IParameterTypeInformation>();
#endregion
#region Build the getter
getter = new Microsoft.Cci.MutableCodeModel.MethodReference() {
InternFactory = Host.InternFactory,
CallingConvention = callingConventions,
ContainingType = containingType,
Type = returnType,
Name = Host.NameTable.GetNameFor("get_" + propertyName),
GenericParameterCount = 0,
Parameters = getterParams
};
#endregion
#region Build the setter
setter = new Microsoft.Cci.MutableCodeModel.MethodReference() {
InternFactory = Host.InternFactory,
CallingConvention = callingConventions,
ContainingType = containingType,
Type = Host.PlatformType.SystemVoid,
Name = Host.NameTable.GetNameFor("set_" + propertyName),
GenericParameterCount = 0,
Parameters = setterParams
};
#endregion
#region Get the assembly reference (this also ensures the assembly gets loaded properly)
IAssemblyReference assemblyReference;
TryGetAssemblyReference(semanticProperty.ContainingAssembly, out assemblyReference);
#endregion
#region ReturnTrue:
//ReturnTrue:
_semanticPropertiesToCCIAccessorMethods[semanticProperty] = new Tuple<IMethodReference, IMethodReference>(getter, setter);
return true;
#endregion
#region ReturnFalse:
ReturnFalse:
if (semanticProperty.Name != null)
{
//.........这里部分代码省略.........
示例2: CreateItemAsync
private async Task<CompletionItem> CreateItemAsync(
Workspace workspace, SemanticModel semanticModel, int textChangeSpanPosition, ISymbol symbol, SyntaxToken token, CancellationToken cancellationToken)
{
int tokenPosition = token.SpanStart;
string symbolText = string.Empty;
if (symbol is INamespaceOrTypeSymbol && token.IsKind(SyntaxKind.DotToken))
{
symbolText = symbol.Name.EscapeIdentifier();
if (symbol.GetArity() > 0)
{
symbolText += "{";
symbolText += string.Join(", ", ((INamedTypeSymbol)symbol).TypeParameters);
symbolText += "}";
}
}
else
{
symbolText = symbol.ToMinimalDisplayString(semanticModel, tokenPosition, CrefFormat);
var parameters = symbol.GetParameters().Select(p =>
{
var displayName = p.Type.ToMinimalDisplayString(semanticModel, tokenPosition);
if (p.RefKind == RefKind.Out)
{
return "out " + displayName;
}
if (p.RefKind == RefKind.Ref)
{
return "ref " + displayName;
}
return displayName;
});
var parameterList = !symbol.IsIndexer() ? string.Format("({0})", string.Join(", ", parameters))
: string.Format("[{0}]", string.Join(", ", parameters));
symbolText += parameterList;
}
var insertionText = symbolText
.Replace('<', '{')
.Replace('>', '}')
.Replace("()", "");
var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
return new CrefCompletionItem(
workspace,
completionProvider: this,
displayText: insertionText,
insertionText: insertionText,
textSpan: GetTextChangeSpan(text, textChangeSpanPosition),
descriptionFactory: CommonCompletionUtilities.CreateDescriptionFactory(workspace, semanticModel, tokenPosition, symbol),
glyph: symbol.GetGlyph(),
sortText: symbolText);
}
示例3: CreateItem
private CompletionItem CreateItem(
Workspace workspace, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, StringBuilder builder)
{
int position = token.SpanStart;
if (symbol is INamespaceOrTypeSymbol && token.IsKind(SyntaxKind.DotToken))
{
// Handle qualified namespace and type names.
builder.Append(symbol.ToDisplayString(QualifiedCrefFormat));
}
else
{
// Handle unqualified namespace and type names, or member names.
builder.Append(symbol.ToMinimalDisplayString(semanticModel, position, CrefFormat));
var parameters = symbol.GetParameters();
if (!parameters.IsDefaultOrEmpty)
{
// Note: we intentionally don't add the "params" modifier for any parameters.
builder.Append(symbol.IsIndexer() ? '[' : '(');
for (int i = 0; i < parameters.Length; i++)
{
if (i > 0)
{
builder.Append(", ");
}
var parameter = parameters[i];
if (parameter.RefKind == RefKind.Out)
{
builder.Append("out ");
}
else if (parameter.RefKind == RefKind.Ref)
{
builder.Append("ref ");
}
builder.Append(parameter.Type.ToMinimalDisplayString(semanticModel, position));
}
builder.Append(symbol.IsIndexer() ? ']' : ')');
}
}
var symbolText = builder.ToString();
var insertionText = builder
.Replace('<', '{')
.Replace('>', '}')
.ToString();
return SymbolCompletionItem.Create(
displayText: insertionText,
insertionText: insertionText,
symbol: symbol,
contextPosition: position,
sortText: symbolText,
rules: GetRules(insertionText));
}
示例4: GetSearchName
private static string GetSearchName(ISymbol symbol)
{
if (symbol.IsConstructor() || symbol.IsStaticConstructor())
{
return symbol.ContainingType.Name;
}
else if (symbol.IsIndexer() && symbol.Name == WellKnownMemberNames.Indexer)
{
return "this";
}
return symbol.Name;
}