当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyName.Contains方法代码示例

本文整理汇总了C#中System.Reflection.AssemblyName.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.Contains方法的具体用法?C# AssemblyName.Contains怎么用?C# AssemblyName.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.AssemblyName的用法示例。


在下文中一共展示了AssemblyName.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleAssemblyResolve

        public static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
        {
            string assemblyName = new AssemblyName(args.Name).Name + ".dll";
            if(assemblyName.Contains(".resources"))
            {
                //Console.WriteLine("AssemblyResolve: {0}", assemblyName);
                return null;
            }

            string fullAssemblyName = string.Empty;
            foreach(var manifestResource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if(manifestResource.Contains(assemblyName))
                {
                    fullAssemblyName = manifestResource;
                    break;
                }
            }

            if(fullAssemblyName == string.Empty)
                return null;

            using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullAssemblyName))
            {
                byte[] assemblyData = new byte[stream.Length];
                stream.Read(assemblyData, 0, assemblyData.Length);
                return Assembly.Load(assemblyData);
            }
        }
开发者ID:PowerOfDark,项目名称:HLDJConverter,代码行数:29,代码来源:App.xaml.cs

示例2: Run

        public void Run()
        {
            string absoluteAssemblyDir = Path.GetFullPath(BuildAssemblyPath);
            string assemblyPath = Path.Combine(absoluteAssemblyDir, BuildAssemblyName);

            AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
            {
                // FIXME: Imprecise
                var requestedAssemblyName = new AssemblyName(e.Name).Name;
                if (! requestedAssemblyName.Contains("System"))
                {
                    string requestedAssemblyDll = requestedAssemblyName + ".dll";

                    foreach (string reference in References)
                    {
                        if (reference.ToLowerInvariant().Contains(requestedAssemblyDll.ToLowerInvariant()))
                            return Assembly.LoadFrom(reference);
                    }

                    var candidateAssemblyPath = Path.Combine(absoluteAssemblyDir, requestedAssemblyDll);
                    if (File.Exists(candidateAssemblyPath))
                        return Assembly.LoadFrom(candidateAssemblyPath);
                }

                return null;
            };

            string serializersAssemblyPath = Path.ChangeExtension(assemblyPath, ".XmlSerializers.dll");
            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            List<Type> serializableTypes = new List<Type>();
            foreach (Type type in assembly.GetExportedTypes())
            {
                if (type.IsDefined(typeof(XmlRootAttribute), false))
                    serializableTypes.Add(type);
            }

            List<XmlMapping> mappings = new List<XmlMapping>();
            XmlReflectionImporter importer = new XmlReflectionImporter();

            foreach (Type type in serializableTypes)
            {
                XmlMapping mapping = importer.ImportTypeMapping(type);
                mappings.Add(mapping);
            }

            CompilerParameters compilerParameters = new CompilerParameters();

            compilerParameters.TempFiles = new TempFileCollection();
            compilerParameters.IncludeDebugInformation = false;
            compilerParameters.GenerateInMemory = false;
            compilerParameters.OutputAssembly = serializersAssemblyPath;

            if (KeyFile != null)
                compilerParameters.CompilerOptions += " /keyfile:\"" + KeyFile + "\"";

            XmlSerializer.GenerateSerializer(serializableTypes.ToArray(),
                mappings.ToArray(), compilerParameters);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:59,代码来源:Program.cs

示例3: OnAssemblyResolve

        /// <summary>
        /// Event handler method to resolve DLL assemblies that can't be found automatically.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        internal static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            Assembly assembly;
            string keyName = new AssemblyName(args.Name).Name;
            if (keyName.Contains(".resources"))
            {
                return null;  // This line is what fixed the problem
            }

            //Go through hint paths to see if we can help add assembly references
            var referenceFromHintPaths = _hintPaths.Where(p => p.EndsWith(string.Format(@"\{0}.dll", keyName)));
            foreach (var hintPath in referenceFromHintPaths)
            {
                assembly = Assembly.LoadFile(hintPath);
                if (!_libs.ContainsKey(keyName))
                {
                    _libs.Add(keyName, assembly);
                }
            }

            if (_libs.ContainsKey(keyName))
            {
                assembly = _libs[keyName]; // If DLL is loaded then don't load it again just return
                return assembly;
            }

            string dllName = DllResourceName(keyName);
            //string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();   // Uncomment this line to debug the possible values for dllName
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(dllName))
            {
                if (stream == null)
                {
                    LoggerBase.Log("Error! Unable to find '" + dllName + "'", true);
                    // Uncomment the next lines to show message the moment an assembly is not found. (This will also stop for .Net assemblies
                    //MessageBox.Show("Error! Unable to find '" + dllName + "'! Application will terminate.");
                    //Environment.Exit(0);
                    return null;
                }

                byte[] buffer = new BinaryReader(stream).ReadBytes((int)stream.Length);
                assembly = Assembly.Load(buffer);

                _libs[keyName] = assembly;
                return assembly;
            }
        }
开发者ID:twistedtwig,项目名称:NHibernateRepository,代码行数:52,代码来源:AssemblyLoadingHelper.cs

示例4: FindType

 Type FindType(string name)
 {
     foreach (string use in usings)
     {
         name = (use != "" ? use + "." : "") + name;
         if (name.Contains('.'))
         {
             name += ".";
             int i = 0;
             i = name.IndexOf('.');
             string first = name.Substring(0, i);
             Type t = null;
             while ((t = Type.GetType(name.Substring(0, i))) == null)
             {
                 i = name.IndexOf('.', i + 1);
             }
             return t;
         }
         else
         {
             Type t = Type.GetType(name);
             if (t != null) return t;
         }
     }
     throw new Exception("Type not found: " + name);
 }
开发者ID:Northcode,项目名称:nvm,代码行数:26,代码来源:ILGenerator.cs

示例5: CurrentDomain_AssemblyResolve

 /// <summary>
 /// Resolve local path on HDInsight VM where the ADF .Net activity is running
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     var assemblyname = new AssemblyName(args.Name).Name;
     if (assemblyname.Contains("Microsoft.WindowsAzure.Storage"))
     {
         assemblyname = "Microsoft.WindowsAzure.Storage";
         var assemblyFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), assemblyname + ".dll");
         var assembly = Assembly.LoadFrom(assemblyFileName);
         return assembly;
     }
     return null;
 }
开发者ID:Coderrs,项目名称:Azure-DataFactory,代码行数:18,代码来源:InvokeRScript.cs


注:本文中的System.Reflection.AssemblyName.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。