ToString() 공개 메소드

public ToString ( ) : String
리턴 String
예제 #1
0
    public ChooseAssemblyName(AssemblyName assemblyName = null)
    {
      InitializeComponent();

      if (assemblyName != null)
        _assemblyName.Text = assemblyName.ToString();
    }
 public static void InitDAD()
 {
     AppDomain ad = AppDomain.CurrentDomain;
     AssemblyName asmName = new AssemblyName();
     asmName.Name = @"G:\naynish\Pro C# 2010 and the .NET 4 Platform\ReflectionLateBindingAttributeBased\ConsoleApplication1\ConsoleApplication1\bin\Debug\MathLibrary.dll";
     ad.AssemblyLoad += new AssemblyLoadEventHandler(ad_AssemblyLoad);
     Assembly.LoadFrom(asmName.ToString());
 }
예제 #3
0
        private string GetGameVersion()
        {
            string output = "Version: ";
            try
            {
            #if WINDOWS_PHONE
                Version version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version;
                return output + version.ToString();
            #endif
            }
            catch
            { }

            //Version for windows
            return output + "1.0.0.1";
        }
예제 #4
0
 private void LoadExternalModule(string path)
 {
     AssemblyName asmName = new AssemblyName();
     asmName.Name = path;
     Assembly asm = Assembly.LoadFrom(asmName.ToString());
     Type[] arrr = asm.GetTypes();
     foreach (Type item in arrr)
     {
         if (item.IsClass && item.GetInterface("MyApplicationInterface")!= null
             && item.GetCustomAttributes(typeof(AppHooks.MyCustomAttributes), false) != null)
         {
             MyApplicationInterface mai = (MyApplicationInterface)Activator.CreateInstance(item);
             mai.DisplayMessage();
             listBox1.Items.Add(item.FullName);
             LoadAttributes(item);
         }
     }
 }
 public void Case2_ToString()
 {
     AssemblyName n = new AssemblyName("Foo");
     Assert.True(n.ToString().StartsWith("Foo"));
 }
예제 #6
0
		public void Update (AssemblyName aname)
		{
			Name = aname.Name;
			Version = aname.Version.ToString ();
			ProcessorArchitecture = aname.ProcessorArchitecture;
			Culture = aname.CultureInfo.Name;
			string fn = aname.ToString ();
			string key = "publickeytoken=";
			int i = fn.ToLower().IndexOf (key) + key.Length;
			int j = fn.IndexOf (',', i);
			if (j == -1) j = fn.Length;
			PublicKeyToken = fn.Substring (i, j - i);
		}
 private static Assembly LoadAssemblyHelper(string assemblyGivenName, string assemblyPath)
 {
     AssemblyName reference = new AssemblyName(assemblyGivenName);
     string str = reference.Name.ToUpper(CultureInfo.InvariantCulture);
     Assembly loadedAssembly = (Assembly) _loadedAssembliesHash[str];
     if (loadedAssembly != null)
     {
         if (reference.Version != null)
         {
             AssemblyName definition = new AssemblyName(loadedAssembly.FullName);
             if (!AssemblyName.ReferenceMatchesDefinition(reference, definition))
             {
                 string str2 = reference.ToString();
                 string str3 = definition.ToString();
                 throw new InvalidOperationException(System.Xaml.SR.Get("ParserAssemblyLoadVersionMismatch", new object[] { str2, str3 }));
             }
         }
         return loadedAssembly;
     }
     if (string.IsNullOrEmpty(assemblyPath))
     {
         loadedAssembly = SafeSecurityHelper.GetLoadedAssembly(reference);
     }
     if (loadedAssembly == null)
     {
         if (!string.IsNullOrEmpty(assemblyPath))
         {
             loadedAssembly = Assembly.LoadFile(assemblyPath);
         }
         else
         {
             try
             {
                 loadedAssembly = Assembly.Load(assemblyGivenName);
             }
             catch (FileNotFoundException)
             {
                 loadedAssembly = null;
             }
         }
     }
     if (loadedAssembly != null)
     {
         _loadedAssembliesHash[str] = loadedAssembly;
     }
     return loadedAssembly;
 }
        private Assembly ProbeForPlatformSpecificAssembly(string platformName)
        {
            var assemblyName = new AssemblyName(GetType().Assembly.FullName)
            {
                Name = "AutoMapper." + platformName
            };

            try
            {
                return _assemblyLoader(assemblyName.ToString());
            }
            catch (FileNotFoundException)
            {
            }

            return null;
        }
