HashHelper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Shared / MS / Internal / HashHelper.cs / 1 / HashHelper.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) 2003 by Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: Static class to help work around hashing-related bugs. 
//
//--------------------------------------------------------------------------- 

using System;
using MS.Internal;                  // BaseHashHelper
 
#if WINDOWS_BASE
namespace MS.Internal.Hashing.WindowsBase 
#elif PRESENTATION_CORE 
namespace MS.Internal.Hashing.PresentationCore
#elif PRESENTATIONFRAMEWORK 
using System.ComponentModel;        // ICustomTypeDescriptor
namespace MS.Internal.Hashing.PresentationFramework
#else
#error Attempt to define HashHelper in an unknown assembly. 
namespace MS.Internal.YourAssemblyName
#endif 
{ 
    internal static class HashHelper
    { 
        // The class cctor registers this assembly's exceptional types with
        // the base helper.
        static HashHelper()
        { 
            Initialize();       // this makes FxCop happy - otherwise Initialize is "unused code"
 
            Type[] types = new Type[] { 
#if WINDOWS_BASE
#elif PRESENTATION_CORE 
                typeof(System.Windows.Media.CharacterMetrics),      // bug 1612093
                typeof(System.Windows.Ink.ExtendedProperty),        // bug 1612101
                typeof(System.Windows.Media.FamilyTypeface),        // bug 1612103
                typeof(System.Windows.Media.NumberSubstitution),    // bug 1612105 
#elif PRESENTATIONFRAMEWORK
                typeof(System.Windows.Markup.Localizer.BamlLocalizableResource),    // bug 1612118 
                typeof(System.Windows.ComponentResourceKey),        // bug 1612119 
#endif
            }; 

            BaseHashHelper.RegisterTypes(typeof(HashHelper).Assembly, types);

            // initialize lower-level assemblies 
#if PRESENTATIONFRAMEWORK
            MS.Internal.Hashing.PresentationCore.HashHelper.Initialize(); 
#endif 
        }
 

        // certain objects don't have reliable hashcodes, and cannot be used
        // within a Hashtable, Dictionary, etc.
        internal static bool HasReliableHashCode(object item) 
        {
            return BaseHashHelper.HasReliableHashCode(item); 
        } 

        // this method doesn't do anything, but calling it makes sure the static 
        // cctor gets called
        internal static void Initialize()
        {
        } 

 
#if PRESENTATIONFRAMEWORK 
        // Helper to identify DataRowView
        internal static bool IsDataRowView(object item, Type type) 
        {
            // the earlier tests filter out most false results before doing
            // the final test.  If we did the final test first, it would load
            // System.Data unnecessarily. 
            return (item is ICustomTypeDescriptor &&
                    item is IDataErrorInfo && 
                    type.Namespace == "System.Data" && 
                    IsDataRowViewType(type));
        } 

        // separate method to avoid loading System.Data until needed
        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
        private static bool IsDataRowViewType(Type type) 
        {
            return (type == typeof(System.Data.DataRowView)); 
        } 
#endif
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) 2003 by Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: Static class to help work around hashing-related bugs. 
//
//--------------------------------------------------------------------------- 

using System;
using MS.Internal;                  // BaseHashHelper
 
#if WINDOWS_BASE
namespace MS.Internal.Hashing.WindowsBase 
#elif PRESENTATION_CORE 
namespace MS.Internal.Hashing.PresentationCore
#elif PRESENTATIONFRAMEWORK 
using System.ComponentModel;        // ICustomTypeDescriptor
namespace MS.Internal.Hashing.PresentationFramework
#else
#error Attempt to define HashHelper in an unknown assembly. 
namespace MS.Internal.YourAssemblyName
#endif 
{ 
    internal static class HashHelper
    { 
        // The class cctor registers this assembly's exceptional types with
        // the base helper.
        static HashHelper()
        { 
            Initialize();       // this makes FxCop happy - otherwise Initialize is "unused code"
 
            Type[] types = new Type[] { 
#if WINDOWS_BASE
#elif PRESENTATION_CORE 
                typeof(System.Windows.Media.CharacterMetrics),      // bug 1612093
                typeof(System.Windows.Ink.ExtendedProperty),        // bug 1612101
                typeof(System.Windows.Media.FamilyTypeface),        // bug 1612103
                typeof(System.Windows.Media.NumberSubstitution),    // bug 1612105 
#elif PRESENTATIONFRAMEWORK
                typeof(System.Windows.Markup.Localizer.BamlLocalizableResource),    // bug 1612118 
                typeof(System.Windows.ComponentResourceKey),        // bug 1612119 
#endif
            }; 

            BaseHashHelper.RegisterTypes(typeof(HashHelper).Assembly, types);

            // initialize lower-level assemblies 
#if PRESENTATIONFRAMEWORK
            MS.Internal.Hashing.PresentationCore.HashHelper.Initialize(); 
#endif 
        }
 

        // certain objects don't have reliable hashcodes, and cannot be used
        // within a Hashtable, Dictionary, etc.
        internal static bool HasReliableHashCode(object item) 
        {
            return BaseHashHelper.HasReliableHashCode(item); 
        } 

        // this method doesn't do anything, but calling it makes sure the static 
        // cctor gets called
        internal static void Initialize()
        {
        } 

 
#if PRESENTATIONFRAMEWORK 
        // Helper to identify DataRowView
        internal static bool IsDataRowView(object item, Type type) 
        {
            // the earlier tests filter out most false results before doing
            // the final test.  If we did the final test first, it would load
            // System.Data unnecessarily. 
            return (item is ICustomTypeDescriptor &&
                    item is IDataErrorInfo && 
                    type.Namespace == "System.Data" && 
                    IsDataRowViewType(type));
        } 

        // separate method to avoid loading System.Data until needed
        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
        private static bool IsDataRowViewType(Type type) 
        {
            return (type == typeof(System.Data.DataRowView)); 
        } 
#endif
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK