From: gu.martinm@gmail.com Date: Sat, 21 Dec 2013 22:52:41 +0000 (+0100) Subject: Chapter 7 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=1f1c61ec7c6d9ab4ccaaca26b231f759d056afbb;p=CSharpForFun%2F.git Chapter 7 --- 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 0000000..02d1e06 Binary files /dev/null and b/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe differ 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 0000000..7524d4e Binary files /dev/null and b/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb differ