Chapter 7
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sat, 21 Dec 2013 22:52:41 +0000 (23:52 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sat, 21 Dec 2013 22:52:41 +0000 (23:52 +0100)
CSharpInDepth/Chapter7/Chapter7.sln [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7.userprefs [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/Chapter7.csproj [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/Example1.cs [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/Example2.cs [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/Main.cs [new file with mode: 0644]
CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe [new file with mode: 0755]
CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb [new file with mode: 0644]

diff --git a/CSharpInDepth/Chapter7/Chapter7.sln b/CSharpInDepth/Chapter7/Chapter7.sln
new file mode 100644 (file)
index 0000000..2622864
--- /dev/null
@@ -0,0 +1,20 @@
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Visual Studio 2010\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter7", "Chapter7\Chapter7.csproj", "{F9C58D62-5522-4FCB-8F6A-69D808E88785}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|x86 = Debug|x86\r
+               Release|x86 = Release|x86\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Debug|x86.ActiveCfg = Debug|x86\r
+               {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Debug|x86.Build.0 = Debug|x86\r
+               {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Release|x86.ActiveCfg = Release|x86\r
+               {F9C58D62-5522-4FCB-8F6A-69D808E88785}.Release|x86.Build.0 = Release|x86\r
+       EndGlobalSection\r
+       GlobalSection(MonoDevelopProperties) = preSolution\r
+               StartupItem = Chapter7\Chapter7.csproj\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/CSharpInDepth/Chapter7/Chapter7.userprefs b/CSharpInDepth/Chapter7/Chapter7.userprefs
new file mode 100644 (file)
index 0000000..e853d2e
--- /dev/null
@@ -0,0 +1,14 @@
+<Properties>
+  <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
+  <MonoDevelop.Ide.Workbench ActiveDocument="Chapter7/Main.cs">
+    <Files>
+      <File FileName="Chapter7/Main.cs" Line="35" Column="38" />
+      <File FileName="Chapter7/Example1.cs" Line="19" Column="4" />
+      <File FileName="Chapter7/Example2.cs" Line="18" Column="34" />
+    </Files>
+  </MonoDevelop.Ide.Workbench>
+  <MonoDevelop.Ide.DebuggingService.Breakpoints>
+    <BreakpointStore />
+  </MonoDevelop.Ide.DebuggingService.Breakpoints>
+  <MonoDevelop.Ide.DebuggingService.PinnedWatches />
+</Properties>
\ No newline at end of file
diff --git a/CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs b/CSharpInDepth/Chapter7/Chapter7/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..086ff91
--- /dev/null
@@ -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 (file)
index 0000000..168ff8d
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{F9C58D62-5522-4FCB-8F6A-69D808E88785}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Chapter7</RootNamespace>
+    <AssemblyName>Chapter7</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>true</Externalconsole>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>true</Externalconsole>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Main.cs" />
+    <Compile Include="AssemblyInfo.cs" />
+    <Compile Include="Example1.cs" />
+    <Compile Include="Example2.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
diff --git a/CSharpInDepth/Chapter7/Chapter7/Example1.cs b/CSharpInDepth/Chapter7/Chapter7/Example1.cs
new file mode 100644 (file)
index 0000000..401b9a8
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+
+namespace Chapter7
+{
+       partial class Example<TFirst, TSecond> : IEquatable<string> 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 (file)
index 0000000..6edbe89
--- /dev/null
@@ -0,0 +1,22 @@
+using System;
+
+namespace Chapter7
+{
+       partial class Example<TFirst, TSecond> : 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 (file)
index 0000000..991fe84
--- /dev/null
@@ -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<string, int> example = new Example<string, int>();
+                       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 (executable)
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 (file)
index 0000000..7524d4e
Binary files /dev/null and b/CSharpInDepth/Chapter7/Chapter7/bin/Debug/Chapter7.exe.mdb differ