예제 #9
0
        // This event handler is called when a ReflectionOnlyLoad can't succeed because of
        // a required assembly not being present.  This handler attempts to load that
        // assembly from the known place where the root assembly lives.
        // NOTE:  It is assumed that all prerequisite assemblies are in the assembly path
        //        table passed to the TypeMapper via SetAssemblyPath().
        private Assembly OnReferencedAssemblyResolve(
            object sender,
            ResolveEventArgs args)
        {
            if (_assemblyPathTable != null && _assemblyPathTable.Count > 0)
            {
                AssemblyName assemblyName = new AssemblyName(args.Name);
                string assemblyShortName = assemblyName.Name;
                assemblyShortName = assemblyShortName.ToUpper(CultureInfo.InvariantCulture);

                Assembly asm = ReflectionHelper.GetAlreadyReflectionOnlyLoadedAssembly(assemblyShortName);
                if (asm != null)
                {
                    if (assemblyName.Version != null)
                    {
                        AssemblyName cachedName = new AssemblyName(asm.FullName);
                        if (!AssemblyName.ReferenceMatchesDefinition(assemblyName, cachedName))
                        {
                            string request = assemblyName.ToString();
                            string found = cachedName.ToString();
                            throw new InvalidOperationException(SR.Get(SRID.ParserAssemblyLoadVersionMismatch, request, found));
                        }
                    }
                    return asm;
                }
                else
                {
                    string assemblyFullPath = _assemblyPathTable[args.Name] as String;

                    if (!String.IsNullOrEmpty(assemblyFullPath) && File.Exists(assemblyFullPath))
                    {
                       return ReflectionHelper.LoadAssembly(args.Name, assemblyFullPath);
                    }
                }
            }

            return ReflectionHelper.LoadAssembly(args.Name, null);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine(Fname);
            BasicMath bm = new BasicMath();
            Console.WriteLine("sum = {0}", bm.Add(10.45, 243.39));
            //different ways to create type instance
            //System.Object
            Type t = bm.GetType();
            System.Reflection.MethodInfo mtInfo = t.GetMethod("Add");
            Console.WriteLine("is Add public {0}", mtInfo.IsPublic);

            //typeof
            Type typo = typeof(BasicMath);

            //you don't need compile time info about the type
            //System.Type.GetType (static method)
            try
            {
                // Obtain type information for a type within an external assembly.
                //fully qualified name of the type, friendly name of the assembly
                Type sysType = System.Type.GetType("MathLibrary.BasicMath, MathLibrary", true, false);

                //Obtain type information for a nested class (add + for nested types)
                System.Type.GetType("MathLibrary.BasicMath+Trigonometry, MathLibrary", true, false);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }

            /*“back tick” character (`) followed by a numerical value that represents
            the number of type parameters*/
            //System.Collections.Generic.List<T>
            Type tInfo = System.Type.GetType("System.Collections.Generic.List`1, mscorlib", true, false);
            RedReflector rdr = new RedReflector();
            rdr.ListMethods(tInfo);
            //rdr.ListProperties(tInfo);
            rdr.ListInterfaces(tInfo);
            rdr.ListStats(tInfo);

            //dynamically loading assembly
            ExternalAssemblyReflector ear = new ExternalAssemblyReflector();
            //ear.DisplayTypesInAsm(Assembly.LoadFrom(@"G:\naynish\Pro C# 2010 and the .NET 4 Platform\ReflectionLateBindingAttributeBased\ConsoleApplication1\MathLibrary\bin\Debug\MathLibrary.dll"));

            String extPath = @"G:\naynish\Pro C# 2010 and the .NET 4 Platform\ReflectionLateBindingAttributeBased\ConsoleApplication1\SimpleEmployee\bin\Debug\SimpleEmployee.dll";
            AssemblyName asmName = new AssemblyName();
            //path including the extension
            asmName.Name = extPath;

            //LoadFrom because the assembly is not in the bin directory of ConsoleApplication1
            ear.DisplayTypesInAsm(Assembly.LoadFrom(asmName.ToString()));

            //loading shared assemblies
            Assembly myAssembly = Assembly.Load(@"System.Windows.Forms, Version = 4.0.0.0, PublicKeyToken = b77a5c561934e089, Culture = """);
            ear.DisplayTypesInSharedAsm(myAssembly);

            AssemblyName customMyAssembly = new AssemblyName();
            customMyAssembly.Name = "CustomLibrary";
            Version v = new Version("1.0.0.0");
            customMyAssembly.Version = v;

            Assembly a = Assembly.Load(customMyAssembly);
            ear.DisplayTypesInAsm(a);
            AttributeBased ab = new AttributeBased();
            //ab.salary; (error on reflecting over this type using C# compiler)

            //reflect over an attributed type
            AssemblyName name = new AssemblyName();
            name.Name = "AttributedEmployeeLibrary";
            Assembly myAttr = Assembly.Load(name);

            Type tp = myAttr.GetType("AttributedEmployeeLibrary.VicePresident");
            Object myInstance = Activator.CreateInstance(tp);
            MethodInfo info = tp.GetMethod("GetFname");
            Console.WriteLine(info.Invoke(myInstance, null));

            Object[] custAttr = tp.GetCustomAttributes(false);
            foreach (var item in custAttr)
            {
                Console.WriteLine(item);
            }

            foreach (Type item in myAttr.GetTypes())
            {
                foreach (object item1 in item.GetCustomAttributes(myAttr.GetType("AttributedEmployeeLibrary.EmployeeDescriptionAttribute"), false))
                {
                    Console.WriteLine((myAttr.GetType("AttributedEmployeeLibrary.EmployeeDescriptionAttribute").GetProperty("Description")).GetValue(item1,null));
                }
            }
            Console.ReadLine();
        }
예제 #11
0
 bool Matches(AssemblyName a, AssemblyName b)
 {
     return a.ToString() == b.ToString();
 }
예제 #12
0
        private void ProcessAssemblyName(AssemblyName assemblyName)
        {
            WriteVerbose("DisplayName: " + assemblyName.ToString());

            if (_version != null)
            {
                if (_version != assemblyName.Version)
                {
                    WriteVerbose(String.Format("Version: {0} != {1}", _version, assemblyName.Version));
                    return;
                }
            }

            if (Import.IsPresent)
            {
                WriteVerbose("Importing " + assemblyName);

                // import the assembly
                WriteObject(Assembly.Load(assemblyName));
            }
            else
            {
                // pass-thru AssemblyName object
                WriteObject(assemblyName);
            }
        }
예제 #13
0
파일: MonoAssembly.cs 프로젝트: Numpsy/mono
		internal static RuntimeAssembly LoadWithPartialNameInternal (AssemblyName an, Evidence securityEvidence, ref StackCrawlMark stackMark)
		{
			return LoadWithPartialNameInternal (an.ToString (), securityEvidence, ref stackMark);
		}
        public void GetFullNameAndToString_AreEquivalentAndDoNotPreserveArchitecture()
        {
            foreach (KeyValuePair<string, ProcessorArchitecture> pair in GetValidNameValuePairs())
            {
                string originalFullName = "Test, Culture=en-US, PublicKeyToken=b77a5c561934e089, ProcessorArchitecture=" + pair.Key;
                string expectedSerializedFullName = "Test, Culture=en-US, PublicKeyToken=b77a5c561934e089";

                var assemblyName = new AssemblyName(originalFullName);

                Assert.Equal(expectedSerializedFullName, assemblyName.FullName);
                Assert.Equal(expectedSerializedFullName, assemblyName.ToString());
            }
        }
