forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScopeStorageComparer.cs
More file actions
63 lines (54 loc) · 2.1 KB
/
Copy pathScopeStorageComparer.cs
File metadata and controls
63 lines (54 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace System.Web.WebPages.Scope
{
/// <summary>
/// Custom comparer for the context dictionaries
/// The comparer treats strings as a special case, performing case insesitive comparison.
/// This guaratees that we remain consistent throughout the chain of contexts since PageData dictionary
/// behaves in this manner.
/// </summary>
internal class ScopeStorageComparer : IEqualityComparer<object>
{
private static IEqualityComparer<object> _instance;
private readonly IEqualityComparer<object> _defaultComparer = EqualityComparer<object>.Default;
private readonly IEqualityComparer<string> _stringComparer = StringComparer.OrdinalIgnoreCase;
private ScopeStorageComparer()
{
}
public static IEqualityComparer<object> Instance
{
get
{
if (_instance == null)
{
_instance = new ScopeStorageComparer();
}
return _instance;
}
}
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Target = "xString, yString",
Justification = "These names make most sense.")]
public new bool Equals(object x, object y)
{
string xString = x as string;
string yString = y as string;
if ((xString != null) && (yString != null))
{
return _stringComparer.Equals(xString, yString);
}
return _defaultComparer.Equals(x, y);
}
public int GetHashCode(object obj)
{
string objString = obj as string;
if (objString != null)
{
return _stringComparer.GetHashCode(objString);
}
return _defaultComparer.GetHashCode(obj);
}
}
}