Last active
March 25, 2018 11:16
-
-
Save MNie/edcdf5b9b8fa9281400752627cff64ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const string ContractPrefix = "App.Contract"; | |
string ImportStatements(Class @class) | |
{ | |
var otherTypesInFile = new List<Type>() | |
.Concat(@class.Methods.Select(x => x.Type)) | |
.Concat(@class.Methods.SelectMany(x => x.Type.TypeArguments)) | |
.Concat(@class.Methods.SelectMany(x => x.Parameters).Select(x => x.Type)) | |
.Concat(@class.Methods.SelectMany(x => x.Parameters).SelectMany(x => x.Type.TypeArguments)) | |
.SelectMany(GetTypes) | |
.ToList(); | |
if (@class.BaseClass != null){ | |
otherTypesInFile.Add(@class.BaseClass); | |
} | |
var imports = otherTypesInFile | |
.Where(t => t.FullName.StartsWith(ContractPrefix)) | |
.Select(t => { | |
return $"import {{ {t.Name} }} from \"../contract/{FileNameFromType(t.FullName)}\";"; | |
}) | |
.Distinct(); | |
return String.Join("\r\n", imports); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment