background preloader


Facebook Twitter

C# covariant return types utilizing generics. Write Mobile Agents In .NET To Roam And Interact On Your Network. Wandering Code Write Mobile Agents In .NET To Roam And Interact On Your Network Matt Neely Code download available at:MobileAgents.exe(145 KB) Recently I had the opportunity to return to school to complete a graduate degree.

Write Mobile Agents In .NET To Roam And Interact On Your Network

This experience made me realize two important things: there are some cool ideas in academia that seem to never find the light of day in the professional setting, and the academic world at large is not yet very familiar with the Microsoft® .NET Framework. The term agent originates in artificial intelligence and describes a logical entity that has some level of autonomy within its environment or host. In this introduction to mobile agents, I'll create an example mobile agent system and develop several mobile agent applications, highlighting some of the problems that I encountered along the way as well as several ideas for overcoming them.

Introduction to Mobile Agents Figure 1 Traveling Agent Hops Between Machines Figure 2 Task Agent Allocates Tasks Assembly Resolution. Output an Assembly Version/Fully Qualified Name from the CommandLine. Sample of non-CAS custom permission with declarative form supported. - Eugene Bobukh's WebLog. Why?

Sample of non-CAS custom permission with declarative form supported. - Eugene Bobukh's WebLog

Recently, I started seeing numerous requests regarding creation of custom permissions that do not inherit from CodeAccessPermission and thus do not perform stackwalk. There is nothing special about implementing such classes. In fact, it is easier then with CodeAccessPermission as a base. However, having a sample handy, I just decided to share it here along with my comments. So welcome WorkingTimePermission Trying to be at least somewhat close to real life, I implemented the permission object with the following Demand semantics: Demystifying C# 3.0 - Part 7: Expression Trees. In this series of Demystifying C# 3.0 we have already covered - a) Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"b) Demystifying C# 3.0 - Part 2: Anonymous Typesc) Demystifying C# 3.0 - Part 3: Extension Methodsd) Demystifying C# 3.0 - Part 4: Lambda Expressionse) Demystifying C# 3.0 - Part 5: Object and Collection Initializersf) Demystifying C# 3.0 - Part 6: (LINQ) Query Expression Translation (to C# 3.0) Thank you to both Eric Wise, and C.

Demystifying C# 3.0 - Part 7: Expression Trees

Steen for linking. The more people we have look at these posts, the better the overall discussion quality will be. Okay, so next we will be talking about "Expression Trees". So in short, Expression trees permit lambda expressions to be represented as data structures, instead of executable code. X => x + 1, is executable code. which could also be written as, Func<int,int> f = x => x + 1 But, Demystifying C# 3.0 - Part 6: (LINQ) Query Expression Translation (to C# 3.0) In this series of Demystifying C# 3.0 we have already covered - a) Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"b) Demystifying C# 3.0 - Part 2: Anonymous Typesc) Demystifying C# 3.0 - Part 3: Extension Methodsd) Demystifying C# 3.0 - Part 4: Lambda Expressionse) Demystifying C# 3.0 - Part 5: Object and Collection Initializers I *strongly* recommend reading up the above in sequence before reading this post.

Demystifying C# 3.0 - Part 6: (LINQ) Query Expression Translation (to C# 3.0)

This is, (I feel) a rather good post, that will set LINQ in your mind clearly. If you rush through this post, you will waste this opportunity. If you are crystal clear about the above 5 posts and the concepts behind them, .. read on .. Okay good, so in this post, we are going to talk about "Queries" or "LINQ" for the very first time in this Demystifying C# series. Demystifying C# 3.0 - Part 4: Lambda Expressions. In the Demystifying C# 3.0, I've already talked about - a) Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"b) Demystifying C# 3.0 - Part 2: Anonymous Typesc) Demystifying C# 3.0 - Part 3: Extension Methods Lets next talk about Lambda Expressions.

Demystifying C# 3.0 - Part 4: Lambda Expressions

The best way I can describe Lambda Expressions are - C# Anonymous Methods, only a lot cooler. So what is an anonymous method in C# 2.0? Well y'know you can write code like below in C# 1.x/2.x - class SomeClass{ delegate void SomeDelegate(); public void InvokeMethod() { SomeDelegate del = new SomeDelegate(SomeMethod); del(); } void SomeMethod() { Console.WriteLine("Hello"); }} Demystifying C# 3.0 - Part 3: Extension Methods. If you've been following my blog, you would have noticed that I've been trying to talk about new C# 3.0 features one by one.

Demystifying C# 3.0 - Part 3: Extension Methods

