1 //------------------------------------------------------------------------------
2 // <copyright file="UrlPropertyAttribute.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.UI {
8     using System;
9     using System.ComponentModel;
10     using System.Web.Util;
11 
12     // An UrlPropertyAttribute metadata attribute can be applied to string
13     // properties that contain URL values.
14     // This can be used to identify URLs which allows design-time functionality and runtime
15     // functionality to do interesting things with the property values.
16     [AttributeUsage(AttributeTargets.Property)]
17     public sealed class UrlPropertyAttribute : Attribute {
18 
19         private string _filter;
20         // Used to mark a property as an URL.
UrlPropertyAttribute()21         public UrlPropertyAttribute() : this("*.*") {
22         }
23 
24         // Used to mark a property as an URL. In addition, the type of files allowed
25         // can be specified. This can be used at design-time to customize the URL picker.
UrlPropertyAttribute(string filter)26         public UrlPropertyAttribute(string filter) {
27             if(filter == null) {
28                 _filter = "*.*";
29             }
30             else {
31                 _filter = filter;
32             }
33         }
34 
35         // The file filter associated with the URL property. This takes
36         // the form of a file filter string typically used with Open File
37         // dialogs. The default is *.*, so all file types can be chosen.
38         public string Filter {
39             get {
40                 return _filter;
41             }
42         }
43 
GetHashCode()44         public override int GetHashCode() {
45             return Filter.GetHashCode();
46         }
47 
Equals(object obj)48         public override bool Equals(object obj) {
49             if (obj == this) {
50                 return true;
51             }
52 
53             UrlPropertyAttribute other = obj as UrlPropertyAttribute;
54             if (other != null) {
55                 return Filter.Equals(other.Filter);
56             }
57 
58             return false;
59         }
60     }
61 }
62