[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection Assembly.cs
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection Assembly.cs, 1.29, 1.30 AssemblyName.cs, 1.4, 1.5 |
Date: |
Wed, 20 Aug 2003 06:58:25 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection
In directory subversions:/tmp/cvs-serv31426/runtime/System/Reflection
Modified Files:
Assembly.cs AssemblyName.cs
Log Message:
Implement the "AssemblyName" class; change the implementation of
"Assembly.FullName" to return the fully-qualified name including
version, culture, and public key token.
Index: Assembly.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Assembly.cs,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** Assembly.cs 7 Aug 2003 14:02:09 -0000 1.29
--- Assembly.cs 20 Aug 2003 10:58:21 -0000 1.30
***************
*** 318,323 ****
== 0)
{
! assembly =
LoadFromFile(assemblyString.Substring(7),
!
out error, caller);
}
else
--- 318,334 ----
== 0)
{
! if(assemblyString.Length >= 10 &&
! assemblyString[7] == '/' &&
! assemblyString[9] == ':')
! {
! // Specification of the form
"file:///X:...".
! assemblyString =
assemblyString.Substring(8);
! }
! else
! {
! // Some other type of file
specification.
! assemblyString =
assemblyString.Substring(7);
! }
! assembly = LoadFromFile(assemblyString,
out error, caller);
}
else
***************
*** 484,492 ****
// Get the full name associated with this assembly.
public virtual String FullName
{
get
{
! return ClrHelpers.GetName(privateData);
}
}
--- 495,507 ----
// Get the full name associated with this assembly.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private String GetFullName();
+
+ // Get the full name associated with this assembly.
public virtual String FullName
{
get
{
! return GetFullName();
}
}
***************
*** 495,516 ****
// Get the code base associated with this assembly.
- [TODO]
public virtual String CodeBase
{
get
{
! // TODO
! return null;
}
}
// Get the escaped code base associated with this assembly.
- [TODO]
public virtual String EscapedCodeBase
{
get
{
! // TODO
! return null;
}
}
--- 510,527 ----
// Get the code base associated with this assembly.
public virtual String CodeBase
{
get
{
! return GetName().CodeBase;
}
}
// Get the escaped code base associated with this assembly.
public virtual String EscapedCodeBase
{
get
{
! return GetName().EscapedCodeBase;
}
}
***************
*** 527,537 ****
// Get the security evidence for this assembly.
- [TODO]
public virtual Evidence Evidence
{
get
{
! // TODO
! return null;
}
}
--- 538,548 ----
// Get the security evidence for this assembly.
public virtual Evidence Evidence
{
get
{
! // We don't use evidence objects in
this implementation
! // at the moment, so return a dummy
evidence object.
! return new Evidence();
}
}
***************
*** 653,664 ****
}
// Get the name of this assembly.
- [TODO]
public virtual AssemblyName GetName()
{
! AssemblyName name = new AssemblyName();
! name.Name = FullName;
! name.Version = new Version(0, 0, 0, 0); // TODO
! return name;
}
public virtual AssemblyName GetName(bool copiedName)
--- 664,691 ----
}
+ // Fill in an assembly name block with a loaded assembly's information.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private void FillAssemblyName(AssemblyName nameInfo);
+
// Get the name of this assembly.
public virtual AssemblyName GetName()
{
! AssemblyName nameInfo = new AssemblyName();
! String filename = GetLocation();
! if(filename != null && filename.Length > 0)
! {
! if(filename[0] == '/' || filename[0] ==
'\\')
! {
! nameInfo.CodeBase = "file://" +
! filename.Replace('\\',
'/');
! }
! else
! {
! nameInfo.CodeBase = "file:///" +
! filename.Replace('\\',
'/');
! }
! }
! FillAssemblyName(nameInfo);
! return nameInfo;
}
public virtual AssemblyName GetName(bool copiedName)
Index: AssemblyName.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/AssemblyName.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** AssemblyName.cs 26 May 2003 04:41:21 -0000 1.4
--- AssemblyName.cs 20 Aug 2003 10:58:21 -0000 1.5
***************
*** 26,33 ****
--- 26,36 ----
using System;
+ using System.IO;
+ using System.Text;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Configuration.Assemblies;
+ using System.Security.Cryptography;
public sealed class AssemblyName
***************
*** 48,69 ****
private byte[] publicKey;
private byte[] publicKeyToken;
// Constructor.
! public AssemblyName() {}
#if CONFIG_SERIALIZATION
! [TODO]
! internal AssemblyName(SerializationInfo info,
! StreamingContext context)
{
! // TODO
}
#endif
// Get the assembly name for a specific file.
- [TODO]
public static AssemblyName GetAssemblyName(String assemblyFile)
{
! // TODO
! return null;
}
--- 51,117 ----
private byte[] publicKey;
private byte[] publicKeyToken;
+ #if CONFIG_SERIALIZATION
+ private SerializationInfo info;
+ #endif
// Constructor.
! public AssemblyName()
! {
! versionCompat =
AssemblyVersionCompatibility.SameMachine;
! }
#if CONFIG_SERIALIZATION
! internal AssemblyName(SerializationInfo info, StreamingContext context)
{
! this.info = info;
}
#endif
+ private AssemblyName(AssemblyName other)
+ {
+ codeBase = other.codeBase;
+ culture = other.culture;
+ flags = other.flags;
+ name = other.name;
+ hashAlg = other.hashAlg;
+ keyPair = other.keyPair;
+ version = (version == null
+ ? null :
(Version)(other.version.Clone()));
+ versionCompat = other.versionCompat;
+ publicKey = (other.publicKey == null
+ ? null :
(byte[])(other.publicKey.Clone()));
+ publicKeyToken = (other.publicKeyToken == null
+ ? null :
(byte[])(other.publicKeyToken.Clone()));
+ }
+
+ // Fill assembly name information from a file. Returns a load error
code.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static int FillAssemblyNameFromFile
+ (AssemblyName nameInfo, String assemblyFile,
Assembly caller);
// Get the assembly name for a specific file.
public static AssemblyName GetAssemblyName(String assemblyFile)
{
! if(assemblyFile == null)
! {
! throw new
ArgumentNullException("assemblyFile");
! }
! assemblyFile = Path.GetFullPath(assemblyFile);
! AssemblyName nameInfo = new AssemblyName();
! if(assemblyFile[0] == '/' || assemblyFile[0] ==
'\\')
! {
! nameInfo.CodeBase = "file://" +
! assemblyFile.Replace('\\', '/');
! }
! else
! {
! nameInfo.CodeBase = "file:///" +
! assemblyFile.Replace('\\', '/');
! }
! int error = FillAssemblyNameFromFile
! (nameInfo, assemblyFile,
Assembly.GetCallingAssembly());
! if(error != Assembly.LoadError_OK)
! {
! Assembly.ThrowLoadError(assemblyFile,
error);
! }
! return nameInfo;
}
***************
*** 95,105 ****
// Get the escaped code base for the assembly name.
- [TODO]
public String EscapedCodeBase
{
get
{
! // TODO
! return codeBase;
}
}
--- 143,167 ----
// Get the escaped code base for the assembly name.
public String EscapedCodeBase
{
get
{
! if(codeBase == null)
! {
! return null;
! }
! StringBuilder builder = new
StringBuilder();
! foreach(char ch in codeBase)
! {
! if(ch == ' ' || ch == '%')
! {
!
builder.Append(String.Format("%{0:x2}", (int)ch));
! }
! else
! {
! builder.Append(ch);
! }
! }
! return builder.ToString();
}
}
***************
*** 119,129 ****
// Get the full name of the assembly.
- [TODO]
public String FullName
{
get
{
! // TODO
! return name;
}
}
--- 181,226 ----
// Get the full name of the assembly.
public String FullName
{
get
{
! if(name == null)
! {
! return null;
! }
! StringBuilder builder = new
StringBuilder();
! builder.Append(name);
! builder.Append(", Version=");
! if(version != null)
! {
!
builder.Append(version.ToString());
! }
! else
! {
! builder.Append("0.0.0.0");
! }
! builder.Append(", Culture=");
! if(culture != null && culture.LCID !=
0x007F)
! {
! builder.Append(culture.Name);
! }
! else
! {
! builder.Append("neutral");
! }
! byte[] token = GetPublicKeyToken();
! builder.Append(", PublicKeyToken=");
! if(token != null)
! {
! foreach(byte b in token)
! {
!
builder.Append(String.Format("{0:x2}", (int)b));
! }
! }
! else
! {
! builder.Append("null");
! }
! return builder.ToString();
}
}
***************
*** 197,201 ****
public Object Clone()
{
! return MemberwiseClone();
}
--- 294,298 ----
public Object Clone()
{
! return new AssemblyName(this);
}
***************
*** 210,213 ****
--- 307,311 ----
{
this.publicKey = publicKey;
+ this.flags |= AssemblyNameFlags.PublicKey;
}
***************
*** 215,218 ****
--- 313,333 ----
public byte[] GetPublicKeyToken()
{
+ #if CONFIG_CRYPTO
+ if(publicKeyToken == null && publicKey != null)
+ {
+ // The public key token is the reverse
of the last
+ // eight bytes of the SHA1 hash of the
public key.
+ SHA1CryptoServiceProvider sha1;
+ sha1 = new SHA1CryptoServiceProvider();
+ byte[] hash =
sha1.ComputeHash(publicKey);
+ ((IDisposable)sha1).Dispose();
+ publicKeyToken = new byte [8];
+ int posn;
+ for(posn = 0; posn < 8; ++posn)
+ {
+ publicKeyToken[posn] =
hash[hash.Length - 1 - posn];
+ }
+ }
+ #endif
return publicKeyToken;
}
***************
*** 227,231 ****
public override String ToString()
{
! return FullName;
}
--- 342,378 ----
public override String ToString()
{
! String name = FullName;
! if(name != null)
! {
! return name;
! }
! return base.ToString();
! }
!
! // Set the culture by name.
! internal void SetCultureByName(String name)
! {
! if(name == null || name.Length == 0 || name ==
"iv")
! {
! culture = null;
! }
! else
! {
! try
! {
! culture = new CultureInfo(name);
! }
! catch(Exception)
! {
! // The culture name was
probably not understood.
! culture = null;
! }
! }
! }
!
! // Set the version information by number.
! internal void SetVersion(int major, int minor, int build, int revision)
! {
! version = new Version(major, minor, build,
revision);
}
***************
*** 233,237 ****
// Get the serialization data for this object.
- [TODO]
public void GetObjectData(SerializationInfo info, StreamingContext
context)
{
--- 380,383 ----
***************
*** 240,244 ****
throw new ArgumentNullException("info");
}
! // TODO
}
--- 386,410 ----
throw new ArgumentNullException("info");
}
! info.AddValue("_Name", name);
! info.AddValue("_PublicKey", publicKey,
typeof(byte[]));
! info.AddValue("_PublicKeyToken", publicKeyToken,
! typeof(byte[]));
! if(culture == null)
! {
! info.AddValue("_CultureInfo", -1);
! }
! else
! {
! info.AddValue("_CultureInfo",
culture.LCID);
! }
! info.AddValue("_CodeBase", codeBase);
! info.AddValue("_Version", version,
typeof(Version));
! info.AddValue("_HashAlgorithm", hashAlg,
!
typeof(AssemblyHashAlgorithm));
! info.AddValue("_StrongNameKeyPair", keyPair,
!
typeof(StrongNameKeyPair));
! info.AddValue("_VersionCompatibility",
versionCompat,
!
typeof(AssemblyVersionCompatibility));
! info.AddValue("_Flags", flags,
typeof(AssemblyNameFlags));
}
***************
*** 246,250 ****
public void OnDeserialization(Object sender)
{
! // Nothing to do here.
}
--- 412,444 ----
public void OnDeserialization(Object sender)
{
! if(info == null)
! {
! return;
! }
! name = info.GetString("_Name");
! publicKey = (byte[])(info.GetValue
! ("_PublicKey", typeof(byte[])));
! publicKeyToken = (byte[])(info.GetValue
! ("_PublicKeyToken", typeof(byte[])));
! int cultureID = info.GetInt32("_CultureInfo");
! if(cultureID != -1)
! {
! culture = new CultureInfo(cultureID);
! }
! else
! {
! culture = null;
! }
! codeBase = info.GetString("_CodeBase");
! version = (Version)(info.GetValue("_Version",
typeof(Version)));
! hashAlg = (AssemblyHashAlgorithm)(info.GetValue
! ("_HashAlgorithm",
typeof(AssemblyHashAlgorithm)));
! keyPair = (StrongNameKeyPair)(info.GetValue
! ("_StrongNameKeyPair",
typeof(StrongNameKeyPair)));
! versionCompat =
(AssemblyVersionCompatibility)(info.GetValue
! ("_VersionCompatibility",
! typeof(AssemblyVersionCompatibility)));
! flags = (AssemblyNameFlags)(info.GetValue
! ("_Flags", typeof(AssemblyNameFlags)));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection Assembly.cs, 1.29, 1.30 AssemblyName.cs, 1.4, 1.5,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System UnitySerializationHolder.cs, NONE, 1.1 DBNull.cs, 1.7, 1.8
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection StrongNameKeyPair.cs, 1.2, 1.3
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System UnitySerializationHolder.cs, NONE, 1.1 DBNull.cs, 1.7, 1.8
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection StrongNameKeyPair.cs, 1.2, 1.3
- Index(es):