15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Partial Classes ❘ 83<br />

{<br />

public void MethodTwo()<br />

{<br />

}<br />

}<br />

When the project that these two source files are part of is compiled, a single type called TheBigClass will<br />

be created with two methods, MethodOne() <strong>and</strong> MethodTwo().<br />

If any of the following keywords are used in describing the class, the same must apply to all partials of the<br />

same type:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

public<br />

private<br />

protected<br />

internal<br />

abstract<br />

sealed<br />

new<br />

generic constraints<br />

Nested partials are allowed as long as the partial keyword precedes the class keyword in the nested type.<br />

Attributes, XML comments, interfaces, generic-type parameter attributes, <strong>and</strong> members will be combined<br />

when the partial types are compiled into the type. Given these two source files:<br />

//BigClassPart1.cs<br />

[CustomAttribute]<br />

partial class TheBigClass: TheBigBaseClass, IBigClass<br />

{<br />

public void MethodOne()<br />

{<br />

}<br />

}<br />

//BigClassPart2.cs<br />

[AnotherAttribute]<br />

partial class TheBigClass: IOtherBigClass<br />

{<br />

public void MethodTwo()<br />

{<br />

}<br />

}<br />

after the compile, the equivalent source file would be:<br />

[CustomAttribute]<br />

[AnotherAttribute]<br />

partial class TheBigClass: TheBigBaseClass, IBigClass, IOtherBigClass<br />

{<br />

public void MethodOne()<br />

{<br />

}<br />

public void MethodTwo()<br />

{<br />

}<br />

}<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!