790cf997728a9b66d23aeed52c8515ad2a56493a
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / Runtime / EarlyBoundInfo.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="EarlyBoundInfo.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 using System.Diagnostics;
10 using System.Reflection;
11
12 namespace System.Xml.Xsl.Runtime {
13
14     /// <summary>
15     /// This class contains information about early bound function objects.
16     /// </summary>
17     internal sealed class EarlyBoundInfo {
18         private string namespaceUri;            // Namespace Uri mapped to these early bound functions
19         private ConstructorInfo constrInfo;     // Constructor for the early bound function object
20
21         public EarlyBoundInfo(string namespaceUri, Type ebType) {
22             Debug.Assert(namespaceUri != null && ebType != null);
23
24             // Get the default constructor
25             this.namespaceUri = namespaceUri;
26             this.constrInfo = ebType.GetConstructor(Type.EmptyTypes);
27             Debug.Assert(this.constrInfo != null, "The early bound object type " + ebType.FullName + " must have a public default constructor");
28         }
29
30         /// <summary>
31         /// Get the Namespace Uri mapped to these early bound functions.
32         /// </summary>
33         public string NamespaceUri { get { return this.namespaceUri; } }
34
35         /// <summary>
36         /// Return the Clr Type of the early bound object.
37         /// </summary>
38         public Type EarlyBoundType { get { return this.constrInfo.DeclaringType; } }
39
40         /// <summary>
41         /// Create an instance of the early bound object.
42         /// </summary>
43         public object CreateObject() { return this.constrInfo.Invoke(new object[] {}); }
44
45         /// <summary>
46         /// Override Equals method so that EarlyBoundInfo to implement value comparison.
47         /// </summary>
48         public override bool Equals(object obj) {
49             EarlyBoundInfo info = obj as EarlyBoundInfo;
50             if (info == null)
51                 return false;
52
53             return this.namespaceUri == info.namespaceUri && this.constrInfo == info.constrInfo;
54         }
55
56         /// <summary>
57         /// Override GetHashCode since Equals is overriden.
58         /// </summary>
59         public override int GetHashCode() {
60             return this.namespaceUri.GetHashCode();
61         }
62     }
63 }
64