/// <summary> /// Rewrites Is expression. /// </summary> /// <param name="asExpression">Expression to rewrite.</param> /// <returns>Expression rewritten as code snippet.</returns> private CodeSnippetExpression RewriteIsExpression(CodeIsExpression asExpression) { using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture)) { sw.Write("("); this.generator.GenerateCodeFromExpression(asExpression.Source, sw, null); sw.Write(" is "); this.generator.GenerateCodeFromExpression(asExpression.TargetType, sw, null); sw.Write(")"); return new CodeSnippetExpression(sw.ToString()); } }
/// <summary> /// Rewrites Is expression. /// </summary> /// <param name="asExpression">Expression to rewrite.</param> /// <returns>Expression rewritten as code snippet.</returns> private CodeSnippetExpression RewriteIsExpression(CodeIsExpression asExpression) { using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture)) { sw.Write("("); // VB.net doesn't allow direct comparision of types such as // c.Id Is Integer // this needs to be rewritten to : // Typeof DirectCast(c.Id,Object) Is Integer // the type comparision operator can only be used on reference types, // hence the cast to Object before the TypeOf operator is invoked. sw.Write("TypeOf DirectCast("); this.generator.GenerateCodeFromExpression(asExpression.Source, sw, null); sw.Write(" , Object )"); sw.Write(" Is "); // Handle the CodeTypeReference issue with Byte[] if (asExpression.TargetType.Type.BaseType == "System.Byte") { sw.Write("Byte()"); } else { this.generator.GenerateCodeFromExpression(asExpression.TargetType, sw, null); } sw.Write(")"); return new CodeSnippetExpression(sw.ToString()); } }