public override string GetNewObjectExpression(DmdConstructorInfo ctor, string argumentExpression, DmdType expectedType) { argumentExpression = LanguageValueNodeFactory.RemoveFormatSpecifiers(argumentExpression); var sb = ObjectCache.AllocStringBuilder(); var output = new StringBuilderTextColorOutput(sb); output.Write(BoxedTextColor.Keyword, "New"); output.Write(BoxedTextColor.Text, " "); FormatTypeName(output, ctor.DeclaringType); output.Write(BoxedTextColor.Punctuation, "("); var castType = ctor.GetMethodSignature().GetParameterTypes()[0]; bool needCast = !expectedType.CanCastTo(castType); if (needCast) { output.Write(BoxedTextColor.Keyword, "CType"); output.Write(BoxedTextColor.Punctuation, "("); } output.Write(BoxedTextColor.Text, argumentExpression); if (needCast) { output.Write(BoxedTextColor.Punctuation, ","); output.WriteSpace(); new Formatters.VisualBasic.VisualBasicTypeFormatter(new StringBuilderTextColorOutput(sb), VisualBasicValueNodeFactory.TypeFormatterOptions, null).Format(castType, null); output.Write(BoxedTextColor.Punctuation, ")"); } output.Write(BoxedTextColor.Punctuation, ")"); return(ObjectCache.FreeAndToString(ref sb)); }
public override string GetNewObjectExpression(DmdConstructorInfo ctor, string argumentExpression, DmdType expectedType) { argumentExpression = LanguageValueNodeFactory.RemoveFormatSpecifiers(argumentExpression); var sb = ObjectCache.AllocStringBuilder(); var output = new DbgStringBuilderTextWriter(sb); output.Write(DbgTextColor.Keyword, "new"); output.Write(DbgTextColor.Text, " "); FormatTypeName(output, ctor.DeclaringType); output.Write(DbgTextColor.Punctuation, "("); var castType = ctor.GetMethodSignature().GetParameterTypes()[0]; if (!expectedType.CanCastTo(castType)) { output.Write(DbgTextColor.Punctuation, "("); new Formatters.CSharp.CSharpTypeFormatter(new DbgStringBuilderTextWriter(sb), CSharpValueNodeFactory.TypeFormatterOptions, null).Format(castType, null); output.Write(DbgTextColor.Punctuation, ")"); } output.Write(DbgTextColor.Text, argumentExpression); output.Write(DbgTextColor.Punctuation, ")"); return(ObjectCache.FreeAndToString(ref sb)); }
public override string GetDereferenceExpression(string instanceExpression) { instanceExpression = LanguageValueNodeFactory.RemoveFormatSpecifiers(instanceExpression); return("*" + instanceExpression); }
public override string GetCallExpression(DmdMethodBase method, string instanceExpression) { instanceExpression = LanguageValueNodeFactory.RemoveFormatSpecifiers(instanceExpression); return(instanceExpression + "." + method.Name + "()"); }