assemblycache.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //------------------------------------------------------------------------------
  2. // <copyright file="assemblycache.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. //------------------------------------------------------------------------------
  9. //ThisAssembly class keeps a map of the following:
  10. //AssemblyName to AssemblyID
  11. //TypeName to TypeID
  12. //AssemblyID to AssemblyRef and State
  13. //TypeID to TypeRef and AssemblyId
  14. //
  15. //Adding an assembly to this class will NOT enable users to create types from that assembly. Users should explicitely add type details and link types to assemblies.
  16. // This class also registers for assembly resolve events so that dependent assemblies can be resolved if they are registered.
  17. //This class does NOT know anything about assembly dependencies. It simply loads assemblies as handed over to it.
  18. //Users can take advantage of connection pooling by tying this instance to a pooling-aware component.
  19. //------------------------------------------------------------------------------
  20. using System;
  21. using System.Collections;
  22. using System.Runtime.InteropServices;
  23. using System.Reflection;
  24. using System.Globalization;
  25. using System.Diagnostics;
  26. using System.Data.Sql;
  27. using System.Data.SqlTypes;
  28. using System.IO;
  29. using System.Security;
  30. using System.Security.Policy;
  31. using System.Security.Permissions;
  32. using System.Data.Common;
  33. using Microsoft.SqlServer.Server;
  34. namespace System.Data.SqlClient {
  35. internal sealed class AssemblyCache {
  36. private AssemblyCache() { /* prevent utility class from being insantiated*/
  37. }
  38. internal static int GetLength(Object inst){
  39. //caller should have allocated enough, based on MaxByteSize
  40. return SerializationHelperSql9.SizeInBytes(inst);
  41. }
  42. //The attribute we are looking for is now moved to an external dll that server provides. If the name is changed.
  43. //then we we have to make corresponding changes here.
  44. //please also change sqludcdatetime.cs, sqltime.cs and sqldate.cs
  45. internal static SqlUdtInfo GetInfoFromType(Type t) {
  46. Debug.Assert(t != null, "Type object cant be NULL");
  47. Type orig = t;
  48. do {
  49. SqlUdtInfo attr = SqlUdtInfo.TryGetFromType(t);
  50. if (attr != null ) {
  51. return attr;
  52. }
  53. else {
  54. t = t.BaseType;
  55. }
  56. }
  57. while (t != null);
  58. throw SQL.UDTInvalidSqlType(orig.AssemblyQualifiedName);
  59. }
  60. }
  61. }