public void GenerateAndStore(SpyGenInfo info) { var ret = new StringBuilder(); AppendHeader(ret, info); AppendProps(ret, info.MethodInfos.OfType <PropInfo>().ToList()); AppendMethods(ret, info.MethodInfos.OfType <MethodInfo>().ToList()); AppendFooter(ret); var path = $"{_destDir}\\{info.FileName}.cs"; MemoryDiskHelper.CreateTextFileForce(path, ret.ToString()); }
private void AppendHeader(StringBuilder ret, SpyGenInfo i) { foreach (var uzing in i.Usings) { ret.Append($"using {uzing};\r\n"); } ret.Append($@" using Pendar.CommonTest.SpyFramework; namespace {_spiedNs} {{ public class {i.SpyGenericName} : BaseSpy, {i.InterfaceList.AggregateToString(",")}{i.GenericConstraints} {{ "); }
private SpyGenInfo Exctract(GenInfo g) { _usingManager.Init(g); var ret = new SpyGenInfo { SpyGenericName = g.SpyGenericName, InterfaceList = g.InterfaceList.Except(g.InterfaceList.SelectMany(i => i.GetInterfaces())).Select(ReflectionHelper.TypeGenericName).ToList(), GenericConstraints = _genericManager.GetTypeConstraints(g.Concrete), FileName = ExtractorMethods.SpyFileName(g), MethodInfos = new List <IMemberInfo>() }; foreach (var @interface in g.InterfaceList) { var n = @interface.TypeGenericName(); ret.MethodInfos.AddRange(ProcessInterface(@interface, n)); } ret.Usings = _usingManager.Result; return(ret); }