Best Of
Re: CreateXhtmlWriter with LINQPadChart - wrong output
Change htmlOut.Write(chart)
to htmlOut.Write (chart.ToBitmap())
. (You can also specify a width and height when calling ToBitmap.)
Re: Dumping the Util ProgressBar and the visible property
I apologize for this taking so long. Just letting Joe know that I got the latest version and was able to accomplish what I intended with the progress bar in the scenario I discussed.
Thanks so much for the quick enhancement!
Re: Warning: LINQPad has identified vulnerabilities in NuGet package Azure.Identity. Click for details.
Thanks - this should now be fixed in 8.3.6.
Re: Any way to suppress vulnerability warnings?
If you expand the warning it tells you how to suppress the warning.
Re: LinqPad8 is showing me a cached Entity ?
I'm guessing this is Linq2Sql caching the entity.
There are a number of ways to resolve this.
If you are not going to be calling SubmitChanges() then you can disable the tracker and caching at the start of your query.
this.ObjectTrackingEnabled = false;
Alternatively keep a reference to the customer that will be changed outside LinqPad, and then refresh that record after calling your webservice - e.g.
var customer = Customers.Single(s => s.CustomerIdInDataHost == _oldCustomerID).Dump(); // ASMX webservice that simply replace the customer id for the Entity (same database as used in my Query) _dataHostService.ReplaceCustomerIdInDataHost(_datahostapikey, _owner, _newID, _oldCustomerID); // Refresh the customer record this.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, customer ); // Show the updated Customer with the new ID Customers.Single(s => s.CustomerIdInDataHost == _newID).Dump();
Alternatively you can create a new DataContext. Unfortunately you can do re-assign the new context to this
, but you can something like
var dc = new TypedDataContext(this.Connection.ConnectionString); dc.Customers.Single(s => s.CustomerIdInDataHost == _newID).Dump();
That is kinda dangerous as it is very easy to forget to prefix your query with dc.
Finally, Linq has a method to clear the cache but unfortunately it is marked as private, but you can if you use Uncapsulate, e.g.
var customer = Customers.Single(s => s.CustomerIdInDataHost == _oldCustomerID).Dump(); // ASMX webservice that simply replace the customer id for the Entity (same database as used in my Query) _dataHostService.ReplaceCustomerIdInDataHost(_datahostapikey, _owner, _newID, _oldCustomerID); this.Uncapsulate().ClearCache(); // Show the updated Customer with the new ID Customers.Single(s => s.CustomerIdInDataHost == _newID).Dump();
Re: Dumping of "new" property
Good call - the member on the derived type should take precedence. This should now be fixed in the 8.3.5 beta:
https://www.linqpad.net/linqpad8.aspx#beta
Re: Util.Dif with the Uncapsulate() conflict
You need to use
LINQPad.Extensions.Dump(Util.Dif(model .Uncapsulate().Dump(), model2.Uncapsulate()), "DIF");
The intellisense as you type .Dump as you have done is confusing as it implies that Dump will work, but if you try assigning your result to a variable and dumping that variable the intellisense tells it won't and what you need to do,
Re: Show dif names when diffing lists
If the purpose is just to remind yourself which list is which, then I'd just use
Util.Dif(firstList, secondList).DumpTell();
or you can set Enable automatic Dump-headings by default for new queries and just dump as per normal.
Re: Show dif names when diffing lists
So my current workaround is this:
void Main() { var a = new House(1, 3); var b = new House(2, 3); Util.Dif(a, b).Dump("Dump objects"); var firstList = new List<House>() { new House(1, 3), new House(2, 3) }; var secondList = new List<House>() { new House(3, 3), new House(4, 3) }; Util.Dif(firstList, secondList).Dump("Dump lists"); UtilEx.DifDump(firstList, secondList); } public class House(int number, int roomCount) { public int Number => number; public int RoomCount => roomCount; public override string ToString() { return $"House {Number}"; } } public static class UtilEx { public static bool DifDump(object object1, object object2, int? depth = null, bool hideMatchingMembers = false, [CallerArgumentExpression(nameof(object1))] string leftLabel = "", [CallerArgumentExpression(nameof(object2))] string rightLabel = "") { var difResult = Util.Dif(object1, object2, depth, hideMatchingMembers); if (!difResult.IsSame) { var difLabels = new Div(); difLabels.HtmlElement.InnerHtml = $"<td class='n'><span class='difremove'>{leftLabel}</span> <span class='difadd'>{rightLabel}</span></td>"; difLabels.Dump(); } difResult.Dump(); return difResult.IsSame; } }
... which results in this output:
I don't love the mixing of the Diffing and Dump, but it's nice and compact at least:)
Re: How to indent a Dump() result?
Would something like this work?
void Main() { var f = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat; f.FirstDayOfWeek.Dump(""); f.NativeCalendarName.DumpIndented(1); f.FullDateTimePattern.DumpTellIndented(1); f.LongDatePattern.DumpTellIndented(2); f.Calendar.DumpIndented(3, "Calendar", collapseTo:1); f.AbbreviatedDayNames.DumpTellIndented(2,collapseTo: 0); } public static class Indent { public static int SizeOfIndent = 10; public static T DumpIndented<T>(this T obj, int indentLevel = 0, string? description = null, int? collapseTo = null) { string indent = " ".PadLeft(indentLevel * SizeOfIndent); if (description != null) Util.HorizontalRun(true, indent, Util.WithHeading(obj, description)).Dump(collapseTo: collapseTo); else Util.HorizontalRun(true, indent, obj).Dump(collapseTo: collapseTo ); return obj; } public static T DumpTellIndented<T>(this T obj, int indentLevel = 0, [System.Runtime.CompilerServices.CallerArgumentExpression("obj")] string? autoGeneratedDescription = null, int? collapseTo = null) { string indent = " ".PadLeft(indentLevel * SizeOfIndent); Util.HorizontalRun(true, indent, Util.WithHeading(obj, autoGeneratedDescription)).Dump(collapseTo: collapseTo); return obj; } }
Results look like
Of course there are a whole load of more optional parameters available with dump and I have just using two, but it is probably easy to add most of the rest of them.