本文整理汇总了C#中UnaryOperatorType类的典型用法代码示例。如果您正苦于以下问题:C# UnaryOperatorType类的具体用法?C# UnaryOperatorType怎么用?C# UnaryOperatorType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryOperatorType类属于命名空间,在下文中一共展示了UnaryOperatorType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:7,代码来源:UnaryOperatorExpressionTests.cs
示例2: Decide
internal static UnaryNumericPromotionDecision Decide(Type type, UnaryOperatorType @operator) {
if (!IsNumericPromotion(type, @operator)) {
return NonNumericPromotion;
}
return new UnaryNumericPromotionDecision(type, @operator);
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:UnaryNumericPromotionDecision.cs
示例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);
}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:7,代码来源:UnaryOperatorExpressionTests.cs
示例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;
}
开发者ID:sbeparey,项目名称:ILSpy,代码行数:8,代码来源:OperatorResolveResult.cs
示例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);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:9,代码来源:UnaryOperatorExpressionTests.cs
示例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;
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:9,代码来源:UnaryNumericPromotionDecision.cs
示例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);
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:20,代码来源:UnaryNumericPromotionDecision.cs
示例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;
}
开发者ID:holmak,项目名称:NRefactory,代码行数:25,代码来源:CSharpResolver.cs
示例9: UnaryOperatorExpression
public UnaryOperatorExpression(UnaryOperatorType op)
{
}
开发者ID:SergeTruth,项目名称:OxyChart,代码行数:3,代码来源:Expressions.cs
示例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");
}
开发者ID:stuman08,项目名称:boo,代码行数:11,代码来源:ProcessMethodBodies.cs
示例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) {
//.........这里部分代码省略.........
开发者ID:holmak,项目名称:NRefactory,代码行数:101,代码来源:CSharpResolver.cs
示例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;
}
开发者ID:Ein,项目名称:monodevelop,代码行数:14,代码来源:ResolveVisitor.cs
示例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);
}
}
开发者ID:ropean,项目名称:Usable,代码行数:26,代码来源:ExpressionTreeConverter.cs
示例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 });
}
开发者ID:nieve,项目名称:NRefactory,代码行数:6,代码来源:CSharpResolver.cs
示例15: UnaryOperatorExpression
public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) {
Expression = expression;
Op = op;
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:4,代码来源:Generated.cs
示例16: GetEquivalentBinaryOperator
BinaryOperatorType GetEquivalentBinaryOperator(UnaryOperatorType op)
{
return op == UnaryOperatorType.Increment || op == UnaryOperatorType.PostIncrement
? BinaryOperatorType.Addition
: BinaryOperatorType.Subtraction;
}
开发者ID:Bombadil77,项目名称:boo,代码行数:6,代码来源:ProcessMethodBodies.cs
示例17: ResolveUnaryOperator
public ResolveResult ResolveUnaryOperator(UnaryOperatorType op, ResolveResult expression)
{
if (expression.Type.Kind == TypeKind.Dynamic) {
if (op == UnaryOperatorType.Await) {
return new AwaitResolveResult(SpecialType.Dynamic, new DynamicInvocationResolveResult(new DynamicMemberResolveResult(expression, "GetAwaiter"), DynamicInvocationType.Invocation, EmptyList<ResolveResult>.Instance), SpecialType.Dynamic, null, null, null);
}
else {
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, NameLookupMode.InvocationTarget);
ResolveResult getAwaiterInvocation = ResolveInvocation(getAwaiterMethodGroup, new ResolveResult[0], argumentNames: null, allowOptionalParameters: false);
var lookup = CreateMemberLookup();
IMethod getResultMethod;
IType awaitResultType;
var getResultMethodGroup = lookup.Lookup(getAwaiterInvocation, "GetResult", EmptyList<IType>.Instance, true) as MethodGroupResolveResult;
if (getResultMethodGroup != null) {
var getResultOR = getResultMethodGroup.PerformOverloadResolution(compilation, new ResolveResult[0], allowExtensionMethods: false, conversions: conversions);
getResultMethod = getResultOR.FoundApplicableCandidate ? getResultOR.GetBestCandidateWithSubstitutedTypeArguments() as IMethod : null;
awaitResultType = getResultMethod != null ? getResultMethod.ReturnType : SpecialType.UnknownType;
}
else {
getResultMethod = null;
awaitResultType = SpecialType.UnknownType;
}
var isCompletedRR = lookup.Lookup(getAwaiterInvocation, "IsCompleted", EmptyList<IType>.Instance, false);
var isCompletedProperty = (isCompletedRR is MemberResolveResult ? ((MemberResolveResult)isCompletedRR).Member as IProperty : null);
if (isCompletedProperty != null && (!isCompletedProperty.ReturnType.IsKnownType(KnownTypeCode.Boolean) || !isCompletedProperty.CanGet))
isCompletedProperty = null;
var interfaceOnCompleted = compilation.FindType(KnownTypeCode.INotifyCompletion).GetMethods().FirstOrDefault(x => x.Name == "OnCompleted");
var interfaceUnsafeOnCompleted = compilation.FindType(KnownTypeCode.ICriticalNotifyCompletion).GetMethods().FirstOrDefault(x => x.Name == "UnsafeOnCompleted");
IMethod onCompletedMethod = null;
var candidates = getAwaiterInvocation.Type.GetMethods().Where(x => x.ImplementedInterfaceMembers.Select(y => y.MemberDefinition).Contains(interfaceUnsafeOnCompleted)).ToList();
if (candidates.Count == 0) {
candidates = getAwaiterInvocation.Type.GetMethods().Where(x => x.ImplementedInterfaceMembers.Select(y => y.MemberDefinition).Contains(interfaceOnCompleted)).ToList();
if (candidates.Count == 1)
onCompletedMethod = candidates[0];
}
else if (candidates.Count == 1) {
onCompletedMethod = candidates[0];
}
return new AwaitResolveResult(awaitResultType, getAwaiterInvocation, getAwaiterInvocation.Type, isCompletedProperty, onCompletedMethod, getResultMethod);
}
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 = CreateOverloadResolution(new[] { expression });
foreach (var candidate in GetUserDefinedOperatorCandidates(type, overloadableOperatorName)) {
userDefinedOperatorOR.AddCandidate(candidate);
}
if (userDefinedOperatorOR.FoundApplicableCandidate) {
return CreateResolveResultForUserDefinedOperator(userDefinedOperatorOR, UnaryOperatorExpression.GetLinqNodeType(op, this.CheckForOverflow));
}
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.Char && code <= TypeCode.Decimal) || type.Kind == TypeKind.Enum || type.Kind == TypeKind.Pointer)
return UnaryOperatorResolveResult(expression.Type, op, expression, isNullable);
else
return new ErrorResolveResult(expression.Type);
case UnaryOperatorType.Plus:
methodGroup = operators.UnaryPlusOperators;
break;
case UnaryOperatorType.Minus:
methodGroup = CheckForOverflow ? operators.CheckedUnaryMinusOperators : operators.UncheckedUnaryMinusOperators;
//.........这里部分代码省略.........
开发者ID:CSRedRat,项目名称:NRefactory,代码行数:101,代码来源:CSharpResolver.cs
示例18: FindUnaryOperatorNavigator
public FindUnaryOperatorNavigator(IMethod op, UnaryOperatorType operatorType)
{
this.op = op;
this.operatorType = operatorType;
}
开发者ID:artifexor,项目名称:NRefactory,代码行数:5,代码来源:FindReferences.cs
示例19: MatchFactorNode
protected MatchFactorNode(UnaryOperatorType op = UnaryOperatorType.None, MatchFactorNode next = null)
{
OpType = op;
Next = next;
}
开发者ID:KJTsanaktsidis,项目名称:rx2,代码行数:5,代码来源:MatchFactorNode.cs
示例20: FindUnaryOperator
SearchScope FindUnaryOperator(IMethod op, UnaryOperatorType operatorType)
{
return FindOperator(op, m => new FindUnaryOperatorNavigator(m, operatorType));
}
开发者ID:artifexor,项目名称:NRefactory,代码行数:4,代码来源:FindReferences.cs
注:本文中的UnaryOperatorType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论