Browse by Tags
All Tags »
Useful .Net classes (RSS)
I had previously tried using the WebBrowser class to retrieve a web page for analysis (using the DocumentText property). The problem was determining the state of the page load (since a page requires several hits before completion on average). Turns out I need to check on track backs to my post, as Anthony Stevens (you should read his " about " page) found a solution to my problem: Once the page load is complete WebBrowser.ReadyState property will be set to Complete , and then you can take...
(שאלה מהפורום בתפוז) מדובר במקרה נפוץ, ודי קל לבדוק - רק לבדוק האם קיים מפתח מתאים ברג'יסטרי (רק שצריך לכתוב קוד לא מנוהל לשם כך): For the .NET Framework 1.0: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.0 For the .NET Framework 1.1: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.1 For the .NET Framework 2.0: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v2.0
This is something I wrote a while ago to allow easy way to serialize/deserialize various objects to and from XML by creating an adapter around the XmlSerializer class. Since I don't know how this XML is going to be used this class stores it inside a string. Serialize usage: string s = SimpleSerializer.Instance.ToString(myObject); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(s); Deserialize: MyClass obj = SimpleSerializer.Instance.FromString(xDoc.OuterXML); /// <summary> /// Objects...
Krzysztof Cwalina wrote a post detailing how have your class support the "foreach" loop without implementing the IEnumerable interface: Public GetEnumerator() method that returns a type with 2 members: The type will have a bool MoveMext() method. The type will have an Current property of type object . Example: class Foo { public Bar GetEnumerator() { return new Bar(); } public struct Bar { public bool MoveNext() { return false ; } public object Current { get { return null ; } } } }
Some times you need to measure the value of something while running the application. Using a logger is not comfortable, since you don't want to monitor gazillion rows of values. The solution: create a performance counter and use Perfmon.exe to view it while the application is running. Here is a code for creating a counter: private PerformanceCounter CreatePerformanceCounter() { string categoryName = "My Category" ; if ( !PerformanceCounterCategory.Exists(categoryName) ) { CounterCreationDataCollection...
Catch every exception in your application. If you must, show the user some kind of an error dialog, but don't force him/her to watch the awful .Net exception dialog. I have seen to many application with various try...catch blocks, but with nothing done...
Inbar Gazit published a post on "Converting the Non-Generic Collections" in the BCL Team blog. He had this handy little table: Non-genericGeneric replacementArrayListList Read More...
Phil Haack wrote a post on .Net services people frequently tend to forget about the re-invent, so I made a list of his pointers as well as some of the comments: System.IO.Path.Combine(folder, filename)string.IsNullOrEmpty(string)Path.DirectorySeparatorCharPath...