Exemple #1
0
        public static RootConfig CreateFromAssembly(AssemblyCache cache, string assembly, GenerateContractMode mode, bool internalVisibility)
        {
            RootConfig root = new RootConfig(cache)
            {
                Contracts = new List<ProxyConfig>()
            };

            Assembly loadedAssembly = null;
            if (!string.IsNullOrEmpty(assembly) && File.Exists(assembly))
            {
                root.Assemblies = new List<string> { Path.GetFullPath(assembly) };
                loadedAssembly = cache.Loader.Load(assembly);
            }
            else
            {
                loadedAssembly = cache.HostedAssembly;
            }

            if (loadedAssembly != null)
            {
                foreach (var type in root.AssemblyCache.GetTypes(loadedAssembly))
                {
                    root.AddContract(type.GetTypeInfo(), mode, internalVisibility);
                };
            }

            return root;
        }
Exemple #2
0
        private int AddContracts(RootConfig rootConfig, List<string> contracts, GenerateContractMode mode, bool internalVisibility)
        {
            if (!contracts.Any() || contracts.Any(c => c.EndsWith(".*", StringComparison.OrdinalIgnoreCase)))
            {
                try
                {
                    rootConfig.AddAllContracts(mode, internalVisibility);
                }
                catch (Exception e)
                {
                    return HandleError($"Failed to resolve contracts", e);
                }

                return 0;
            }

            foreach (var contract in contracts)
            {
                if (contract.EndsWith(".*", StringComparison.OrdinalIgnoreCase))
                {
                    var ns = contract.TrimEnd('*', '.');
                    try
                    {
                        rootConfig.AddContractsFromNamespace(ns, mode, internalVisibility);
                    }
                    catch (Exception e)
                    {
                        return HandleError($"Failed to resolve contracts: {contract.White().Bold()}", e);
                    }
                }
                else
                {
                    try
                    {
                        rootConfig.AddContract(contract, mode, internalVisibility);
                    }
                    catch (Exception e)
                    {
                        return HandleError($"Failed to resolve contract: {contract.White().Bold()}", e);
                    }
                }
            }

            return 0;
        }