I am trying to take the technical jargon out, and bring these features down to an understandable level. You may want to read the two features I have already talked about below - Demystifying C# 3.0 - Part 2: Anonymous Types. In my last blog entry, I had talked about Implicitly typed local variables and the "var" keyword.

Demystifying C# 3.0 - Part 2: Anonymous Types

If you have stumbled across this post through a search engine, or otherwise, I would recommend reading that first. Assuming that you understand "var" - lets dive into part 2 of Demystifying C#3.0 ~ Anonymous Types. In C# 2.0, lets say you wanted to represent a person, you would typically have to write a class as follows - public class Person{ string hairColor ; string skinColor ; int teethCount ;} // I'm obviously taking the shortcut by not creating properties .. anyway, that's besides the point. Well, in LINQ, I could be querying arbitrary groups of my data. Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"

I am going to publish a series of blogposts that intend to bring C# 3.0 down to earth.

Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"

C# 3.0, along with LINQ, and all the heavy duty talk that surrounds it has sort of made it difficult to understand IMO. Well - if not difficult to understand, it sure is tough to gauge - "Where to begin". So with 5 minutes a day, a short post a day will dice and slice a single feature, and we will logically move to a fuller picture of C# 3.0, followed by LINQ, and DLINQ (if I still have steam left). So here we go, with the first in that series, the "var" keyword. Cutting Edge: Customize Your Open File Dialog. Cutting Edge Customize Your Open File Dialog Dino Esposito Code download available at:CuttingEdge0303.exe(96 KB) Displaying an Open File dialog is certainly easy in the Microsoft® .NET Framework with Windows® Forms, but the resulting window is not as customizable as when you create it through the Win32® API.

Cutting Edge: Customize Your Open File Dialog

With Windows 2000, Microsoft added a nice feature—the places bar, which is the vertical toolbar that appears on the left side of the window to let you select a frequently visited folder. Figure 1 Selecting a Folder in the Places Bar When coding against the Open File common dialog in the Win32 API, you can set a style to hide the places bar. In this column, I'll focus on the places bar of the Open File common dialog. Creating Your Own Code Access Permissions. There are other situations in which a custom permission might be appropriate.

Creating Your Own Code Access Permissions

When a built-in code access permission class protects a resource but does not sufficiently control access to that resource, you might need a custom code access permission. For example, an application might use personnel records for which each employee record is stored in a separate file; in such a case, read and write access could be controlled independently for different types of employee data. An internal management tool could be authorized to read certain sections of an employee's personnel file but not to modify those sections. In fact, it might not even be allowed to read some sections. Wherever possible, permissions should not overlap. Implementing a custom code access permission involves the following steps, some of which are optional.

Class Data Binding using Custom Attributes. Download source files - 1.73 KB Introduction At the end of this article, you should be comfortable using Custom Attributes. This article focuses on using them in order to create a quick, flexible data binding mechanism. Prerequisite Experience/Knowledge At least a beginner's understanding of ADO.NET and Reflection is required to follow this article. Understanding Attributes Attributes are used to add additional metadata to any element within a class (including the class itself).

Why are NameValueCollection lookups slower than Hashtable? [Kim Hamilton] - BCL Team Blog. An internal discussion came up recently on the performance difference of lookups in Hashtable versus NameValueCollection. Benchmarks revealed that NVC lookups were ~2-8 times slower than Hashtable. For example, when doing 40,000 lookups on a collection size of 100,000, NameValueCollection is about 2.6x worse: This leads to the question of whether NameValueCollection and Hashtable have different asymptotic behavior or if it simply has additional overhead. By repeating the benchmark over increasing collection sizes, it’s clear that the asymptotic behavior is the same for lookups. .NET Matters: ICustomTypeDescriptor, Part 1.

.NET Matters ICustomTypeDescriptor, Part 1 Stephen Toub Code download available at:NETMatters0504.exe(163 KB) Q I write a lot of one-off utilities for personal use, and since they don't require any sophisticated user interfaces, I often use a System.Windows.Forms.PropertyGrid bound to a settings class in order to allow the user to configure a tool's operations. Unfortunately, sometimes I don't write these settings classes, and often they've been constructed in a way that's incompatible with the PropertyGrid. A It sounds like you're using the Microsoft® .NET Framework 1.x, given your description of wsdl.exe and the proxy classes it generates. If the PropertyGrid bound to your types used only reflection to examine a type's metadata, you'd be out of luck, and there'd be no way to accomplish what you're trying to do (short of some hackish and non-user-friendly workarounds, one of which might be dynamic code generation).

