Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
845c105
commit 52dc908
Showing
433 changed files
with
31,083 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,8 @@ bin | |
obj | ||
|
||
# mstest test results | ||
TestResults | ||
TestResults | ||
/src/_ReSharper.geschikt | ||
|
||
*.user | ||
*.suo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
GNU LESSER GENERAL PUBLIC LICENSE | ||
Version 3, 29 June 2007 | ||
|
||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
Everyone is permitted to copy and distribute verbatim copies | ||
of this license document, but changing it is not allowed. | ||
|
||
|
||
This version of the GNU Lesser General Public License incorporates | ||
the terms and conditions of version 3 of the GNU General Public | ||
License, supplemented by the additional permissions listed below. | ||
|
||
0. Additional Definitions. | ||
|
||
As used herein, "this License" refers to version 3 of the GNU Lesser | ||
General Public License, and the "GNU GPL" refers to version 3 of the GNU | ||
General Public License. | ||
|
||
"The Library" refers to a covered work governed by this License, | ||
other than an Application or a Combined Work as defined below. | ||
|
||
An "Application" is any work that makes use of an interface provided | ||
by the Library, but which is not otherwise based on the Library. | ||
Defining a subclass of a class defined by the Library is deemed a mode | ||
of using an interface provided by the Library. | ||
|
||
A "Combined Work" is a work produced by combining or linking an | ||
Application with the Library. The particular version of the Library | ||
with which the Combined Work was made is also called the "Linked | ||
Version". | ||
|
||
The "Minimal Corresponding Source" for a Combined Work means the | ||
Corresponding Source for the Combined Work, excluding any source code | ||
for portions of the Combined Work that, considered in isolation, are | ||
based on the Application, and not on the Linked Version. | ||
|
||
The "Corresponding Application Code" for a Combined Work means the | ||
object code and/or source code for the Application, including any data | ||
and utility programs needed for reproducing the Combined Work from the | ||
Application, but excluding the System Libraries of the Combined Work. | ||
|
||
1. Exception to Section 3 of the GNU GPL. | ||
|
||
You may convey a covered work under sections 3 and 4 of this License | ||
without being bound by section 3 of the GNU GPL. | ||
|
||
2. Conveying Modified Versions. | ||
|
||
If you modify a copy of the Library, and, in your modifications, a | ||
facility refers to a function or data to be supplied by an Application | ||
that uses the facility (other than as an argument passed when the | ||
facility is invoked), then you may convey a copy of the modified | ||
version: | ||
|
||
a) under this License, provided that you make a good faith effort to | ||
ensure that, in the event an Application does not supply the | ||
function or data, the facility still operates, and performs | ||
whatever part of its purpose remains meaningful, or | ||
|
||
b) under the GNU GPL, with none of the additional permissions of | ||
this License applicable to that copy. | ||
|
||
3. Object Code Incorporating Material from Library Header Files. | ||
|
||
The object code form of an Application may incorporate material from | ||
a header file that is part of the Library. You may convey such object | ||
code under terms of your choice, provided that, if the incorporated | ||
material is not limited to numerical parameters, data structure | ||
layouts and accessors, or small macros, inline functions and templates | ||
(ten or fewer lines in length), you do both of the following: | ||
|
||
a) Give prominent notice with each copy of the object code that the | ||
Library is used in it and that the Library and its use are | ||
covered by this License. | ||
|
||
b) Accompany the object code with a copy of the GNU GPL and this license | ||
document. | ||
|
||
4. Combined Works. | ||
|
||
You may convey a Combined Work under terms of your choice that, | ||
taken together, effectively do not restrict modification of the | ||
portions of the Library contained in the Combined Work and reverse | ||
engineering for debugging such modifications, if you also do each of | ||
the following: | ||
|
||
a) Give prominent notice with each copy of the Combined Work that | ||
the Library is used in it and that the Library and its use are | ||
covered by this License. | ||
|
||
b) Accompany the Combined Work with a copy of the GNU GPL and this license | ||
document. | ||
|
||
c) For a Combined Work that displays copyright notices during | ||
execution, include the copyright notice for the Library among | ||
these notices, as well as a reference directing the user to the | ||
copies of the GNU GPL and this license document. | ||
|
||
d) Do one of the following: | ||
|
||
0) Convey the Minimal Corresponding Source under the terms of this | ||
License, and the Corresponding Application Code in a form | ||
suitable for, and under terms that permit, the user to | ||
recombine or relink the Application with a modified version of | ||
the Linked Version to produce a modified Combined Work, in the | ||
manner specified by section 6 of the GNU GPL for conveying | ||
Corresponding Source. | ||
|
||
1) Use a suitable shared library mechanism for linking with the | ||
Library. A suitable mechanism is one that (a) uses at run time | ||
a copy of the Library already present on the user's computer | ||
system, and (b) will operate properly with a modified version | ||
of the Library that is interface-compatible with the Linked | ||
Version. | ||
|
||
e) Provide Installation Information, but only if you would otherwise | ||
be required to provide such information under section 6 of the | ||
GNU GPL, and only to the extent that such information is | ||
necessary to install and execute a modified version of the | ||
Combined Work produced by recombining or relinking the | ||
Application with a modified version of the Linked Version. (If | ||
you use option 4d0, the Installation Information must accompany | ||
the Minimal Corresponding Source and Corresponding Application | ||
Code. If you use option 4d1, you must provide the Installation | ||
Information in the manner specified by section 6 of the GNU GPL | ||
for conveying Corresponding Source.) | ||
|
||
5. Combined Libraries. | ||
|
||
You may place library facilities that are a work based on the | ||
Library side by side in a single library together with other library | ||
facilities that are not Applications and are not covered by this | ||
License, and convey such a combined library under terms of your | ||
choice, if you do both of the following: | ||
|
||
a) Accompany the combined library with a copy of the same work based | ||
on the Library, uncombined with any other library facilities, | ||
conveyed under the terms of this License. | ||
|
||
b) Give prominent notice with the combined library that part of it | ||
is a work based on the Library, and explaining where to find the | ||
accompanying uncombined form of the same work. | ||
|
||
6. Revised Versions of the GNU Lesser General Public License. | ||
|
||
The Free Software Foundation may publish revised and/or new versions | ||
of the GNU Lesser General Public License from time to time. Such new | ||
versions will be similar in spirit to the present version, but may | ||
differ in detail to address new problems or concerns. | ||
|
||
Each version is given a distinguishing version number. If the | ||
Library as you received it specifies that a certain numbered version | ||
of the GNU Lesser General Public License "or any later version" | ||
applies to it, you have the option of following the terms and | ||
conditions either of that published version or of any later version | ||
published by the Free Software Foundation. If the Library as you | ||
received it does not specify a version number of the GNU Lesser | ||
General Public License, you may choose any version of the GNU Lesser | ||
General Public License ever published by the Free Software Foundation. | ||
|
||
If the Library as you received it specifies that a proxy can decide | ||
whether future versions of the GNU Lesser General Public License shall | ||
apply, that proxy's public statement of acceptance of any version is | ||
permanent authorization for you to choose that version for the | ||
Library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,85 @@ | ||
ProductivityExtensions | ||
====================== | ||
|
||
Coming soon | ||
Coming Soon... | ||
|
||
Productivity Extensions is a series of extension methods for .NET 4.0 or newer (Visual Studio 2010 or newer). | ||
|
||
Currently, there over 650 methods extending over 400 classes in the .NET Framework. | ||
|
||
The .NET Framework has been around since 2002. There are many common classes and methods that have been around a long time. The Framework and the languages used to develop on it have evolved quite a bit since many of these classes and their method came into existence. Existing classes and methods in the base class library (BCL) could be kept up to date with these technologies, but it's time consuming and potentially destabilizing to add or change methods after a library has been released and Microsoft generally avoids this unless there's a *really good* reason. | ||
|
||
Generics, for example, came along in the .Net 2.0 timeframe; so, many existing Framework subsystems never had the benefit of generics to make certain methods more strongly-typed. Many methods in the Framework take a `Type` parameter and return an `Object` of that `Type` but must be first cast in order for the object to be used as its requested type. `Attribute.GetCustomAttribute(Assembly, Type)` gets an `Attribute`-based class that has been added at the assembly level. For example, to get the copyright information of an assembly, you might do something like: | ||
|
||
```C# | ||
var aca = (AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), | ||
typeof (AssemblyCopyrightAttribute)); | ||
Trace.WriteLine(aca.Copyright); | ||
``` | ||
|
||
Involving, an `Assembly` instance, the `Attribute` class, the `typeof` operator, and a cast. The Productivity Extensions contains a generic extension method to `Assembly` to get this information without the `Attribute` class, the `typeof` operator or the cast. For example: | ||
|
||
```C# | ||
var aca = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>(); | ||
Trace.WriteLine(aca.Copyright); | ||
``` | ||
|
||
Other Framework methods came into existence before anonymous methods so their use could not have used anonymous method and captured variables and tended to require passing along state information. Asynchronous patterns like the Asynchronous Programming Model (APM) introduced methods starting with `Begin` that asynchronously performed a task and invoked a callback when done that would execute a matching `End` method. The callback delegate passed to these methods, prior to anonymous methods, had to be instance or class methods and thus had to store the state required to perform the callback explicitly. This could be done with instance or class members but often this required passing an opaque state object instance into the `Begin` method that was passed along to the callback via the `IAsyncResult.AsyncState` property. The callback would cast the object to whatever type it passed in and thus have its state. For example: | ||
|
||
```C# | ||
//... | ||
byte[] buffer = new byte[1024]; | ||
fileStream.BeginRead(buffer, 0, buffer.Length, ReadCompleted, fileStream); | ||
//... | ||
private static void ReadCompleted(IAsyncResult ar) | ||
{ | ||
FileStream fileStream = (FileStream) ar.AsyncState; | ||
fileStream.EndRead(ar); | ||
//... | ||
} | ||
``` | ||
|
||
With anonymous methods passing this state in often became unnecessary as the compiler would generate a state machine to manage any variables used within the anonymous method that were declared outside of the anonymous method. For example: | ||
|
||
```C# | ||
fileStream.BeginRead(buffer, 0, buffer.Length, | ||
delegate(IAsyncResult ar) { fileStream.EndRead(ar); }, | ||
null); | ||
``` | ||
Or, if you prefer the more recent lambda syntax: | ||
```C# | ||
fileStream.BeginRead(buffer, 0, buffer.Length, | ||
ar => fileStream.EndRead(ar), | ||
null); | ||
``` | ||
|
||
The state passed in in these situations would be `null`. Using `null` in many of these places can be a bit tedious. So, Productivity Extensions includes many extension methods that extend APM `Begin` methods to avoid passing this value in (and just send null). For example: | ||
|
||
```C# | ||
fileStream.BeginRead(buffer, 0, buffer.Length, | ||
ar => fileStream.EndRead(ar)); | ||
``` | ||
|
||
`FileStream` points out another area of potential productivity increase, the needless passing of `0, buffer.Length`. If I always want to just fill a buffer with data, why is there no method that simply does the `0, buffer.Length` for me? Well, now there is--in Productivity Extensions. You can no write: | ||
|
||
```C# | ||
fileStream.BeginRead(buffer, ar => fileStream.EndRead(ar)); | ||
``` | ||
|
||
Must less typing. | ||
|
||
Other themes in the extension library include interface fluidity. For example, the `Int32.Seconds()` extension method allows you to create a `TimeSpan` object that represents a span of time of second granularity: | ||
|
||
```C# | ||
waitHandle.WaitOne(5.Seconds()); | ||
``` | ||
|
||
###Structure### | ||
The nature of extensions methods is such that they can only be scoped by namespace. Two extension methods in the same namespace extending the same type, with the same signature will cause an error. | ||
|
||
All the extension methods in Productivity Extensions are contained in namespaces unique to the type they extend. These namespaces are simply called `<ClassName>Extensions`. If you want to use an extension method, you'll have to add a reference to that namespace within the source code file you want to use it. Each class being in their own namespace adds a granularity that avoids conflicts with extension methods in other libraries. If all the extension methods in Productivity Extensions were on one namespace (remember, there's over 650 extension methods that could conflict with other extension methods in different libraries) you would not be able to pick and choose which classes you want to extend in case of a conflict. For example, if you had a conflict with a method that extends `Stream` with the signature `BeginRead(this Stream stream, Byte[] buffer, AsyncCallback callback, Object state)` but wanted to use the extension method `FontConverter.ConvertTo<T>(Object value)` you'd have to use neither if they were bot in the same namespace. | ||
|
||
Each extension class is simply named `<ClassName>able`. This was arbitrary and basically mirrors `System.Enumerable`. The name of the class is never used and this provides a way to avoid a conflict with the namespace while providing a cogent namespace. | ||
|
||
Some methods may have originate from http://dotnetext.codeplex.com/license |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NUnit.Framework; | ||
using PRI.ProductivityExtensions.ReflectionExtensions; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class CustomAttributeProviderExtensionsTests | ||
{ | ||
[Test] | ||
public void ContainsAttributeReturnsTrueForMethodThatHasAttributeApplied() | ||
{ | ||
var mi = typeof (string).GetMethod("Equals", new [] {typeof(object)}); | ||
Assert.IsTrue(mi.ContainsAttribute("ReliabilityContractAttribute")); | ||
} | ||
[Test] | ||
public void ContainsAttributeReturnsTrueForMethodThatDoesNotHaveAttributeApplied() | ||
{ | ||
var mi = typeof(string).GetMethod("Equals", new[] { typeof(object) }); | ||
Assert.IsFalse(mi.ContainsAttribute("ObsoleteAttribute")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Data; | ||
using NUnit.Framework; | ||
using PRI.ProductivityExtensions.DataColumnExcentions; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class DataColumnableTests | ||
{ | ||
[Test] | ||
public void AddCorrectlyAddsNewColumn() | ||
{ | ||
var sut = new DataTable(); | ||
const string expectedValue = "My Column"; | ||
sut.Columns.Add<string>(expectedValue); | ||
Assert.AreEqual(1, sut.Columns.Count); | ||
Assert.AreEqual(expectedValue, sut.Columns[0].ColumnName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Tests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("Tests")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("4c81177b-da0c-41d5-8d12-5714503de935")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.