From 1f1c61ec7c6d9ab4ccaaca26b231f759d056afbb Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Sat, 21 Dec 2013 23:52:41 +0100 Subject: [PATCH] Chapter 7 --- CSharpInDepth/Chapter7/Chapter7.sln | 20 ++++++ CSharpInDepth/Chapter7/Chapter7.userprefs | 14 ++++ CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs | 27 ++++++++ CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj | 43 ++++++++++++ CSharpInDepth/Chapter7/Chapter7/Example1.cs | 27 ++++++++ CSharpInDepth/Chapter7/Chapter7/Example2.cs | 22 ++++++ CSharpInDepth/Chapter7/Chapter7/Main.cs | 74 +++++++++++++++++++++ .../Chapter7/Chapter7/bin/Debug/Chapter7.exe | Bin 0 -> 5120 bytes .../Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb | Bin 0 -> 1173 bytes 9 files changed, 227 insertions(+) create mode 100644 CSharpInDepth/Chapter7/Chapter7.sln create mode 100644 CSharpInDepth/Chapter7/Chapter7.userprefs create mode 100644 CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs create mode 100644 CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj create mode 100644 CSharpInDepth/Chapter7/Chapter7/Example1.cs create mode 100644 CSharpInDepth/Chapter7/Chapter7/Example2.cs create mode 100644 CSharpInDepth/Chapter7/Chapter7/Main.cs create mode 100755 CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe create mode 100644 CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb diff --git a/CSharpInDepth/Chapter7/Chapter7.sln b/CSharpInDepth/Chapter7/Chapter7.sln new file mode 100644 index 0000000..2622864 --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter7", "Chapter7\Chapter7.csproj", "{F9C58D62-5522-4FCB-8F6A-69D808E88785}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Debug|x86.ActiveCfg = Debug|x86 + {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Debug|x86.Build.0 = Debug|x86 + {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Release|x86.ActiveCfg = Release|x86 + {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Chapter7\Chapter7.csproj + EndGlobalSection +EndGlobal diff --git a/CSharpInDepth/Chapter7/Chapter7.userprefs b/CSharpInDepth/Chapter7/Chapter7.userprefs new file mode 100644 index 0000000..e853d2e --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7.userprefs @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs b/CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs new file mode 100644 index 0000000..086ff91 --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Chapter7")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("gustavo")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj b/CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj new file mode 100644 index 0000000..168ff8d --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj @@ -0,0 +1,43 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {F9C58D62-5522-4FCB-8F6A-69D808E88785} + Exe + Chapter7 + Chapter7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + none + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharpInDepth/Chapter7/Chapter7/Example1.cs b/CSharpInDepth/Chapter7/Chapter7/Example1.cs new file mode 100644 index 0000000..401b9a8 --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7/Example1.cs @@ -0,0 +1,27 @@ +using System; + +namespace Chapter7 +{ + partial class Example : IEquatable where TFirst : class + { + public bool Equals(string other) + { + return false; + } + } + + + partial class PartialMethodDemo + { + public PartialMethodDemo () + { + OnConstructorStart(); + Console.WriteLine("Generated constructor"); + OnConstructorEnd(); + } + + partial void OnConstructorStart(); + partial void OnConstructorEnd(); + } +} + diff --git a/CSharpInDepth/Chapter7/Chapter7/Example2.cs b/CSharpInDepth/Chapter7/Chapter7/Example2.cs new file mode 100644 index 0000000..6edbe89 --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7/Example2.cs @@ -0,0 +1,22 @@ +using System; + +namespace Chapter7 +{ + partial class Example : EventArgs, IDisposable + { + public void Dispose() + { + Console.WriteLine("Running Dispose"); + } + } + + + partial class PartialMethodDemo + { + partial void OnConstructorEnd() + { + Console.WriteLine("Manual code"); + } + } +} + diff --git a/CSharpInDepth/Chapter7/Chapter7/Main.cs b/CSharpInDepth/Chapter7/Chapter7/Main.cs new file mode 100644 index 0000000..991fe84 --- /dev/null +++ b/CSharpInDepth/Chapter7/Chapter7/Main.cs @@ -0,0 +1,74 @@ +using System; + +namespace Chapter7 +{ + class Chapter7 + { + public static void Main (string[] args) + { + + /** + * + * Listing 7.1 Demonstration of mixing declarations of a partial type. + */ + Console.WriteLine("Listing 7.1: Demonstration of mixing declarations of a partial type."); + Example example = new Example(); + example.Dispose(); + + + /** + * + * Listing 7.2 A partial method called from a constructor. + */ + Console.WriteLine("Listing 7.2: A partial method called from a constructor."); +#pragma warning disable 0219 + PartialMethodDemo partialMethodDemo = new PartialMethodDemo(); +#pragma warning restore 0219 + + /** + * + * Listing 7.3 A typical C# 1 utility class. + */ + Console.WriteLine("Listing 7.3: A typical C# 1 utility class."); + string message = "noimahcrE nereB"; + string reverseMessage = NonStaticStringHelper.Reverse(message); + Console.WriteLine(reverseMessage); + + + /** + * + * Listing 7.4 The same utility class as in listing 7.3, but converted a C# 2 static class. + */ + Console.WriteLine("Listing 7.4: The same utility class as in listing 7.3, but converted a C# 2 static class.oimahcrE nereB"); + message = "leivúniT neihtúL"; + reverseMessage = NonStaticStringHelper.Reverse(message); + Console.WriteLine(reverseMessage); + + } + } + + public sealed class NonStaticStringHelper + { + private NonStaticStringHelper () + { + } + + public static string Reverse(string input) + { + char[] chars = input.ToCharArray(); + Array.Reverse(chars); + return new string(chars); + } + } + + + public static class StringHelper + { + public static string Reverse(string input) + { + char[] chars = input.ToCharArray(); + Array.Reverse(chars); + return new string(chars); + } + } +} diff --git a/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe b/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe new file mode 100755 index 0000000000000000000000000000000000000000..02d1e069661cb7f29acdd1d07d2f07f98c05ba76 GIT binary patch literal 5120 zcmeHLU2Ggz75-+u>)0E6@lVn?Rnv@>6dAW#*|8x7Rqgs`lbHA?^={IpAd=bLYkSD- z%;wIlu_1y4s-jAHfS0Oo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k$NW0W{-6qw6$MnmVZfFtR9M=B{}P2u|`{heACnx z@L6wEt!EI=g>+lJu7hVj9JsngM9QtQ?^~B*NhDGe{k(% z9kEJ$J}t{13^sd?H+`%1ruJtF{E%ds*DOBH(G+Gln#CD>0#BQ4gP-3)u3u}!D{o6; zY2p+v&ggzzS>o7Xm-dvw*Un+QJEUI9=Sky+K^x;W3qB~sZv5ASZ0rx)2QCBu0gr2J AQ~&?~ literal 0 HcmV?d00001 diff --git a/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb b/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb new file mode 100644 index 0000000000000000000000000000000000000000..7524d4eebe47e07ac4ac29e59ea0e88cdeca870f GIT binary patch literal 1173 zcmb_cTS!zv7@l*Rv${}zm!RL?3N9-+XiaZ)U##%$b=DH_k6) z=X`MHlSG+4mC>E4Z!T2QCiQy|?uj-tWA8q5AmUf*n(btbY5@z4~vbEzaq@IpSHnrL#s0=|PqUyR&1( zKW_yqN*eUK=FiR9z22(H2g>#@^VX)WzUy0DPyVA_KI}#dTH7lg?RK|~J-q1|X)zZ1 zN?y+DrvPSOV}zRQC2HdAw&@Q{#Z{a zIg&~QL0FK*MY$1zOjMRw2qL8Gnh~wkf*uwPM9Pa;C_+Rv#7tB3Ga{`sST!?D=1B&S zi7KRd?UE`|;Y_^t+8s-Ln7ec+;<)k(F3bF-edunD=b(s-N+X3x6d$&wiGI>S!RoL( zxO|0*J+ya)?D#7WQgMVng}iKTS&Dz1G)d*x^c~mmffCZRZo-VxES2Zz_heY+VK2gR zvr1dkR&~WpQX0?G>b3Kc-KyN9_VX^7P?pk?BcH4Eh58a?ia)O0U62f&ihV_+wMd}tN89Kckx9$W+9Fw-vZB>;z-J_Zi}xCH0~cocwd{L+9G dnF0_ZB?$66VF=9iJrKF>O5{V_V6OYXe*oTREQ