public TypeWriterBase(TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, ConfigBase config) { this.TypeDefinition = typeDefinition; this.IndentCount = indentCount; this.TypeCollection = typeCollection; this.Config = config; }
public void Collect(Mono.Cecil.TypeDefinition td, TypeCollection typeCollection, ConfigBase config) { if (td.ShouldIgnoreType()) { return; } // don't duplicate types if (typeCollection.Contains(td.FullName)) { return; } StringBuilder sb = new StringBuilder(); var indentCount = 0; ITypeWriter typeWriter = typeSelector.PickTypeWriter(td, indentCount, typeCollection, config); td.Interfaces.Each(item => { var foundType = typeCollection.LookupType(item); if (foundType == null) { //TODO: This reporting a missing type is too early in the process. // typeNotFoundErrorHandler.Handle(item); return; } var itemWriter = typeSelector.PickTypeWriter(foundType, indentCount, typeCollection, config); typeCollection.Add(foundType.Namespace, foundType.Name, itemWriter); }); typeCollection.Add(td.Namespace, td.Name, typeWriter); }
public ITypeWriter PickTypeWriter(Mono.Cecil.TypeDefinition td, int indentCount, TypeCollection typeCollection, ConfigBase config) { if (td.IsEnum) { return new EnumWriter(td, indentCount, typeCollection, config); } if (td.IsInterface) { return new InterfaceWriter(td, indentCount, typeCollection, config); } if (td.IsClass) { if (td.BaseType.FullName == "System.MulticastDelegate" || td.BaseType.FullName == "System.Delegate") { return new DelegateWriter(td, indentCount, typeCollection, config); } return new ClassWriter(td, indentCount, typeCollection, config); } throw new NotImplementedException("Could not get a type to generate for:" + td.FullName); }
public void Collect(IEnumerable<Mono.Cecil.TypeDefinition> tds, TypeCollection typeCollection, ConfigBase config) { foreach (var item in tds) { Collect(item, typeCollection, config); } }
public void Collect(IEnumerable <Mono.Cecil.TypeDefinition> tds, TypeCollection typeCollection, ConfigBase config) { foreach (var item in tds) { Collect(item, typeCollection, config); } }
public static bool AllAssemblies(ConfigBase config, TextWriter w) { w.Write(GetHeader(config.AssemblyPaths, config.IncludeSpecialTypes)); var typeCollection = new TypeCollection(config.GetTypeWriterTypeSelector()); var wroteAnyTypes = WriteSpecialTypes(config.IncludeSpecialTypes, w, config); wroteAnyTypes |= WriteFiles(config.AssemblyPaths, w, config.TypeNotFoundErrorHandler, typeCollection, config.RegexFilter, config); return wroteAnyTypes; }
public static string ToTypeScript(this IEnumerable<TypeDefinition> value, string filterRegex = null) { var typeCollection = new TypeCollection(new WinMDTypeWriterTypeSelector()); var errors = new StringBuilderTypeNotFoundErrorHandler(); var config = new WinmdConfig(); new TypeWriterCollector(errors, typeCollection.TypeSelector) .Collect(value, typeCollection, config); var result = typeCollection.Render(filterRegex); var errorResult = errors.ToString(); if (string.IsNullOrEmpty(errorResult)) { return result; } return errorResult + Environment.NewLine + Environment.NewLine + result; }
private static bool WriteFiles(IEnumerable<string> assemblyPaths, TextWriter w, ITypeNotFoundErrorHandler typeNotFoundErrorHandler, TypeCollection typeCollection, string filterRegex, ConfigBase config) { var filesAlreadyProcessed = new HashSet<string>(new IgnoreCaseStringEqualityComparer()); if (!assemblyPaths.Any()) return false; assemblyPaths.Each(assemblyPath => { if (filesAlreadyProcessed.Contains(assemblyPath)) return; filesAlreadyProcessed.Add(assemblyPath); CollectTypes(assemblyPath, typeNotFoundErrorHandler, typeCollection, config); }); var renderedOut = typeCollection.Render(filterRegex); w.WriteLine(renderedOut); return true; }
public ITypeWriter PickTypeWriter(Mono.Cecil.TypeDefinition td, int indentCount, TypeCollection typeCollection, ConfigBase config) { var castedConfig = (DotNetConfig)config; if (td.IsEnum) { return new EnumWriter(td, indentCount, typeCollection, config); } if (td.IsInterface) { return new InterfaceWriter(td, indentCount, typeCollection, castedConfig); } if (td.IsClass) { return new ClassWriter(td, indentCount, typeCollection, castedConfig); } throw new NotImplementedException("Could not get a type to generate for:" + td.FullName); }
public static string FullAssembly(string assemblyPath, TypeCollection typeCollection, ConfigBase config) { CollectTypes(assemblyPath, config.TypeNotFoundErrorHandler, typeCollection, config); return GetHeader(new[] { assemblyPath }, config.IncludeSpecialTypes) + typeCollection.Render(config.RegexFilter); }
private static void CollectTypes(string assemblyPath, ITypeNotFoundErrorHandler typeNotFoundErrorHandler, TypeCollection typeCollection, ConfigBase config) { var assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly(assemblyPath); typeCollection.AddAssembly(assembly); var typeWriterGenerator = new TypeWriterCollector(typeNotFoundErrorHandler, typeCollection.TypeSelector); foreach (var item in assembly.MainModule.Types) { typeWriterGenerator.Collect(item, typeCollection, config); } }
public EnumWriter(TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, ConfigBase config) { this.config = config; this.TypeDefinition = typeDefinition; this.IndentCount = indentCount; }
public DelegateWriter(Mono.Cecil.TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, ConfigBase config) : base(typeDefinition, indentCount, typeCollection, config) { }
public ClassWriter(Mono.Cecil.TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, DotNetConfig config) : base(typeDefinition, indentCount, typeCollection, config) { }