コード例 #1
0
        private Assembly CreateAssembly()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();
            var interfaceNames    = executingAssembly
                                    .GetTypes()
                                    .Select(x => x.GetComInterfaceNameIfWrapper())
                                    .Where(x => x != null)
                                    .ToArray();
            var iids           = IID.GetIIDs(interfaceNames);
            var compileTargets = new List <string>();

            {
                var assemblyInfo = executingAssembly.GetManifestResourceNames().Single(x => x.Contains("AssemblyInfo"));
                var stream       = executingAssembly.GetManifestResourceStream(assemblyInfo);
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        var sourceCode = reader.ReadToEnd().Replace("{VERSION}", ProductInfo.OSBuild.ToString());
                        compileTargets.Add(sourceCode);
                    }
                }
            }

            foreach (var name in executingAssembly.GetManifestResourceNames())
            {
                var typeName = Path.GetFileNameWithoutExtension(name)?.Split('.').LastOrDefault();
                if (typeName == null)
                {
                    continue;
                }

                var interfaceName = interfaceNames.FirstOrDefault(x => typeName == x);
                if (interfaceName == null)
                {
                    continue;
                }

                var stream = executingAssembly.GetManifestResourceStream(name);
                if (stream == null)
                {
                    continue;
                }

                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    var sourceCode = reader.ReadToEnd().Replace(_placeholderGuid, iids[interfaceName].ToString());
                    compileTargets.Add(sourceCode);
                }
            }

            return(this.Compile(compileTargets.ToArray()));
        }
コード例 #2
0
        private Assembly CreateAssembly()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();
            var interfaceVersion  = _interfaceVersions
                                    .Reverse()
                                    .First(build => build <= ProductInfo.OSBuild);
            var interfaceNames = executingAssembly
                                 .GetTypes()
                                 .SelectMany(x => x.GetComInterfaceNamesIfWrapper(interfaceVersion))
                                 .Where(x => x != null)
                                 .ToArray();
            var iids           = IID.GetIIDs(interfaceNames);
            var compileTargets = new List <string>();

            {
                var assemblyInfo = executingAssembly.GetManifestResourceNames().Single(x => x.Contains("AssemblyInfo"));
                var stream       = executingAssembly.GetManifestResourceStream(assemblyInfo);
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        var sourceCode = reader.ReadToEnd()
                                         .Replace("{VERSION}", ProductInfo.OSBuild.ToString())
                                         .Replace("{BUILD}", interfaceVersion.ToString());
                        compileTargets.Add(sourceCode);
                    }
                }
            }

            foreach (var name in executingAssembly.GetManifestResourceNames())
            {
                var texts    = Path.GetFileNameWithoutExtension(name)?.Split('.');
                var typeName = texts.LastOrDefault();
                if (typeName == null)
                {
                    continue;
                }

                if (int.TryParse(string.Concat(texts[texts.Length - 2].Skip(1)), out var build) && build != interfaceVersion)
                {
                    continue;
                }

                var interfaceName = interfaceNames.FirstOrDefault(x => typeName == x);
                if (interfaceName == null)
                {
                    continue;
                }
                if (!iids.ContainsKey(interfaceName))
                {
                    continue;
                }

                var stream = executingAssembly.GetManifestResourceStream(name);
                if (stream == null)
                {
                    continue;
                }

                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    var sourceCode = reader.ReadToEnd().Replace(_placeholderGuid, iids[interfaceName].ToString());
                    compileTargets.Add(sourceCode);
                }
            }

            return(this.Compile(compileTargets.ToArray()));
        }