Question

I use Visual Studio 2010, C#, .Net 4.0; Excel 2007 Add-In project.

Why I see 2 different declarations of the class ThisAddIn in the Add-In project?

a) the first one in the file ThisAddIn.cs

public partial class ThisAddIn

b) the second one in the file ThisAddIn.Designer.cs

public sealed partial class ThisAddIn : Microsoft.Office.Tools.AddInBase

How these two declarations are interrelated? Does it really specifies two separate classes or it essentially defines one class?

When I scroll down the file ThisAddIn.Designer.cs, I see the following lines:

internal sealed partial class Globals {


        private Globals() {
        }

        private static ThisAddIn _ThisAddIn;

        .....    
}

Which class (out of two mentioned above) is being used in the line private static ThisAddIn _ThisAddIn; ?

Thanks a lot for any help!

Was it helpful?

Solution

It's a partial class, which means that it will be defined in multiple source files. They are combined during compilation, and result in only one actual class.

This technique is commonly used to allow auto-generated code to be in one file (the .Designer.cs file), and your own code to be in the other file.

More at: http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.90).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top