The rest of the class is fairly self-explanatory. An MSN Messenger Log Listener. Download demo project and source - 296 Kb The code download has been updated for the final release of the Enterprise Library, including design support for the EntLibConfig application. Introduction A group of programmers, far smarter than I, have been laboring from some time to create a library of utilities to help developers like myself to create better applications. The fruits of that labor is the Enterprise Library from the Patterns & Practices group at Microsoft. The Enterprise Library encompasses Exception Handling, Logging, Caching, Security, Cryptography, and Database Access. The focus of this article is the Logging bits from the Enterprise Library. The good stuff I used the FormattedDatabaseTraceListener as a reference for creating my listener.

Avoiding configuration pitfalls with incompatible copies of Enterprise Library - Tom Hollander's blog. When you install Enterprise Library 3.0, you actually get two distinct copies of the library. One copy is in the form of pre-compiled binaries - by default these get installed to "C:\Program Files\Microsoft Enteprise Library 3.0 - April 2007\bin". The other copy is in the form of source code, which by default will be compiled and the assemblies coped to "C:\EntLib3Src\App Blocks\bin".

While both copies of Enterprise Library contain identical code, there is one critical difference: the pre-compiled binaries are strong-named (with a Microsoft key that we do not ship), and the assemblies compiled from the source code are not initially strong-named. So as far as .NET is concerned, these two sets of assemblies are completely different and completely incompatible with one another. The good news is that all of these problems can be avoided easily enough if you keep a few things in mind. Parallel Performance: Optimize Managed Code For Multi-Core Machines. Parallel Performance Optimize Managed Code For Multi-Core Machines Daan Leijen and Judd Hall Multi-processor machines are now becoming standard while the speed increases of single processors have slowed down.

The key to performance improvements is therefore to run a program on multiple processors in parallel. Design: Task Parallel Library explored - MSDN Utopia. As some of you may know, the threadpool code of the .NET is helping many developers to use multiple threads on their applications, increasing “sometimes” the responsiveness and delegating all the switching responsibility. But, for those less fuzzy that like to know how it really works you usually find that the code is not the best threadpool library. Enable/Disable Network Connection - David Aiken. Large Data and Streaming. When you have a large amount of data to transfer, the streaming transfer mode in WCF is a feasible alternative to the default behavior of buffering and processing messages in memory in their entirety.

As mentioned earlier, enable streaming only for large messages (with text or binary content) if the data cannot be segmented, if the message must be delivered in a timely fashion, or if the data is not yet fully available when the transfer is initiated. Restrictions You cannot use a significant number of WCF features when streaming is enabled: Digital signatures for the message body cannot be performed because they require computing a hash over the entire message contents. With streaming, the content is not fully available when the message headers are constructed and sent and, therefore, a digital signature cannot be computed.

Because of these functional constraints, you can use only transport-level security options for streaming and you cannot turn on reliable sessions. Using Custom Filters in the Enterprise Library Logging Block. One of the things you can configure in the Enterprise Library logging block is a custom filter. Script# Gemrcsharpcs.pdf (application/pdf Object) The most complete C# Webbrowser wrapper control. Download control, demo source and binaries - 1,110.8 Kb Introduction. C# - How can I get a value of a property from an anonymous type. Flag enum confusion C# Menus, part III : animated multi-level drop-down menu. An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Continuation-Passing Style Simplifies Your C# Exception Handling Code « Paint.NET Blog.

Many lines of code in C# and other imperative languages are seemingly wasted by dealing with overhead such as exception handling and the like. How many times have you written the following type of code? String[] fileNames;try { fileNames = Directory.GetFiles(…); } catch (Exception) { // There was an error, like the directory isn’t there. // This isn’t an error for us, so just use a 0-length array // to simplify our later code fileNames = new string[0]; } foreach (string fileName in fileNames) { … do some processing on this file … } The basic pattern is, "try to obtain a value by calling this function, but if there’s an error then use a default value. " It’s a lot of code, and it gets tiring and unreadable or unmanageable after awhile. This pattern, which is called the hole in the middle pattern, crops up all the time in imperative programming.

Exploring Lambda Expression in C# Introduction. HTTP Communication and Security with Silverlight. By default, Silverlight supports calls to Web services on the same domain or site of origin. Same domain means that calls must use the same sub domain, protocol, and port. .NET Matters: Abortable Thread Pool. Coding Best Practices Using DateTime in the .NET Framework. Popup Window Finder and Mouse Tracker in C# Low-Level Mouse Hook in C# - Stephen Toub. Blog Archive » DynamicObject in C# 4.0. Pattern Matching in C# - Part 1.