Skip to content

Instantly share code, notes, and snippets.

@MNie
Last active March 25, 2018 11:16
Show Gist options
  • Save MNie/edcdf5b9b8fa9281400752627cff64ae to your computer and use it in GitHub Desktop.
Save MNie/edcdf5b9b8fa9281400752627cff64ae to your computer and use it in GitHub Desktop.
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