public ProxyExtraction ExtractAssembly(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } var types = assembly.GetTypes(); ProxyExtraction extraction = new ProxyExtraction(); extraction.SourceAssembly = assembly.FullName; extraction.TypeExtractions = new List <TypeExtraction>(); foreach (var type in types) { ExtractFromType(type, extraction); } extraction.Timestamp = DateTime.Now; return(extraction); }
private void ExtractFromType(Type type, ProxyExtraction extraction) { var name = type.Name; if (type.IsGenericType) { int pos = name.IndexOf("`"); name = $"{type.Name.Substring(0, pos)}<T>"; } TypeExtraction typExtracted = new TypeExtraction() { Name = name, Namespace = type.Namespace, Fields = new List <FieldExtraction>(), Properties = new List <PropertyExtraction>(), Methods = new List <MethodExtraction>() }; foreach (var fieldInfo in type.GetFields()) { ExtractFromField(fieldInfo, typExtracted); } foreach (var propertyInfo in type.GetProperties()) { ExtractFromProperty(propertyInfo, typExtracted); } foreach (var methodInfo in type.GetMethods()) { ExtractFromMethod(methodInfo, typExtracted); } extraction.TypeExtractions.Add(typExtracted); }
public IList <string> FormatProxyExtraction(ProxyExtraction extraction) { List <string> formattedList = new List <string>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("#region Header"); sb.AppendLine($"/*"); sb.AppendLine($"+------------------------------------------------------------------------------+"); sb.AppendLine(MakeCommentLine("|- ", $"Proxy generated from: {extraction.SourceAssembly}", "-|", 80)); sb.AppendLine($"|- Proxy generated on: {extraction.Timestamp}"); sb.AppendLine($"+------------------------------------------------------------------------------+"); sb.AppendLine($"*/"); sb.AppendLine("#endregion\n"); foreach (var typeExtraction in extraction.TypeExtractions) { var typeContent = FormatExtractedType(sb.ToString(), typeExtraction); formattedList.Add(typeContent); } return(formattedList); }