- Windows 11 SDK support.
- Adds Xcode 13.0 support.
- Add AMD64 math functions to ARM64X CRT.
- Updates to the ARM64 and ARM64EC interfaces between the binary and the POGO instrumentation runtime.
- Fixed several problems with IntelliSense responsiveness and correctness affecting C++20 concepts, ranges, and abbreviated function templates.
- Fixed a false positive in local lifetime checks.
- Corrected an issue where arrays allocated with a constant of size > 32bits could allocate less memory than requested.
- Ensures that ATL string initialization occurs during static variable initialization, in the default AppDomain.
- Fixed a bug in C++ Concurrency::parallel_for_each that was crashing the calling process due to integer overflow.
- Fixed a bug in the STL's iterator debugging machinery that could cause crashes in multithreaded programs using STL containers.
- We have fixed a fatal internal compiler error caused by unnamed structs whose fields are referenced from SAL annotations.
- Fixes a rare crash when analyzing templated code that uses __uuidof.
- Fixed an issue that caused C++ static analysis results to sometimes not display correctly in the FixIt action.
- Fixed opening .uitest extension files in Coded UI project
- Fire component change events for non-component objects also in WinForms .NET designer
- Fix for crash on deleting ContextMenuStrip control in Windows Forms .NET designer.
- Guard against crashes when the Windows Forms designer reloads when dragging.
- Fix for intermittent VS crash while interacting with WinForms .NET designer during solution or project rebuild.
- Fixed a bug causing .NET 5 projects to be reported as out of date when they should have been up to date, causing slower builds.
- Automatically disable asset-indexing for large scale Unity projects.
- This release fixes an issue with deploying certain Windows Application Packaging projects where deployment is unnecessarily copying unmodified files.
حجم تقریبی آپدیت از نسخه قبلی (16.11.3) حدود 1.11G میشه.
در ادامه مثال سوم قسمت قبل، در مورد حذف کدهای تکراری توسط Action و Func، در این قسمت به یک مثال نسبتا پرکاربرد دیگر آن جهت ساده سازی try/catch/finally اشاره خواهد شد.
احتمالا هزاران بار در کدهای خود چنین قطعه کدی را تکرار کردهاید:
این مورد را نیز میتوان توسط Actionها کپسوله کرد و پیاده سازی قسمت بدنه try آنرا به فراخوان واگذار نمود:
و برای نمونه جهت استفاده از آن خواهیم داشت:
یا اگر عمل انجام شده باید خروجی خاصی را بازگرداند (برخلاف یک Action که خروجی از آن انتظار نمیرود)، میتوان طراحی متد Execute را با Func انجام داد:
در این حالت فراخوانی متد Execute به نحو زیر خواهد بود:
و اگر در این بین استثنایی رخ دهد، علاوه بر ثبت جزئیات خطای رخ داده شده، نال را بازگشت خواهد داد.
از همین دست میتوان به کپسوله سازی منطق «سعی مجدد» در انجام کاری اشاره کرد:
برای مثال فرض کنید برنامه قرار است اطلاعاتی را از وب دریافت کند. ممکن است در سعی اول آن، خطای اتصال یا در دسترس نبودن لحظهای سایت رخ دهد. در اینجا نیاز خواهد بود تا این عملیات چندین بار تکرار شود؛ که نمونهای از آنرا در ذیل ملاحظه میکنید:
احتمالا هزاران بار در کدهای خود چنین قطعه کدی را تکرار کردهاید:
try { // code } catch(Exception ex) { // do something }
void Execute(Action action) { try { action(); } catch(Exception ex) { // log errors } }
Execute(() => {open a file});
یا اگر عمل انجام شده باید خروجی خاصی را بازگرداند (برخلاف یک Action که خروجی از آن انتظار نمیرود)، میتوان طراحی متد Execute را با Func انجام داد:
public static class SafeExecutor { public static T Execute<T>(Func<T> operation) { try { return operation(); } catch (Exception ex) { // Log Exception } return default(T); } }
var data = SafeExecutor.Execute<string>(() => { // do something return "result"; });
از همین دست میتوان به کپسوله سازی منطق «سعی مجدد» در انجام کاری اشاره کرد:
public static class RetryHelper { public static void RetryOperation(Action action, int numRetries, int retryTimeout) { if( action == null ) throw new ArgumentNullException("action"); do { try { action(); return; } catch { if( numRetries <= 0 ) throw; else Thread.Sleep( retryTimeout ); } } while( numRetries-- > 0 ); } }
RetryHelper.RetryOperation(() => SomeFunction(), 3, 1000);
یکی از متداولترین کارهایی که با اسناد میتوان انجام داد، تهیه خروجی pdf از word و پر کردن یک فایل word با مقادیر ورودی است که سعی داریم یک نمونه از آن را اینجا بررسی کنیم. کد عمومی برای جایگزین کردن:
برای تهیه pdf نیز میتوانید به کد زیر مراجعه کنید:
public void MsInteropReplace(Microsoft.Office.Interop.Word.Application doc, object findText, object replaceWithText) { object matchCase = false; object matchWholeWord = true; object matchWildCards = false; object matchSoundsLike = false; object matchAllWordForms = false; object forward = true; object format = false; object matchKashida = false; object matchDiacritics = false; object matchAlefHamza = false; object matchControl = false; object read_only = false; object visible = true; object replace = 2; object wrap = 1; //execute find and replace doc.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl); }
و یا این مورد:
که هر دو مورد را در stackoverflow میتوانید پیدا کنید. به شخصه از این مورد برای replace کردن مقادیر در یک فایل template.docx استفاده میکردم؛ ولی بعد از مدتی فهمیدم که Footerها و Header را نمیتواند پردازش کند. کد زیر در تمامی قسمتهایی که در یک فایل word میتوان متغیر تعریف کرد را گشته و عمل پر کردن مقادیر را بر روی فایل نمونه، انجام میدهد و شامل سه متد ذیل است:
private static void MsInteropReplace2() { var doc = new Microsoft.Office.Interop.Word.Application().Documents.Open(@"D:\temp\te1.docx"); doc.Content.Find.Execute("@levelOrder", false, true, false, false, false, true, 1, false, "12345", 2, false, false, false, false); object missing = System.Reflection.Missing.Value; doc.SaveAs(@"D:\temp\out.docx", ref missing, ref missing, ref missing, ref missing , ref missing, ref missing, ref missing, ref missing, ref missing, ref missing , ref missing, ref missing, ref missing, ref missing, ref missing); }
که هر دو مورد را در stackoverflow میتوانید پیدا کنید. به شخصه از این مورد برای replace کردن مقادیر در یک فایل template.docx استفاده میکردم؛ ولی بعد از مدتی فهمیدم که Footerها و Header را نمیتواند پردازش کند. کد زیر در تمامی قسمتهایی که در یک فایل word میتوان متغیر تعریف کرد را گشته و عمل پر کردن مقادیر را بر روی فایل نمونه، انجام میدهد و شامل سه متد ذیل است:
private static void repAll() { object Missing = System.Reflection.Missing.Value; Application app = null; Microsoft.Office.Interop.Word.Document doc = null; try { app = new Microsoft.Office.Interop.Word.Application(); doc = app.Documents.Open(@"D:\temp\te1.docx", Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); FindReplaceAnywhere(app, "@levelOrder", "محرمانه"); doc.SaveAs(@"D:\temp\out.docx", Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); } finally { try { if (doc != null) ((Microsoft.Office.Interop.Word._Document)doc).Close(true, Missing, Missing); } finally { } if (app != null) ((Microsoft.Office.Interop.Word._Application)app).Quit(true, Missing, Missing); } } private static void searchAndReplaceInStory(Microsoft.Office.Interop.Word.Range rngStory, string strSearch, string strReplace) { rngStory.Find.ClearFormatting(); rngStory.Find.Replacement.ClearFormatting(); rngStory.Find.Text = strSearch; rngStory.Find.Replacement.Text = strReplace; rngStory.Find.Wrap = WdFindWrap.wdFindContinue; object Missing = System.Reflection.Missing.Value; object arg1 = Missing; // Find Pattern object arg2 = Missing; //MatchCase object arg3 = Missing; //MatchWholeWord object arg4 = Missing; //MatchWildcards object arg5 = Missing; //MatchSoundsLike object arg6 = Missing; //MatchAllWordForms object arg7 = Missing; //Forward object arg8 = Missing; //Wrap object arg9 = Missing; //Format object arg10 = Missing; //ReplaceWith object arg11 = WdReplace.wdReplaceAll; //Replace object arg12 = Missing; //MatchKashida object arg13 = Missing; //MatchDiacritics object arg14 = Missing; //MatchAlefHamza object arg15 = Missing; //MatchControl rngStory.Find.Execute(ref arg1, ref arg2, ref arg3, ref arg4, ref arg5, ref arg6, ref arg7, ref arg8, ref arg9, ref arg10, ref arg11, ref arg12, ref arg13, ref arg14, ref arg15); } // Main routine to find text and replace it, // var app = new Microsoft.Office.Interop.Word.Application(); public static void FindReplaceAnywhere(Microsoft.Office.Interop.Word.Application app, string findText, string replaceText) { // http://forums.asp.net/p/1501791/3739871.aspx var doc = app.ActiveDocument; // Fix the skipped blank Header/Footer problem // http://msdn.microsoft.com/en-us/library/aa211923(office.11).aspx Microsoft.Office.Interop.Word.WdStoryType lngJunk = doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.StoryType; // Iterate through all story types in the current document foreach (Microsoft.Office.Interop.Word.Range rngStory in doc.StoryRanges) { // Iterate through all linked stories var internalRangeStory = rngStory; do { searchAndReplaceInStory(internalRangeStory, findText, replaceText); try { // 6 , 7 , 8 , 9 , 10 , 11 -- http://msdn.microsoft.com/en-us/library/aa211923(office.11).aspx switch (internalRangeStory.StoryType) { case Microsoft.Office.Interop.Word.WdStoryType.wdEvenPagesHeaderStory: // 6 case Microsoft.Office.Interop.Word.WdStoryType.wdPrimaryHeaderStory: // 7 case Microsoft.Office.Interop.Word.WdStoryType.wdEvenPagesFooterStory: // 8 case Microsoft.Office.Interop.Word.WdStoryType.wdPrimaryFooterStory: // 9 case Microsoft.Office.Interop.Word.WdStoryType.wdFirstPageHeaderStory: // 10 case Microsoft.Office.Interop.Word.WdStoryType.wdFirstPageFooterStory: // 11 if (internalRangeStory.ShapeRange.Count > 0) { foreach (Microsoft.Office.Interop.Word.Shape oShp in internalRangeStory.ShapeRange) { if (oShp.TextFrame.HasText != 0) { searchAndReplaceInStory(oShp.TextFrame.TextRange, findText, replaceText); } } } break; default: break; } } catch { // On Error Resume Next } // ON ERROR GOTO 0 -- http://www.harding.edu/fmccown/vbnet_csharp_comparison.html // Get next linked story (if any) internalRangeStory = internalRangeStory.NextStoryRange; } while (internalRangeStory != null); // http://www.harding.edu/fmccown/vbnet_csharp_comparison.html } }
برای تهیه pdf نیز میتوانید به کد زیر مراجعه کنید:
public static void getFileDocxInPdf() { // Create a new Microsoft Word application object Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); // C# doesn't have optional arguments so we'll need a dummy value object oMissing = System.Reflection.Missing.Value; // Get list of Word files in specified directory DirectoryInfo dirInfo = new DirectoryInfo(@"D:\temp"); FileInfo[] wordFiles = dirInfo.GetFiles("*.docx"); word.Visible = false; word.ScreenUpdating = false; foreach (FileInfo wordFile in wordFiles) { // Cast as Object for word Open method Object filename = (Object)wordFile.FullName; // Use the dummy value as a placeholder for optional arguments Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); doc.Activate(); object outputFileName = wordFile.FullName.Replace(".docx", ".pdf"); object fileFormat = WdSaveFormat.wdFormatPDF; // Save document into PDF Format doc.SaveAs(ref outputFileName, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); // Close the Word document, but leave the Word application open. // doc has to be cast to type _Document so that it will find the // correct Close method. object saveChanges = WdSaveOptions.wdDoNotSaveChanges; ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing); doc = null; } // word has to be cast to type _Application so that it will find // the correct Quit method. ((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing); word = null; }
اشتراکها
جلوگیری از حملات XSS در Net core.
اشتراکها
کتابخانه star-rating
Top Issues Fixed in Visual Studio 2019 version 16.6.0
- When New Git experience feature flag is enabled, a message will appear in Team Explorer guiding users to the new Git tool window.
- Fix for intermittent UI delay while closing VS when WinForms .NET Core designer is in open state.
- Fixed issues creating projects using type providers, throwing missing method exception at runtime.
- Fixed project creation for .NET framework projects.
- New find in files experience respects options in Tools-Options-Find and Replace pane.
- Fixed a bug where Git repository does not change when closing a Folder and opening a Solution.
- Fixed bug when building iOS app using full debug symbols.
- Added back browing of Mac Distribution provisioning profiles and certificates from Windows.
- Fixed a bug causing Visual Studio 2019 to stop responding when working with Xamarin projects on certain scenarios.
- Added keyboard shortcut for "Copy with Headers" option in SQL Script Results Grid
- SSDT users will now be able to set and view sensitivity properties for all version above SQL Server 2008
- Improve Connection Properties dialog for accessibility users.
- Fixed occasional crashes when using Tested By Code Lens indicator.
- Ensure auto population of text in Find in files is as per legacy behavior.
- Ensure left arrow key behavior in find in files is correct.
- An issue blocking C++ users of the C++20 Ranges library from using algorithms.
اشتراکها
آشنایی با volatile در سی شارپ
In this particular example (Windows 10 with SSD drive with BitLocker enabled) reading 1 MB file is now 2.5 times faster, while writing is 5.5 times faster.
The memory allocations dropped from 39 kilobytes to 192 bytes! This is a 99.5% improvement!
Method | Runtime | Mean | Ratio | Allocated |
---|---|---|---|---|
ReadAsync | .NET 5.0 | 3.419 ms | 1.00 | 39,504 B |
ReadAsync | .NET 6.0 | 1.445 ms | 0.42 | 192 B |
| | | | |
WriteAsync | .NET 5.0 | 12.181 ms | 1.00 | 39,192 B |
WriteAsync | .NET 6.0 | 2.193 ms | 0.18 | 192 B |
نظرات مطالب
سری فیبوناچی و دات نت 4 !
استاد نمی دونم چقدر این سوال به موضوع ربط داره،ولی در بعضی جاها نوشته شده که حلقه foreach سنگین تر از حلقه for هستش و حلقه for سریعتر اجرا میشه.
بعضی ها هم میگن که اینطور نیست.می خواستم بدونم نظر شما در این مورد چی هست.
بعضی ها هم میگن که اینطور نیست.می خواستم بدونم نظر شما در این مورد چی هست.
اشتراکها
مقایسه HTTP/2 PUSH و HTTP Preload
HTTP/2 PUSH is a feature that lets a server pre-emptively push resources to the client (without a corresponding request). HTTP Preload is a way to indicate to the browser resources it would require while loading the current page. In this post, we will discuss the key differences between PUSH and Preload, with a detailed explanation of which one to choose based on your use case.