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


C# IRuntime.Log方法代码示例

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


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

示例1: TryLoadTypes

        private bool TryLoadTypes(string filePath, int lineNumber, string assemblyNameAndNamespaceReference, IRuntime runtime, out Type[] types)
        {
            if (string.IsNullOrWhiteSpace(assemblyNameAndNamespaceReference))
            {
                types = new Type[0];
                return true;
            }

            try
            {
                runtime.Log("Parsing " + assemblyNameAndNamespaceReference);
                var parts = Regex.Split(assemblyNameAndNamespaceReference, "::");
                if (parts.Length != 2)
                {
                    var error = string.Format("Unrecognised format: use AssemblyName::Namespace) in '{0}'", assemblyNameAndNamespaceReference);
                    runtime.ErrorInFile(filePath, lineNumber, error);
                    System.Environment.Exit(-1);
                }

                var assemblyName = parts[0];
                var namespaceName = parts[1];
                var assembly = assemblyLoader.Load(assemblyName);

                runtime.Log(string.Format("Generating from assembly {0}, namespace {1}", assemblyName, namespaceName ));

                types = assembly
                    .GetTypes()
                    .Where(TypeExtensions.IsExportableType)
                    .Where(t => t.Namespace.StartsWith(namespaceName))
                    .ToArray();

                runtime.Log("Loaded " + types.Length.ToString() + " types");

                return true;
            }
            catch (ReflectionTypeLoadException ex)
            {
                runtime.Error(ex.ToString());
                foreach (var loaderException in ex.LoaderExceptions)
                {
                    runtime.Error(loaderException.ToString());
                }

                types = new Type[0];
                return false;
            }
            catch (Exception ex)
            {
                runtime.Error(ex.ToString());
                types = new Type[0];
                return false;
            }
        }
开发者ID:spelltwister,项目名称:TypeWalker,代码行数:53,代码来源:FileGenerator.cs

示例2: TryGenerate

        public bool TryGenerate(string filePath, string[] assemblyNames, IRuntime runtime, LanguageGenerator[] generators, out string result)
        {
            try
            {
                bool loadFailed = false;
                List<Type> allTypes = new List<Type>();
                int lineNumber = 0;
                foreach (var assemblyName in assemblyNames)
                {
                    lineNumber++;
                    Type[] types;
                    if (TryLoadTypes(filePath, lineNumber, assemblyName, runtime, out types))
                    {
                        allTypes.AddRange(types);
                    }
                    else
                    {
                        loadFailed = true;
                        break;
                    }
                }

                runtime.Log("Loaded a a total of " + allTypes.Count + " types.");

                var sb = new StringBuilder();

                var exports = KnockoutGeneratorFactory.Create(allTypes);

                foreach (var g in exports.Dtos)
                {
                    sb.AppendLine($"declare module {g.Key} {{");
                    foreach (var d in g)
                    {
                        sb.AppendLine(d);
                    }
                    sb.AppendLine("}");
                }

                foreach (var g in exports.Controllers)
                {
                    sb.AppendLine($"declare module {g.Key} {{");
                    foreach (var d in g)
                    {
                        sb.AppendLine(d);
                    }
                    sb.AppendLine("}");
                }

                result = sb.ToString();
                return !loadFailed;

                foreach (var generator in generators)
                {
                    var thisResult = generator.Generate(allTypes);
                    sb.Append(thisResult).AppendLine();
                }

                result = sb.ToString();
                return !loadFailed;
            }
            catch
            {
                result = null;
                return false;
            }
        }
开发者ID:spelltwister,项目名称:TypeWalker,代码行数:66,代码来源:FileGenerator.cs


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