本文整理汇总了C#中UnaryOperatorType类的典型用法代码示例。如果您正苦于以下问题:C# UnaryOperatorType类的具体用法?C# UnaryOperatorType怎么用?C# UnaryOperatorType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryOperatorType类属于命名空间,在下文中一共展示了UnaryOperatorType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CSharpTestUnaryOperatorExpressionTest
void CSharpTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op)
{
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>(program);
Assert.AreEqual(op, uoe.Op);
Assert.IsTrue(uoe.Expression is IdentifierExpression);
}
示例2: Decide
internal static UnaryNumericPromotionDecision Decide(Type type, UnaryOperatorType @operator) {
if (!IsNumericPromotion(type, @operator)) {
return NonNumericPromotion;
}
return new UnaryNumericPromotionDecision(type, @operator);
}
示例3: VBNetTestUnaryOperatorExpressionTest
void VBNetTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op)
{
UnaryOperatorExpression uoe = ParseUtil.ParseExpression<UnaryOperatorExpression>(program);
Assert.AreEqual(op, uoe.Op);
Assert.IsTrue(uoe.Expression is SimpleNameExpression);
}
示例4: UnaryOperatorResolveResult
public UnaryOperatorResolveResult(IType resultType, UnaryOperatorType op, ResolveResult input)
: base(resultType)
{
if (input == null)
throw new ArgumentNullException("input");
this.Operator = op;
this.Input = input;
}
示例5: TestUnaryOperatorExpressionTest
void TestUnaryOperatorExpressionTest(string program, UnaryOperatorType op)
{
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>(program);
Assert.AreEqual(op, uoe.Operator);
Assert.IsTrue(uoe.Expression is IdentifierExpression);
Assert.AreEqual(new TextLocation(1, 1), uoe.StartLocation);
Assert.AreEqual(new TextLocation(1, program.Length + 1), uoe.EndLocation);
}
示例6: IsNumericPromotion
private static bool IsNumericPromotion(Type type, UnaryOperatorType @operator) {
if (!type.IsNumeric() ||
type.Equals(TypeSystem.Boolean) ||
Array.IndexOf(_unaryOperators, @operator) == -1) {
return false;
}
return true;
}
示例7: UnaryNumericPromotionDecision
private UnaryNumericPromotionDecision(Type type, UnaryOperatorType @operator) {
switch (@operator) {
case UnaryOperatorType.BitNot:
case UnaryOperatorType.Minus:
case UnaryOperatorType.Plus:
if (Array.IndexOf(_convertableTypes, type) > -1) {
Type = new TypePromotionDecision(type, TypeSystem.Int);
return;
}
if (@operator == UnaryOperatorType.Minus && type.Equals(TypeSystem.Uint)) {
Type = new TypePromotionDecision(type, TypeSystem.Long);
return;
}
break;
}
Type = new TypePromotionDecision(type);
}
示例8: UnaryNumericPromotion
ResolveResult UnaryNumericPromotion(UnaryOperatorType op, ref IType type, bool isNullable, ResolveResult expression)
{
// C# 4.0 spec: §7.3.6.1
TypeCode code = ReflectionHelper.GetTypeCode(type);
if (isNullable && SpecialType.NullType.Equals(type))
code = TypeCode.SByte; // cause promotion of null to int32
switch (op) {
case UnaryOperatorType.Minus:
if (code == TypeCode.UInt32) {
type = compilation.FindType(KnownTypeCode.Int64);
return Convert(expression, MakeNullable(type, isNullable),
isNullable ? Conversion.ImplicitNullableConversion : Conversion.ImplicitNumericConversion);
}
goto case UnaryOperatorType.Plus;
case UnaryOperatorType.Plus:
case UnaryOperatorType.BitNot:
if (code >= TypeCode.Char && code <= TypeCode.UInt16) {
type = compilation.FindType(KnownTypeCode.Int32);
return Convert(expression, MakeNullable(type, isNullable),
isNullable ? Conversion.ImplicitNullableConversion : Conversion.ImplicitNumericConversion);
}
break;
}
return expression;
}
示例9: UnaryOperatorExpression
public UnaryOperatorExpression(UnaryOperatorType op)
{
}
示例10: GetRelatedPreOperator
static UnaryOperatorType GetRelatedPreOperator(UnaryOperatorType op)
{
switch (op)
{
case UnaryOperatorType.PostIncrement:
return UnaryOperatorType.Increment;
case UnaryOperatorType.PostDecrement:
return UnaryOperatorType.Decrement;
}
throw new ArgumentException("op");
}
示例11: ResolveUnaryOperator
public ResolveResult ResolveUnaryOperator(UnaryOperatorType op, ResolveResult expression)
{
if (SpecialType.Dynamic.Equals(expression.Type))
return UnaryOperatorResolveResult(SpecialType.Dynamic, op, expression);
// C# 4.0 spec: §7.3.3 Unary operator overload resolution
string overloadableOperatorName = GetOverloadableOperatorName(op);
if (overloadableOperatorName == null) {
switch (op) {
case UnaryOperatorType.Dereference:
PointerType p = expression.Type as PointerType;
if (p != null)
return UnaryOperatorResolveResult(p.ElementType, op, expression);
else
return ErrorResult;
case UnaryOperatorType.AddressOf:
return UnaryOperatorResolveResult(new PointerType(expression.Type), op, expression);
case UnaryOperatorType.Await:
ResolveResult getAwaiterMethodGroup = ResolveMemberAccess(expression, "GetAwaiter", EmptyList<IType>.Instance, true);
ResolveResult getAwaiterInvocation = ResolveInvocation(getAwaiterMethodGroup, new ResolveResult[0]);
var getResultMethodGroup = CreateMemberLookup().Lookup(getAwaiterInvocation, "GetResult", EmptyList<IType>.Instance, true) as MethodGroupResolveResult;
if (getResultMethodGroup != null) {
var or = getResultMethodGroup.PerformOverloadResolution(compilation, new ResolveResult[0], allowExtensionMethods: false, conversions: conversions);
IType awaitResultType = or.GetBestCandidateWithSubstitutedTypeArguments().ReturnType;
return UnaryOperatorResolveResult(awaitResultType, UnaryOperatorType.Await, expression);
} else {
return UnaryOperatorResolveResult(SpecialType.UnknownType, UnaryOperatorType.Await, expression);
}
default:
throw new ArgumentException("Invalid value for UnaryOperatorType", "op");
}
}
// If the type is nullable, get the underlying type:
IType type = NullableType.GetUnderlyingType(expression.Type);
bool isNullable = NullableType.IsNullable(expression.Type);
// the operator is overloadable:
OverloadResolution userDefinedOperatorOR = new OverloadResolution(compilation, new[] { expression }, conversions: conversions);
foreach (var candidate in GetUserDefinedOperatorCandidates(type, overloadableOperatorName)) {
userDefinedOperatorOR.AddCandidate(candidate);
}
if (userDefinedOperatorOR.FoundApplicableCandidate) {
return CreateResolveResultForUserDefinedOperator(userDefinedOperatorOR);
}
expression = UnaryNumericPromotion(op, ref type, isNullable, expression);
CSharpOperators.OperatorMethod[] methodGroup;
CSharpOperators operators = CSharpOperators.Get(compilation);
switch (op) {
case UnaryOperatorType.Increment:
case UnaryOperatorType.Decrement:
case UnaryOperatorType.PostIncrement:
case UnaryOperatorType.PostDecrement:
// C# 4.0 spec: §7.6.9 Postfix increment and decrement operators
// C# 4.0 spec: §7.7.5 Prefix increment and decrement operators
TypeCode code = ReflectionHelper.GetTypeCode(type);
if ((code >= TypeCode.SByte && code <= TypeCode.Decimal) || type.Kind == TypeKind.Enum || type.Kind == TypeKind.Pointer)
return UnaryOperatorResolveResult(expression.Type, op, expression);
else
return new ErrorResolveResult(expression.Type);
case UnaryOperatorType.Plus:
methodGroup = operators.UnaryPlusOperators;
break;
case UnaryOperatorType.Minus:
methodGroup = CheckForOverflow ? operators.CheckedUnaryMinusOperators : operators.UncheckedUnaryMinusOperators;
break;
case UnaryOperatorType.Not:
methodGroup = operators.LogicalNegationOperators;
break;
case UnaryOperatorType.BitNot:
if (type.Kind == TypeKind.Enum) {
if (expression.IsCompileTimeConstant && !isNullable) {
// evaluate as (E)(~(U)x);
var U = compilation.FindType(expression.ConstantValue.GetType());
var unpackedEnum = new ConstantResolveResult(U, expression.ConstantValue);
return CheckErrorAndResolveCast(expression.Type, ResolveUnaryOperator(op, unpackedEnum));
} else {
return UnaryOperatorResolveResult(expression.Type, op, expression);
}
} else {
methodGroup = operators.BitwiseComplementOperators;
break;
}
default:
throw new InvalidOperationException();
}
OverloadResolution builtinOperatorOR = new OverloadResolution(compilation, new[] { expression }, conversions: conversions);
foreach (var candidate in methodGroup) {
builtinOperatorOR.AddCandidate(candidate);
}
CSharpOperators.UnaryOperatorMethod m = (CSharpOperators.UnaryOperatorMethod)builtinOperatorOR.BestCandidate;
IType resultType = m.ReturnType;
if (builtinOperatorOR.BestCandidateErrors != OverloadResolutionErrors.None) {
// If there are any user-defined operators, prefer those over the built-in operators.
// It'll be a more informative error.
if (userDefinedOperatorOR.BestCandidate != null)
return CreateResolveResultForUserDefinedOperator(userDefinedOperatorOR);
else
return new ErrorResolveResult(resultType);
} else if (expression.IsCompileTimeConstant && m.CanEvaluateAtCompileTime) {
//.........这里部分代码省略.........
示例12: GetOperatorName
static string GetOperatorName (UnaryOperatorType type)
{
switch (type) {
case UnaryOperatorType.Not:
return "op_LogicalNot";
case UnaryOperatorType.BitNot:
return "op_OnesComplement";
case UnaryOperatorType.Minus:
return "op_UnaryNegation";
case UnaryOperatorType.Plus:
return "op_UnaryPlus";
}
return null;
}
示例13: ConvertUnaryOperator
Expression ConvertUnaryOperator(InvocationExpression invocation, UnaryOperatorType op, bool? isChecked = null)
{
if (invocation.Arguments.Count < 1)
return NotSupported(invocation);
Expression expr = Convert(invocation.Arguments.ElementAt(0));
if (expr == null)
return null;
UnaryOperatorExpression uoe = new UnaryOperatorExpression(op, expr);
if (isChecked != null)
uoe.AddAnnotation(isChecked.Value ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation);
switch (invocation.Arguments.Count) {
case 1:
return uoe;
case 2:
Match m = getMethodFromHandlePattern.Match(invocation.Arguments.ElementAt(1));
if (m.Success)
return uoe.WithAnnotation(m.Get<AstNode>("method").Single().Annotation<MethodReference>());
else
return null;
default:
return NotSupported(invocation);
}
}
示例14: UnaryOperatorResolveResult
OperatorResolveResult UnaryOperatorResolveResult(IType resultType, UnaryOperatorType op, ResolveResult expression, bool isLifted = false)
{
return new OperatorResolveResult(
resultType, UnaryOperatorExpression.GetLinqNodeType(op, this.CheckForOverflow),
null, isLifted, new[] { expression });
}
示例15: UnaryOperatorExpression
public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) {
Expression = expression;
Op = op;
}