本文整理汇总了C#中ICSharpCode.NRefactory.Ast.CastExpression类的典型用法代码示例。如果您正苦于以下问题:C# CastExpression类的具体用法?C# CastExpression怎么用?C# CastExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CastExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了CastExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitCastExpression
public override object VisitCastExpression(CastExpression castExpression, object data)
{
//This was the hardest achievement to write ever :p
UnlockWith(castExpression);
return base.VisitCastExpression(castExpression, data);
}
示例2: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression.TargetObject is FieldReferenceExpression)
{
FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
string methodName = targetObject.FieldName;
TypeDeclaration typeDeclaration = GetEnclosingTypeDeclaration(invocationExpression);
TypeDeclaration thisTypeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
if (typeDeclaration != null && IsTestFixture(thisTypeDeclaration))
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
IList specialMethods = GetMethods(methods, methodName);
if (ContainsInternalMethod(specialMethods))
{
Expression replacedExpression;
MethodDeclaration method = (MethodDeclaration) specialMethods[0];
bool staticMethod = AstUtil.ContainsModifier(method, Modifiers.Static);
replacedExpression = CreateReflectionInvocation(invocationExpression, staticMethod);
if (invocationExpression.Parent is Expression || invocationExpression.Parent is VariableDeclaration)
{
TypeReference returnType = GetInternalMethodReturnType(specialMethods);
CastExpression castExpression = new CastExpression(returnType, replacedExpression, CastType.Cast);
replacedExpression = castExpression;
}
ReplaceCurrentNode(replacedExpression);
}
}
}
return base.TrackedVisitInvocationExpression(invocationExpression, data);
}
示例3: VisitCastExpression
public override object VisitCastExpression(CastExpression castExpression, object data)
{
if (GetPrecedence(castExpression.Expression) > GetPrecedence(castExpression)) {
castExpression.Expression = Deparenthesize(castExpression.Expression);
}
return base.VisitCastExpression(castExpression, data);
}
示例4: GetCastExpression
private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression)
{
TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left);
CastExpression castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast);
ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift);
return new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast);
}
示例5: CreateDebugListExpression
/// <summary>
/// Creates an expression which, when evaluated, creates a List<T> in the debugee
/// filled with contents of IEnumerable<T> from the debugee.
/// </summary>
/// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
/// <param name="itemType">
/// The generic argument of IEnumerable<T> that <paramref name="iEnumerableVariable"/> implements.</param>
public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
{
// is using itemType.AppDomain ok?
listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
// explicitely cast the variable to IEnumerable<T>, where T is itemType
Expression iEnumerableVariableExplicitCast = new CastExpression(iEnumerableType.GetTypeReference() , iEnumerableVariable, CastType.Cast);
return new ObjectCreateExpression(listType.GetTypeReference(), iEnumerableVariableExplicitCast.ToList());
}
示例6: VisitCastExpression
public override object VisitCastExpression(CastExpression castExpression, object data)
{
if (castExpression.CastTo.Type == "int" &&
castExpression.Expression is MemberReferenceExpression &&
(castExpression.Expression as MemberReferenceExpression).MemberName == "Length") {
ReplaceCurrentNode(castExpression.Expression);
return null;
}
return base.VisitCastExpression(castExpression, data);
}
示例7: CreateDebugListExpression
/// <summary>
/// Creates an expression which, when evaluated, creates a List<T> in the debugee
/// filled with contents of IEnumerable<T> from the debugee.
/// </summary>
/// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
/// <param name="itemType">
/// The generic argument of IEnumerable<T> that <paramref name="iEnumerableVariable"/> implements.</param>
public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
{
// is using itemType.AppDomain ok?
listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
// explicitely cast the variable to IEnumerable<T>, where T is itemType
Expression iEnumerableVariableExplicitCast = new CastExpression { Expression = iEnumerableVariable.Clone() , Type = iEnumerableType.GetTypeReference() };
var obj = new ObjectCreateExpression() { Type = listType.GetTypeReference() };
obj.Arguments.Add(iEnumerableVariableExplicitCast);
return obj;
}
示例8: VisitLambdaExpression
public override object VisitLambdaExpression(ICSharpCode.NRefactory.Ast.LambdaExpression lambdaExpression, object data)
{
var invocationExpression = lambdaExpression.Parent as InvocationExpression;
if (invocationExpression == null)
return base.VisitLambdaExpression(lambdaExpression, data);
var target = invocationExpression.TargetObject as MemberReferenceExpression;
if(target == null)
return base.VisitLambdaExpression(lambdaExpression, data);
INode node = lambdaExpression;
var parenthesizedlambdaExpression = new ParenthesizedExpression(lambdaExpression);
switch (target.MemberName)
{
case "Sum":
case "Average":
node = ModifyLambdaForNumerics(lambdaExpression, parenthesizedlambdaExpression);
break;
case "Max":
case "Min":
node = ModifyLambdaForMinMax(lambdaExpression, parenthesizedlambdaExpression);
break;
case "OrderBy":
case "OrderByDescending":
case "GroupBy":
case "Recurse":
case "Select":
node = ModifyLambdaForSelect(parenthesizedlambdaExpression, target);
break;
case "SelectMany":
node = ModifyLambdaForSelectMany(lambdaExpression, parenthesizedlambdaExpression, invocationExpression);
break;
case "Any":
case "all":
case "First":
case "FirstOrDefault":
case "Last":
case "LastOfDefault":
case "Single":
case "Where":
case "Count":
case "SingleOrDefault":
node = new CastExpression(new TypeReference("Func<dynamic, bool>"), parenthesizedlambdaExpression, CastType.Cast);
break;
}
ReplaceCurrentNode(node);
return base.VisitLambdaExpression(lambdaExpression, data);
}
示例9: VisitCastExpression
public override object VisitCastExpression(CastExpression castExpression, object data)
{
if (castExpression.CastType == CastType.Cast) {
// Casts to value types are marked as conversions
// this code only supports primitive types, user-defined value types are handled by
// the DOM-aware CSharpToVBNetConvertVisitor
string type;
if (TypeReference.PrimitiveTypesCSharpReverse.TryGetValue(castExpression.CastTo.Type, out type)) {
if (type != "object" && type != "string") {
// type is value type
castExpression.CastType = CastType.Conversion;
}
}
}
return base.VisitCastExpression(castExpression, data);
}
示例10: VisitCastExpression
public override object VisitCastExpression(CastExpression castExpression, object data)
{
base.VisitCastExpression(castExpression, data);
if (castExpression.CastType == CastType.Conversion || castExpression.CastType == CastType.PrimitiveConversion) {
switch (castExpression.CastTo.Type) {
case "System.Boolean":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToBoolean");
case "System.Byte":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToByte");
case "System.Char":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToChar");
case "System.DateTime":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDateTime");
case "System.Decimal":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDecimal");
case "System.Double":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDouble");
case "System.Int16":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt16");
case "System.Int32":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt32");
case "System.Int64":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt64");
case "System.SByte":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToSByte");
case "System.Single":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToSingle");
case "System.String":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToString");
case "System.UInt16":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt16");
case "System.UInt32":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt32");
case "System.UInt64":
return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt64");
}
}
return null;
}
示例11: VisitCastExpression
public sealed override object VisitCastExpression(CastExpression castExpression, object data) {
this.BeginVisit(castExpression);
object result = this.TrackedVisitCastExpression(castExpression, data);
this.EndVisit(castExpression);
return result;
}
示例12: VisitCastExpression
public virtual object VisitCastExpression(CastExpression castExpression, object data) {
throw new global::System.NotImplementedException("CastExpression");
}
示例13: SimpleNonInvocationExpression
//.........这里部分代码省略.........
#line 1688 "VBNET.ATG"
pexpr = expr;
break;
}
case 81: case 93: case 204: {
#line 1690 "VBNET.ATG"
CastType castType = CastType.Cast;
if (la.kind == 93) {
lexer.NextToken();
} else if (la.kind == 81) {
lexer.NextToken();
#line 1692 "VBNET.ATG"
castType = CastType.Conversion;
} else if (la.kind == 204) {
lexer.NextToken();
#line 1693 "VBNET.ATG"
castType = CastType.TryCast;
} else SynErr(259);
Expect(25);
Expr(
#line 1695 "VBNET.ATG"
out expr);
Expect(12);
TypeName(
#line 1695 "VBNET.ATG"
out type);
Expect(26);
#line 1696 "VBNET.ATG"
pexpr = new CastExpression(type, expr, castType);
break;
}
case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: {
CastTarget(
#line 1697 "VBNET.ATG"
out type);
Expect(25);
Expr(
#line 1697 "VBNET.ATG"
out expr);
Expect(26);
#line 1697 "VBNET.ATG"
pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion);
break;
}
case 44: {
lexer.NextToken();
Expr(
#line 1698 "VBNET.ATG"
out expr);
#line 1698 "VBNET.ATG"
pexpr = new AddressOfExpression(expr);
break;
}
case 116: {
lexer.NextToken();
Expect(25);
GetTypeTypeName(
#line 1699 "VBNET.ATG"
out type);
示例14: VisitCastExpression
public override object VisitCastExpression (CastExpression expression, object data)
{
// Console.WriteLine ("CastExpression");
IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data;
if (IsExpressionToReplace (expression.Expression, (IntegrateTemporaryVariableVisitorOptions)data)) {
if (IsPrimary (options.Initializer))
options.Changes.Add (ReplaceExpression (expression.Expression, options.Initializer, options));
else
options.Changes.Add (ReplaceExpression (expression.Expression, new ParenthesizedExpression (options.Initializer), options));
return null;
} else {
return base.VisitCastExpression (expression, data);
}
}
示例15: RelationalExpr
void RelationalExpr(
#line 2251 "cs.ATG"
ref Expression outExpr) {
#line 2253 "cs.ATG"
TypeReference type;
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
Location startLocation = la.Location;
ShiftExpr(
#line 2259 "cs.ATG"
ref outExpr);
while (StartOf(37)) {
if (StartOf(38)) {
if (la.kind == 23) {
lexer.NextToken();
#line 2261 "cs.ATG"
op = BinaryOperatorType.LessThan;
} else if (la.kind == 22) {
lexer.NextToken();
#line 2262 "cs.ATG"
op = BinaryOperatorType.GreaterThan;
} else if (la.kind == 36) {
lexer.NextToken();
#line 2263 "cs.ATG"
op = BinaryOperatorType.LessThanOrEqual;
} else if (la.kind == 35) {
lexer.NextToken();
#line 2264 "cs.ATG"
op = BinaryOperatorType.GreaterThanOrEqual;
} else SynErr(215);
UnaryExpr(
#line 2266 "cs.ATG"
out expr);
ShiftExpr(
#line 2267 "cs.ATG"
ref expr);
#line 2268 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation };
} else {
if (la.kind == 85) {
lexer.NextToken();
TypeWithRestriction(
#line 2271 "cs.ATG"
out type, false, false);
if (
#line 2272 "cs.ATG"
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
NullableQuestionMark(
#line 2273 "cs.ATG"
ref type);
}
#line 2274 "cs.ATG"
outExpr = new TypeOfIsExpression(outExpr, type) { StartLocation = startLocation, EndLocation = t.EndLocation };
} else if (la.kind == 50) {
lexer.NextToken();
TypeWithRestriction(
#line 2276 "cs.ATG"
out type, false, false);
if (
#line 2277 "cs.ATG"
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
NullableQuestionMark(
#line 2278 "cs.ATG"
ref type);
}
#line 2279 "cs.ATG"
outExpr = new CastExpression(type, outExpr, CastType.TryCast) { StartLocation = startLocation, EndLocation = t.EndLocation };
} else SynErr(216);
}
}
}