Initial commit
[mono.git] / mcs / class / referencesource / System / compmod / system / componentmodel / LicenseException.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="LicenseException.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 namespace System.ComponentModel {
8     using Microsoft.Win32;
9     using System;
10     using System.Diagnostics;
11     using System.Runtime.Serialization;
12     using System.Security.Permissions;
13
14     /// <devdoc>
15     ///    <para>Represents the exception thrown when a component cannot be granted a license.</para>
16     /// </devdoc>
17     [HostProtection(SharedState = true)]
18     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")] // must not, a Type is required in all constructors.
19     [Serializable]
20     public class LicenseException : SystemException {
21         private Type type;
22         private object instance;
23
24         /// <devdoc>
25         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
26         ///    specified type.</para>
27         /// </devdoc>
28         public LicenseException(Type type) : this(type, null, SR.GetString(SR.LicExceptionTypeOnly, type.FullName)) {
29         }
30         /// <devdoc>
31         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
32         ///    specified type and instance.</para>
33         /// </devdoc>
34         public LicenseException(Type type, object instance) : this(type, null, SR.GetString(SR.LicExceptionTypeAndInstance, type.FullName, instance.GetType().FullName))  {
35         }
36         /// <devdoc>
37         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
38         ///    specified type and instance with the specified message.</para>
39         /// </devdoc>
40         public LicenseException(Type type, object instance, string message) : base(message) {
41             this.type = type;
42             this.instance = instance;
43             HResult = HResults.License;
44         }
45         /// <devdoc>
46         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
47         ///    specified innerException, type and instance with the specified message.</para>
48         /// </devdoc>
49         public LicenseException(Type type, object instance, string message, Exception innerException) : base(message, innerException) {
50             this.type = type;
51             this.instance = instance;
52             HResult = HResults.License;
53         }
54    
55         /// <devdoc>
56         ///     Need this constructor since Exception implements ISerializable. 
57         /// </devdoc>
58         protected LicenseException(SerializationInfo info, StreamingContext context) : base (info, context) {
59             type = (Type) info.GetValue("type", typeof(Type));
60             instance = info.GetValue("instance", typeof(object));
61         }
62
63         /// <devdoc>
64         ///    <para>Gets the type of the component that was not granted a license.</para>
65         /// </devdoc>
66         public Type LicensedType {
67             get {
68                 return type;
69             }
70         }
71
72         /// <devdoc>
73         ///     Need this since Exception implements ISerializable and we have fields to save out.
74         /// </devdoc>
75         [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
76         public override void GetObjectData(SerializationInfo info, StreamingContext context) {
77             if (info == null) {
78                 throw new ArgumentNullException("info");
79             }
80
81             info.AddValue("type", type);
82             info.AddValue("instance", instance);
83
84             base.GetObjectData(info, context);
85         }
86     }
87 }