The Labs \ Source Viewer \ SSCLI \ System.Configuration \ PropertySourceInfo

  1. //------------------------------------------------------------------------------
  2. // <copyright file="PropertySourceInfo.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Configuration.Internal;
  17. using System.Collections;
  18. using System.Collections.Specialized;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using System.Reflection;
  22. using System.Security.Permissions;
  23. using System.Xml;
  24. using System.Globalization;
  25. using System.ComponentModel;
  26. using System.Security;
  27. using System.Text;
  28. namespace System.Configuration
  29. {
  30.    
  31.     internal class PropertySourceInfo
  32.     {
  33.         private string _fileName;
  34.         private int _lineNumber;
  35.        
  36.         internal PropertySourceInfo(XmlReader reader)
  37.         {
  38.             _fileName = GetFilename(reader);
  39.             _lineNumber = GetLineNumber(reader);
  40.         }
  41.        
  42.         internal string FileName {
  43.             get {
  44.                 //
  45.                 // Ensure we return the same string to the caller as the one on which we issued the demand.
  46.                 //
  47.                 string filename = _fileName;
  48.                 try {
  49.                     new FileIOPermission(FileIOPermissionAccess.PathDiscovery, filename).Demand();
  50.                 }
  51.                 catch (SecurityException) {
  52.                     // don't expose the path to this user but show the filename
  53.                     filename = Path.GetFileName(_fileName);
  54.                     if (filename == null) {
  55.                         filename = String.Empty;
  56.                     }
  57.                 }
  58.                
  59.                 return filename;
  60.             }
  61.         }
  62.        
  63.         internal int LineNumber {
  64.             get { return _lineNumber; }
  65.         }
  66.        
  67.         private string GetFilename(XmlReader reader)
  68.         {
  69.             IConfigErrorInfo err = reader as IConfigErrorInfo;
  70.            
  71.             if (err != null) {
  72.                 return (string)err.Filename;
  73.             }
  74.            
  75.             return "";
  76.         }
  77.        
  78.         private int GetLineNumber(XmlReader reader)
  79.         {
  80.             IConfigErrorInfo err = reader as IConfigErrorInfo;
  81.            
  82.             if (err != null) {
  83.                 return (int)err.LineNumber;
  84.             }
  85.             return 0;
  86.         }
  87.     }
  88. }

Developer Fusion