home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_customreader_cpp________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2002-04-08  |  2.2 KB  |  78 lines

  1. //-----------------------------------------------------------------------
  2. //  This file is part of the Microsoft .NET SDK Code Samples.
  3. // 
  4. //  Copyright (C) Microsoft Corporation.  All rights reserved.
  5. // 
  6. //This source code is intended only as a supplement to Microsoft
  7. //Development Tools and/or on-line documentation.  See these other
  8. //materials for detailed information regarding Microsoft code samples.
  9. // 
  10. //THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
  11. //KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. //IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  13. //PARTICULAR PURPOSE.
  14. //-----------------------------------------------------------------------
  15.  
  16. // CustomReader: Implement the interface IResourceReader.
  17. // CustomManager: Sub-class ResourceManager and create
  18. // ResourceSets using the CustomReader class.
  19. //
  20.  
  21. #using <mscorlib.dll>
  22.  
  23. using namespace System;
  24. using namespace System::Collections;
  25. using namespace System::Globalization;
  26. using namespace System::Resources;
  27.  
  28.  
  29. public __gc class CustomReader : public IResourceReader
  30. {
  31. public:
  32.  
  33.     void IResourceReader::Close()
  34.     {
  35.     // Close any open files, DB connections, etc here.
  36.     }
  37.  
  38.     IEnumerator* IEnumerable::GetEnumerator() {
  39.         return __try_cast<IEnumerator*>( __try_cast<IResourceReader*>( this )->GetEnumerator() );
  40.     }
  41.  
  42.     IDictionaryEnumerator* IResourceReader::GetEnumerator()
  43.     {
  44.         Hashtable* dict = new Hashtable;
  45.  
  46.         dict->Add( S"key1", S"value 1" );
  47.         dict->Add( S"key2", S"value 2" );
  48.         dict->Add( S"key3", S"value 3" );
  49.  
  50.         return dict->GetEnumerator();
  51.     }
  52.  
  53.     void IDisposable::Dispose()
  54.     {
  55.     }
  56.  
  57. };
  58.  
  59. public __gc class CustomManager : public ResourceManager
  60. {
  61. protected:
  62.  
  63.     ResourceSet* InternalGetResourceSet( CultureInfo* culture,
  64.                                         __value bool createIfNotExists,
  65.                                         __value bool tryParents )
  66.     {
  67.         return new ResourceSet( new CustomReader );
  68.     }
  69. };
  70.  
  71. void main( void )
  72. {
  73.     ResourceManager* resourceManager = new CustomManager;
  74.     Console::WriteLine( String::Concat( S"Lookup for key1 yields: ", resourceManager->GetString( S"key1" ) ) );
  75.     Console::WriteLine( S"\r\nPress Return to exit." );
  76.     Console::Read();
  77. }
  78.