本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbol.GetTypeOrReturnType方法的典型用法代码示例。如果您正苦于以下问题:C# Symbol.GetTypeOrReturnType方法的具体用法?C# Symbol.GetTypeOrReturnType怎么用?C# Symbol.GetTypeOrReturnType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbol
的用法示例。
在下文中一共展示了Symbol.GetTypeOrReturnType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemberGroupFinalValidationAccessibilityChecks
/// <summary>
/// Performs the following checks:
///
/// Spec 7.6.5: Invocation expressions (definition of Final Validation)
/// The method is validated in the context of the method group: If the best method is a static method,
/// the method group must have resulted from a simple-name or a member-access through a type. If the best
/// method is an instance method, the method group must have resulted from a simple-name, a member-access
/// through a variable or value, or a base-access. If neither of these requirements is true, a binding-time
/// error occurs.
/// (Note that the spec omits to mention, in the case of an instance method invoked through a simple name, that
/// the invocation must appear within the body of an instance method)
///
/// Spec 7.5.4: Compile-time checking of dynamic overload resolution
/// If F is a static method, the method group must have resulted from a simple-name, a member-access through a type,
/// or a member-access whose receiver can’t be classified as a type or value until after overload resolution (see §7.6.4.1).
/// If F is an instance method, the method group must have resulted from a simple-name, a member-access through a variable or value,
/// or a member-access whose receiver can’t be classified as a type or value until after overload resolution (see §7.6.4.1).
/// </summary>
/// <returns>
/// True if there is any error.
/// </returns>
private bool MemberGroupFinalValidationAccessibilityChecks(BoundExpression receiverOpt, Symbol memberSymbol, CSharpSyntaxNode node, DiagnosticBag diagnostics, bool invokedAsExtensionMethod)
{
// Perform final validation of the method to be invoked.
Debug.Assert(memberSymbol.Kind != SymbolKind.Method || memberSymbol.CanBeReferencedByName); //should be true since the caller has LookupOptions.MustBeReferenceableByName set
//note that the same assert does not hold for all properties. Some properties and (all indexers) are not referenceable by name, yet
//their binding brings them through here, perhaps needlessly.
if (receiverOpt != null && receiverOpt.Kind == BoundKind.TypeOrValueExpression)
{
// TypeOrValue expression isn't replaced only if the invocation is late bound, in which case it can't be extension method.
// None of the checks below apply if the receiver can’t be classified as a type or value.
Debug.Assert(!invokedAsExtensionMethod);
}
else if (memberSymbol.IsStatic)
{
Debug.Assert(!invokedAsExtensionMethod || (receiverOpt != null));
if (!invokedAsExtensionMethod && !WasImplicitReceiver(receiverOpt) && IsMemberAccessedThroughVariableOrValue(receiverOpt))
{
if (this.Flags.Includes(BinderFlags.CollectionInitializerAddMethod))
{
diagnostics.Add(ErrorCode.ERR_InitializerAddHasWrongSignature, node.Location, memberSymbol);
}
else if (node.Kind == SyntaxKind.AwaitExpression && memberSymbol.Name == WellKnownMemberNames.GetAwaiter)
{
diagnostics.Add(ErrorCode.ERR_BadAwaitArg, node.Location, receiverOpt.Type);
}
else
{
diagnostics.Add(ErrorCode.ERR_ObjectProhibited, node.Location, memberSymbol);
}
return true;
}
}
else if (IsMemberAccessedThroughType(receiverOpt))
{
diagnostics.Add(ErrorCode.ERR_ObjectRequired, node.Location, memberSymbol);
return true;
}
else if (WasImplicitReceiver(receiverOpt))
{
if (InFieldInitializer && !ContainingType.IsScriptClass || InConstructorInitializer || InAttributeArgument)
{
CSharpSyntaxNode errorNode = node;
if (node.Parent != null && node.Parent.Kind == SyntaxKind.InvocationExpression)
{
errorNode = node.Parent;
}
ErrorCode code = InFieldInitializer ? ErrorCode.ERR_FieldInitRefNonstatic : ErrorCode.ERR_ObjectRequired;
diagnostics.Add(code, errorNode.Location, memberSymbol);
return true;
}
// If we could access the member thru implicit "this" the receiver would be a BoundThisReference.
// If it is null it means that the instance member is inaccessible.
if (receiverOpt == null || ContainingMember().IsStatic)
{
Error(diagnostics, ErrorCode.ERR_ObjectRequired, node, memberSymbol);
return true;
}
}
var containingType = this.ContainingType;
if ((object)containingType != null)
{
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
bool isAccessible = this.IsSymbolAccessibleConditional(memberSymbol.GetTypeOrReturnType(), containingType, ref useSiteDiagnostics);
diagnostics.Add(node, useSiteDiagnostics);
if (!isAccessible)
{
// In the presence of non-transitive [InternalsVisibleTo] in source, or obnoxious symbols from metadata, it is possible
// to select a method through overload resolution in which the type is not accessible. In this case a method cannot
// be called through normal IL, so we give an error. Neither [InternalsVisibleTo] nor the need for this diagnostic is
// described by the language specification.
//
// Dev11 perform different access checks. See bug #530360 and tests AccessCheckTests.InaccessibleReturnType.
Error(diagnostics, ErrorCode.ERR_BadAccess, node, memberSymbol);
//.........这里部分代码省略.........