예제 #15
0
	[Test] // ctor (String)
	public void Constructor1_Name ()
	{
		const string assemblyName = "TestAssembly";

		an = new AssemblyName (assemblyName);
		Assert.IsNull (an.CodeBase, "CodeBase");
		Assert.IsNull (an.CultureInfo, "CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
		Assert.AreEqual ("TestAssembly", an.FullName, "FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "PA");
		Assert.IsNull (an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "GetPublicKey");
		Assert.IsNull (an.GetPublicKeyToken (), "GetPublicKeyToken");
		Assert.AreEqual ("TestAssembly", an.ToString (), "ToString");
#if NET_4_5
		Assert.IsNull (an.CultureName, "CultureName");
		Assert.AreEqual (AssemblyContentType.Default, an.ContentType, "ContentType");
#endif
	}
예제 #16
0
 public static IEnumerable<string> GetAssemblyStrongNames(AssemblyName assemblyName)
 {
     return GetAssemblyStrongNames(assemblyName.ToString());
 }
예제 #17
0
	public void Serialization_WithoutStrongName ()
	{
		an = new AssemblyName ();
		an.CodeBase = "http://www.test.com/test.dll";
		an.CultureInfo = CultureInfo.InvariantCulture;
		an.Flags = AssemblyNameFlags.None;
		an.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
		an.KeyPair = null;
		an.Name = "TestAssembly2";
		an.Version = new Version (1, 5, 0, 0);
		an.VersionCompatibility = AssemblyVersionCompatibility.SameMachine;

		MemoryStream ms = new MemoryStream ();
		BinaryFormatter bf = new BinaryFormatter ();
		bf.Serialize (ms, an);

		// reset position of memorystream
		ms.Position = 0;

		// deserialze assembly name
		AssemblyName dsAssemblyName = (AssemblyName) bf.Deserialize (ms);

		// close the memorystream
		ms.Close ();

		// compare orginal and deserialized assembly name
		Assert.AreEqual (an.CodeBase, dsAssemblyName.CodeBase, "CodeBase");
		Assert.AreEqual (an.CultureInfo, dsAssemblyName.CultureInfo, "CultureInfo");
		Assert.AreEqual (an.Flags, dsAssemblyName.Flags, "Flags");
		Assert.AreEqual (an.HashAlgorithm, dsAssemblyName.HashAlgorithm, "HashAlgorithm");
		Assert.AreEqual (an.Name, dsAssemblyName.Name, "Name");
		Assert.AreEqual (an.Version, dsAssemblyName.Version, "Version");
		Assert.AreEqual (an.VersionCompatibility, dsAssemblyName.VersionCompatibility, "VersionCompatibility");
		Assert.AreEqual (an.EscapedCodeBase, dsAssemblyName.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (an.FullName, dsAssemblyName.FullName, "FullName");
		Assert.AreEqual (an.ToString (), dsAssemblyName.ToString (), "ToString");
		Assert.AreEqual (an.GetPublicKey (), dsAssemblyName.GetPublicKey (), "PublicKey");
		Assert.AreEqual (an.GetPublicKeyToken (), dsAssemblyName.GetPublicKeyToken (), "PublicToken");
	}
예제 #18
0
		public static Type GetType (string typeName, bool throwOnError, bool ignoreCase)
		{
			if (String.IsNullOrEmpty (typeName))
				throw new HttpException ("Type name must not be empty.");
			
			Type ret = null;
			Exception ex = null;
			try {
				string wantedAsmName;
				string wantedTypeName;
				int comma = typeName.IndexOf (',');

				if (comma > 0 && comma < typeName.Length - 1) {
					var aname = new AssemblyName (typeName.Substring (comma + 1));
					wantedAsmName = aname.ToString ();
					wantedTypeName = typeName.Substring (0, comma);
				} else {
					wantedAsmName = null;
					wantedTypeName = typeName;
				}

				var assemblies = new List <Assembly> ();
				assemblies.AddRange (BuildManager.GetReferencedAssemblies () as List <Assembly>);
				assemblies.AddRange (TopLevel_Assemblies);
				Type appType = HttpApplicationFactory.AppType;
				if (appType != null)
					assemblies.Add (appType.Assembly);
				
				foreach (Assembly asm in assemblies) {
					if (asm == null)
						continue;

					if (wantedAsmName != null) {
						// So dumb...
						if (String.Compare (wantedAsmName, asm.GetName ().ToString (), StringComparison.Ordinal) == 0) {
							ret = asm.GetType (wantedTypeName, throwOnError, ignoreCase);
							if (ret != null)
								return ret;
						}
						continue;
					}
					
					ret = asm.GetType (wantedTypeName, false, ignoreCase);
					if (ret != null)
						return ret;
				}
			} catch (Exception e) {
				ex = e;
			}

			if (throwOnError)
				throw new HttpException ("Failed to find the specified type.", ex);

			return null;
		}
예제 #19
0
	public void Clone_Self ()
	{
		an = Assembly.GetExecutingAssembly ().GetName ();
		AssemblyName clone = (AssemblyName) an.Clone ();

		Assert.AreEqual (an.CodeBase, clone.CodeBase, "CodeBase");
		Assert.AreEqual (an.CultureInfo, clone.CultureInfo, "CultureInfo");
		Assert.AreEqual (an.EscapedCodeBase, clone.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (an.Flags, clone.Flags, "Flags");
		Assert.AreEqual (an.FullName, clone.FullName, "FullName");
		Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm, "HashAlgorithm");
		Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair");
		Assert.AreEqual (an.Name, clone.Name, "Name");
#if NET_2_0
		//Assert.AreEqual (ProcessorArchitecture.MSIL, clone.ProcessorArchitecture, "PA");
#endif
		Assert.AreEqual (an.Version, clone.Version, "Version");
		Assert.AreEqual (an.VersionCompatibility, clone.VersionCompatibility, "VersionCompatibility");
		Assert.AreEqual (an.GetPublicKey (), clone.GetPublicKey (), "GetPublicKey");
		Assert.AreEqual (an.GetPublicKeyToken (), clone.GetPublicKeyToken (), "GetPublicKeyToken");
		Assert.AreEqual (an.ToString (), clone.ToString (), "ToString");
	}
 private static bool ReferenceMatchesDefinitionEx(AssemblyName reference, AssemblyName definition)
 {
     #if __MonoCS__
     return string.Equals(reference.ToString(), definition.ToString(), StringComparison.OrdinalIgnoreCase);
     #else
     return AssemblyName.ReferenceMatchesDefinition(reference, definition);
     #endif
 }
예제 #21
0
	[Category ("NotWorking")] // bug #351708
	public void Constructor1_ProcessorArchitecture ()
	{
		const string assemblyName = "TestAssembly";

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=X86");
		Assert.IsNull (an.CodeBase, "CodeBase");
		Assert.IsNull (an.CultureInfo, "CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
		Assert.AreEqual ("TestAssembly", an.FullName, "FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "Name");
		Assert.AreEqual (ProcessorArchitecture.X86, an.ProcessorArchitecture, "PA");
		Assert.IsNull (an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "GetPublicKey");
		Assert.IsNull (an.GetPublicKeyToken (), "GetPublicKeyToken");
		Assert.AreEqual ("TestAssembly", an.ToString (), "ToString");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=mSiL");
		Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "PA: MSIL");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=AmD64");
		Assert.AreEqual (ProcessorArchitecture.Amd64, an.ProcessorArchitecture, "PA: Amd64");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=iA64");
		Assert.AreEqual (ProcessorArchitecture.IA64, an.ProcessorArchitecture, "PA: IA64");
	}
예제 #22
0
파일: MakeSfxCA.cs 프로젝트: zooba/wix3
        /// <summary>
        /// Sets up a reflection-only assembly-resolve-handler to handle loading dependent assemblies during reflection.
        /// </summary>
        /// <param name="inputFiles">List of input files which include non-GAC dependent assemblies.</param>
        /// <param name="inputDir">Directory to auto-locate additional dependent assemblies.</param>
        /// <remarks>
        /// Also searches the assembly's directory for unspecified dependent assemblies, and adds them
        /// to the list of input files if found.
        /// </remarks>
        private static void ResolveDependentAssemblies(IDictionary<string, string> inputsMap, string inputDir)
        {
            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += delegate(object sender, ResolveEventArgs args)
            {
                AssemblyName resolveName = new AssemblyName(args.Name);
                Assembly assembly = null;

                // First, try to find the assembly in the list of input files.
                foreach (string inputFile in inputsMap.Values)
                {
                    string inputName = Path.GetFileNameWithoutExtension(inputFile);
                    string inputExtension = Path.GetExtension(inputFile);
                    if (String.Equals(inputName, resolveName.Name, StringComparison.OrdinalIgnoreCase) &&
                        (String.Equals(inputExtension, ".dll", StringComparison.OrdinalIgnoreCase) ||
                         String.Equals(inputExtension, ".exe", StringComparison.OrdinalIgnoreCase)))
                    {
                        assembly = MakeSfxCA.TryLoadDependentAssembly(inputFile);

                        if (assembly != null)
                        {
                            break;
                        }
                    }
                }

                // Second, try to find the assembly in the input directory.
                if (assembly == null && inputDir != null)
                {
                    string assemblyPath = null;
                    if (File.Exists(Path.Combine(inputDir, resolveName.Name) + ".dll"))
                    {
                        assemblyPath = Path.Combine(inputDir, resolveName.Name) + ".dll";
                    }
                    else if (File.Exists(Path.Combine(inputDir, resolveName.Name) + ".exe"))
                    {
                        assemblyPath = Path.Combine(inputDir, resolveName.Name) + ".exe";
                    }

                    if (assemblyPath != null)
                    {
                        assembly = MakeSfxCA.TryLoadDependentAssembly(assemblyPath);

                        if (assembly != null)
                        {
                            // Add this detected dependency to the list of files to be packed.
                            inputsMap.Add(Path.GetFileName(assemblyPath), assemblyPath);
                        }
                    }
                }

                // Third, try to load the assembly from the GAC.
                if (assembly == null)
                {
                    try
                    {
                        assembly = Assembly.ReflectionOnlyLoad(args.Name);
                    }
                    catch (FileNotFoundException)
                    {
                    }
                }

                if (assembly != null)
                {
                    if (String.Equals(assembly.GetName().ToString(), resolveName.ToString()))
                    {
                        log.WriteLine("    Loaded dependent assembly: " + assembly.Location);
                        return assembly;
                    }
                    else
                    {
                        log.WriteLine("    Warning: Loaded mismatched dependent assembly: " + assembly.Location);
                        log.WriteLine("      Loaded assembly   : " + assembly.GetName());
                        log.WriteLine("      Reference assembly: " + resolveName);
                    }
                }
                else
                {
                    log.WriteLine("    Error: Dependent assembly not supplied: " + resolveName);
                }

                return null;
            };
        }
예제 #23
0
	[Test] // ctor (String)
	public void Constructor1_PublicKeyToken ()
	{
		const string assemblyName = "TestAssembly";

		an = new AssemblyName (assemblyName + ", PublicKeyToken=" + GetTokenString (pk_token1));
		Assert.IsNull (an.CodeBase, "#A:CodeBase");
		Assert.IsNull (an.CultureInfo, "#A:CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "#A:EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A:Flags");
		Assert.AreEqual ("TestAssembly, PublicKeyToken=" + GetTokenString (pk_token1), an.FullName, "#A:FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "#A:HashAlgorithm");
		Assert.IsNull (an.KeyPair, "#A:KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "#A:Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "#A:PA");
		Assert.IsNull (an.Version, "#A:Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "#A:VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "#A:GetPublicKey");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#A:GetPublicKeyToken");
		Assert.AreEqual (an.FullName, an.ToString (), "#A:ToString");

		an = new AssemblyName (assemblyName + ", PublicKeyToken=null");
		Assert.IsNull (an.CodeBase, "#B:CodeBase");
		Assert.IsNull (an.CultureInfo, "#B:CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "#B:EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#B:Flags");
		//Assert.AreEqual ("TestAssembly, PublicKeyToken=null", an.FullName, "#B:FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "#B:HashAlgorithm");
		Assert.IsNull (an.KeyPair, "#B:KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "#B:Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "#B:PA");
		Assert.IsNull (an.Version, "#B:Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "#B:VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "#B:GetPublicKey");
		Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#B:GetPublicKeyToken");
		Assert.AreEqual (an.FullName, an.ToString (), "#B:ToString");
	}
예제 #24
0
 internal static RuntimeAssembly LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, ref StackCrawlMark stackMark)
 {
     return(LoadWithPartialNameInternal(an.ToString(), securityEvidence, ref stackMark));
 }
예제 #25
0
	[Test] // ctor (String)
	public void Constructor1_Retargetable ()
	{
		const string assemblyName = "TestAssembly";

		try {
			new AssemblyName (assemblyName + ", Retargetable=Yes");
			Assert.Fail ("#A1");
		} catch (FileLoadException ex) {
			// The given assembly name or codebase was invalid
			Assert.AreEqual (typeof (FileLoadException), ex.GetType (), "#A2");
			Assert.IsNull (ex.FileName, "#A3");
			Assert.IsNull (ex.InnerException, "#A4");
			Assert.IsNotNull (ex.Message, "#A5");
		}

		try {
			new AssemblyName (assemblyName + ", Retargetable=No");
			Assert.Fail ("#B1");
		} catch (FileLoadException ex) {
			// The given assembly name or codebase was invalid
			Assert.AreEqual (typeof (FileLoadException), ex.GetType (), "#B2");
			Assert.IsNull (ex.FileName, "#B3");
			Assert.IsNull (ex.InnerException, "#B4");
			Assert.IsNotNull (ex.Message, "#B5");
		}

		try {
			new AssemblyName (assemblyName + ", Version=1.0.0.0, Retargetable=Yes");
			Assert.Fail ("#C1");
		} catch (FileLoadException ex) {
			// The given assembly name or codebase was invalid
			Assert.AreEqual (typeof (FileLoadException), ex.GetType (), "#C2");
			Assert.IsNull (ex.FileName, "#C3");
			Assert.IsNull (ex.InnerException, "#C4");
			Assert.IsNotNull (ex.Message, "#C5");
		}

		try {
			new AssemblyName (assemblyName + ", Version=1.0.0.0, Culture=neutral, Retargetable=Yes");
			Assert.Fail ("#D1");
		} catch (FileLoadException ex) {
			// The given assembly name or codebase was invalid
			Assert.AreEqual (typeof (FileLoadException), ex.GetType (), "#D2");
			Assert.IsNull (ex.FileName, "#D3");
			Assert.IsNull (ex.InnerException, "#D4");
			Assert.IsNotNull (ex.Message, "#D5");
		}

		try {
			new AssemblyName (assemblyName + ", Version=1.0.0.0, PublicKeyToken=null, Retargetable=Yes");
			Assert.Fail ("#E1");
		} catch (FileLoadException ex) {
			// The given assembly name or codebase was invalid
			Assert.AreEqual (typeof (FileLoadException), ex.GetType (), "#E2");
			Assert.IsNull (ex.FileName, "#E3");
			Assert.IsNull (ex.InnerException, "#E4");
			Assert.IsNotNull (ex.Message, "#E5");
		}

		an = new AssemblyName (assemblyName + ", Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=yEs");
		Assert.IsNull (an.CodeBase, "F:CodeBase");
		Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#F:CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "#F:EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.Retargetable, an.Flags, "#F:Flags");
		Assert.AreEqual ("TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=Yes", an.FullName, "#F:FullName");
		Assert.IsNull (an.GetPublicKey (), "#F:GetPublicKey");
		Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#F:GetPublicKeyToken");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "#F:HashAlgorithm");
		Assert.IsNull (an.KeyPair, "#F:KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "#F:Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "#F:PA");
		Assert.AreEqual (an.FullName, an.ToString (), "#F:ToString");
		Assert.AreEqual (new Version (1, 0, 0, 0), an.Version, "#F:Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "#F:VersionCompatibility");

		an = new AssemblyName (assemblyName + ", Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=nO");
		Assert.IsNull (an.CodeBase, "G:CodeBase");
		Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#G:CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "#G:EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#G:Flags");
		Assert.AreEqual ("TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#G:FullName");
		Assert.IsNull (an.GetPublicKey (), "#G:GetPublicKey");
		Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#G:GetPublicKeyToken");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "#G:HashAlgorithm");
		Assert.IsNull (an.KeyPair, "#G:KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "#G:Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "#G:PA");
		Assert.AreEqual (an.FullName, an.ToString (), "#G:ToString");
		Assert.AreEqual (new Version (1, 0, 0, 0), an.Version, "#G:Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "#G:VersionCompatibility");

		an = new AssemblyName (assemblyName + ", Version=1.0.0.0, Culture=neutral, PublicKeyToken=" + GetTokenString (pk_token1) + ", Retargetable=yes");
		Assert.IsNull (an.CodeBase, "H:CodeBase");
		Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#H:CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "#H:EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.Retargetable, an.Flags, "#H:Flags");
		Assert.AreEqual ("TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=" + GetTokenString (pk_token1) + ", Retargetable=Yes", an.FullName, "#H:FullName");
		Assert.IsNull (an.GetPublicKey (), "#H:GetPublicKey");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#H:GetPublicKeyToken");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "#H:HashAlgorithm");
		Assert.IsNull (an.KeyPair, "#H:KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "#H:Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "#H:PA");
		Assert.AreEqual (an.FullName, an.ToString (), "#H:ToString");
		Assert.AreEqual (new Version (1, 0, 0, 0), an.Version, "#H:Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "#H:VersionCompatibility");
	}
예제 #26
0
		//If we can't load an assembly directly, maybe it's in the path
		private Assembly GetAssemblyByName(AssemblyName an)
		{
			try
			{
				Assembly asm = Assembly.Load(an);
				return asm;
			}
			catch{}

			//may I please point out that my actual finished code does not contain things like this.
			//In real life, I would have found some elegant way to make services such as 'finding an assembly in a given path'
			//available to all objects that need them without having to cast up the GUI hierarchy.
			//Ironically, as this code is free there is a high chance that someone will notice my ugly kludge, whereas in the
			//code I'm PAID to write, I could easily get away with this kind of structure if I wanted to.
			//I'm sure there is some sort of commentary about the whole Open Source thing in there, but I don't know what it is.
			MainFrame fr = (MainFrame)this.TreeView.Parent.Parent.Parent;

			ArrayList arr = fr.GetPathAssemblies();

			for(int i=0;i<arr.Count; ++i)
			{
				AssemblyName a = ((Assembly)arr[i]).GetName(); //have to compare strings as Equals() does not work(?)

				if (a.ToString() == an.ToString())
				{
					return (Assembly)arr[i];
				}
			}

			return null;
		}
예제 #27
0
	[Test] // ctor ()
	public void Constructor0 ()
	{
		an = new AssemblyName ();
		Assert.IsNull (an.CodeBase, "CodeBase");
		Assert.IsNull (an.CultureInfo, "CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
#if NET_2_0
		Assert.AreEqual (String.Empty, an.FullName, "FullName");
#else
		Assert.IsNull (an.FullName, "FullName");
#endif
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.IsNull (an.Name, "Name");
#if NET_2_0
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "PA");
#endif
		Assert.IsNull (an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "GetPublicKey");
		Assert.IsNull (an.GetPublicKeyToken (), "GetPublicKeyToken");
#if NET_2_0
		Assert.AreEqual (string.Empty, an.ToString (), "ToString");
#else
		Assert.AreEqual (typeof (AssemblyName).FullName, an.ToString (), "ToString");
#endif
	}
예제 #28
0
 public static string GetAssemblyVersion (AssemblyName assembly)
 {
     Match versionMatch = Regex.Match(assembly.ToString(), @"Version=([\d.]+)");
     return versionMatch.Groups[1].Success ? versionMatch.Groups[1].Value : "unknown";
 }
예제 #29
0
	[Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM.
	public void Constructor1_Version ()
	{
		const string assemblyName = "TestAssembly";
		const string assemblyVersion = "1.2.3.4";

		an = new AssemblyName (assemblyName + ", Version=" + assemblyVersion);
		Assert.IsNull (an.CodeBase, "CodeBase");
		Assert.IsNull (an.CultureInfo, "CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
		Assert.AreEqual ("TestAssembly, Version=1.2.3.4", an.FullName, "FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "Name");
		Assert.AreEqual (ProcessorArchitecture.None, an.ProcessorArchitecture, "PA");
		Assert.AreEqual (new Version (assemblyVersion), an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "GetPublicKey");
		Assert.IsNull (an.GetPublicKeyToken (), "GetPublicKeyToken");
		Assert.AreEqual (an.FullName, an.ToString (), "ToString");
	}
 public void Case3_ToString()
 {
     String name = "Hi There";
     AssemblyName n = new AssemblyName(name);
     Assert.True(n.ToString().StartsWith(name));
 }
예제 #31
0
	public void Self ()
	{
		Assembly a = Assembly.GetExecutingAssembly ();
		an = a.GetName ();

		Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "CultureInfo");
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "Flags");
		Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.IsNotNull (an.Name, "Name");
#if NET_2_0
		//Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "PA");
#endif
		Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine,
			an.VersionCompatibility, "VersionCompatibility");
		Assert.AreEqual (new byte [0], an.GetPublicKey (), "GetPublicKey");
		Assert.AreEqual (an.FullName, an.ToString (), "ToString");
	}