本文整理汇总了C#中Symbol.IsOperator方法的典型用法代码示例。如果您正苦于以下问题:C# Symbol.IsOperator方法的具体用法?C# Symbol.IsOperator怎么用?C# Symbol.IsOperator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol
的用法示例。
在下文中一共展示了Symbol.IsOperator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReportDefaultParameterErrors
//.........这里部分代码省略.........
{
// error CS1751: Cannot specify a default value for a parameter array
diagnostics.Add(ErrorCode.ERR_DefaultValueForParamsParameter, paramsKeyword.GetLocation());
hasErrors = true;
}
else if (thisKeyword.Kind() == SyntaxKind.ThisKeyword)
{
// Only need to report CS1743 for the first parameter. The caller will
// have reported CS1100 if 'this' appeared on another parameter.
if (parameter.Ordinal == 0)
{
// error CS1743: Cannot specify a default value for the 'this' parameter
diagnostics.Add(ErrorCode.ERR_DefaultValueForExtensionParameter, thisKeyword.GetLocation());
hasErrors = true;
}
}
else if (!defaultExpression.HasAnyErrors && !isValidDefaultValue)
{
// error CS1736: Default parameter value for '{0}' must be a compile-time constant
diagnostics.Add(ErrorCode.ERR_DefaultValueMustBeConstant, parameterSyntax.Default.Value.Location, parameterSyntax.Identifier.ValueText);
hasErrors = true;
}
else if (!conversion.Exists ||
conversion.IsUserDefined ||
conversion.IsIdentity && parameterType.SpecialType == SpecialType.System_Object && defaultExpression.Type.IsDynamic())
{
// If we had no implicit conversion, or a user-defined conversion, report an error.
//
// Even though "object x = (dynamic)null" is a legal identity conversion, we do not allow it.
// CONSIDER: We could. Doesn't hurt anything.
// error CS1750: A value of type '{0}' cannot be used as a default parameter because there are no standard conversions to type '{1}'
diagnostics.Add(ErrorCode.ERR_NoConversionForDefaultParam, parameterSyntax.Identifier.GetLocation(),
defaultExpression.Type ?? defaultExpression.Display, parameterType);
hasErrors = true;
}
else if (conversion.IsReference &&
(parameterType.SpecialType == SpecialType.System_Object || parameterType.Kind == SymbolKind.DynamicType) &&
(object)defaultExpression.Type != null &&
defaultExpression.Type.SpecialType == SpecialType.System_String ||
conversion.IsBoxing)
{
// We don't allow object x = "hello", object x = 123, dynamic x = "hello", etc.
// error CS1763: '{0}' is of type '{1}'. A default parameter value of a reference type other than string can only be initialized with null
diagnostics.Add(ErrorCode.ERR_NotNullRefDefaultParameter, parameterSyntax.Identifier.GetLocation(),
parameterSyntax.Identifier.ValueText, parameterType);
hasErrors = true;
}
else if (conversion.IsNullable && defaultExpression.Kind == BoundKind.DefaultOperator && !defaultExpression.Type.IsNullableType() &&
!(parameterType.GetNullableUnderlyingType().IsEnumType() || parameterType.GetNullableUnderlyingType().IsIntrinsicType()))
{
// We can do:
// M(int? x = default(int))
// M(int? x = default(int?))
// M(MyEnum? e = default(enum))
// M(MyEnum? e = default(enum?))
// M(MyStruct? s = default(MyStruct?))
//
// but we cannot do:
//
// M(MyStruct? s = default(MyStruct))
// error CS1770:
// A value of type '{0}' cannot be used as default parameter for nullable parameter '{1}' because '{0}' is not a simple type
diagnostics.Add(ErrorCode.ERR_NoConversionForNubDefaultParam, parameterSyntax.Identifier.GetLocation(),
defaultExpression.Type, parameterSyntax.Identifier.ValueText);
hasErrors = true;
}
// Certain contexts allow default parameter values syntactically but they are ignored during
// semantic analysis. They are:
// 1. Explicitly implemented interface methods; since the method will always be called
// via the interface, the defaults declared on the implementation will not
// be seen at the call site.
//
// UNDONE: 2. The "actual" side of a partial method; the default values are taken from the
// UNDONE: "declaring" side of the method.
//
// UNDONE: 3. An indexer with only one formal parameter; it is illegal to omit every argument
// UNDONE: to an indexer.
//
// 4. A user-defined operator; it is syntactically impossible to omit the argument.
if (owner.IsExplicitInterfaceImplementation() ||
owner.IsPartialImplementation() ||
owner.IsOperator())
{
// CS1066: The default value specified for parameter '{0}' will have no effect because it applies to a
// member that is used in contexts that do not allow optional arguments
diagnostics.Add(ErrorCode.WRN_DefaultValueForUnconsumedLocation,
parameterSyntax.Identifier.GetLocation(),
parameterSyntax.Identifier.ValueText);
}
return hasErrors;
}
示例2: ReportParameterErrors
private static void ReportParameterErrors(
Symbol owner,
ParameterSyntax parameterSyntax,
SourceParameterSymbol parameter,
int firstDefault,
DiagnosticBag diagnostics)
{
TypeSymbol parameterType = parameter.Type;
int parameterIndex = parameter.Ordinal;
bool isDefault = parameterSyntax.Default != null;
SyntaxToken thisKeyword = parameterSyntax.Modifiers.FirstOrDefault(SyntaxKind.ThisKeyword);
if (thisKeyword.Kind() == SyntaxKind.ThisKeyword && parameterIndex != 0)
{
// Report CS1100 on "this". Note that is a change from Dev10
// which reports the error on the type following "this".
// error CS1100: Method '{0}' has a parameter modifier 'this' which is not on the first parameter
diagnostics.Add(ErrorCode.ERR_BadThisParam, thisKeyword.GetLocation(), owner.Name);
}
else if (parameter.IsParams && owner.IsOperator())
{
// error CS1670: params is not valid in this context
diagnostics.Add(ErrorCode.ERR_IllegalParams, parameterSyntax.Modifiers.First(t => t.Kind() == SyntaxKind.ParamsKeyword).GetLocation());
}
else if (parameter.IsParams && !parameterType.IsSingleDimensionalArray())
{
// error CS0225: The params parameter must be a single dimensional array
diagnostics.Add(ErrorCode.ERR_ParamsMustBeArray, parameterSyntax.Modifiers.First(t => t.Kind() == SyntaxKind.ParamsKeyword).GetLocation());
}
else if (parameter.Type.IsStatic && !parameter.ContainingSymbol.ContainingType.IsInterfaceType())
{
// error CS0721: '{0}': static types cannot be used as parameters
diagnostics.Add(ErrorCode.ERR_ParameterIsStaticClass, owner.Locations[0], parameter.Type);
}
else if (firstDefault != -1 && parameterIndex > firstDefault && !isDefault && !parameter.IsParams)
{
// error CS1737: Optional parameters must appear after all required parameters
Location loc = parameterSyntax.Identifier.GetNextToken(includeZeroWidth: true).GetLocation(); //could be missing
diagnostics.Add(ErrorCode.ERR_DefaultValueBeforeRequiredValue, loc);
}
else if (parameter.RefKind != RefKind.None && parameter.Type.IsRestrictedType())
{
// CS1601: Cannot make reference to variable of type 'System.TypedReference'
diagnostics.Add(ErrorCode.ERR_MethodArgCantBeRefAny, parameterSyntax.Location, parameter.Type);
}
}
示例3: CheckNonOverrideMember
private static void CheckNonOverrideMember(
Symbol hidingMember,
bool hidingMemberIsNew,
OverriddenOrHiddenMembersResult overriddenOrHiddenMembers,
DiagnosticBag diagnostics, out bool suppressAccessors)
{
suppressAccessors = false;
var hidingMemberLocation = hidingMember.Locations[0];
Debug.Assert(overriddenOrHiddenMembers != null);
Debug.Assert(!overriddenOrHiddenMembers.OverriddenMembers.Any()); //since hidingMethod.IsOverride is false
Debug.Assert(!overriddenOrHiddenMembers.RuntimeOverriddenMembers.Any()); //since hidingMethod.IsOverride is false
var hiddenMembers = overriddenOrHiddenMembers.HiddenMembers;
Debug.Assert(!hiddenMembers.IsDefault);
if (hiddenMembers.Length == 0)
{
if (hidingMemberIsNew && !hidingMember.IsAccessor())
{
diagnostics.Add(ErrorCode.WRN_NewNotRequired, hidingMemberLocation, hidingMember);
}
}
else
{
var diagnosticAdded = false;
//for interfaces, we always report WRN_NewRequired
//if we went into the loop, the pseudo-abstract nature of interfaces would throw off the other checks
if (!hidingMember.ContainingType.IsInterface)
{
foreach (var hiddenMember in hiddenMembers)
{
diagnosticAdded |= AddHidingAbstractDiagnostic(hidingMember, hidingMemberLocation, hiddenMember, diagnostics, ref suppressAccessors);
//can actually get both, so don't use else if
if (!hidingMemberIsNew && hiddenMember.Kind == hidingMember.Kind &&
!hidingMember.IsAccessor() &&
(hiddenMember.IsAbstract || hiddenMember.IsVirtual || hiddenMember.IsOverride))
{
diagnostics.Add(ErrorCode.WRN_NewOrOverrideExpected, hidingMemberLocation, hidingMember, hiddenMember);
diagnosticAdded = true;
}
if (diagnosticAdded)
{
break;
}
}
}
if (!hidingMemberIsNew && !diagnosticAdded && !hidingMember.IsAccessor() && !hidingMember.IsOperator())
{
diagnostics.Add(ErrorCode.WRN_NewRequired, hidingMemberLocation, hidingMember, hiddenMembers[0]);
}
}
}