Closed ufetahu closed 5 years ago
I've been trying to generate comments using helpers but it's not working
Are you calling services.AddHandlebarsHelpers(myHelper)? Can you show me your ScaffoldingDesignTimeServices
class?
Is there is way to check the property name
Yes, see here.
Hi Anthony,
Thank you for your reply. Attached you will find the ScaffoldingDesignTimeService.cs, DBContext.hbs and the results received from scaffolding in ChronDbContext.cs.
As far as my second question I was thinking whether it’s possible to check the property name within the helper itself, such as:
void MyHbsHelper(TextWriter writer, object context, object[] parameters)
{
foreach (var property in parameters)
{
if(property.ToString() == "CreatedBy")
writer.Write("//");
}
}
And in .hbs file
{{spaces 8}}{{my-helper}}public {{property-type}} {{property-name}} { get; set; }
which would comment out all the auditable/trackable properties inherited from another class.
I appreciate you taking your time.
Regards,
Uran
I can confirm that issue. I had the same problem when trying to include my own helpers. The method AddHandlebarsHelpers does not seem to find the internal collection in order to append the given helper to it. I succeeded by installing the helpers altogether myself by
// Register Handlebars helper
services.AddHandlebarsHelpers(myHelper); // does not work but the following
services.AddSingleton(
provider => (IHbsHelperService)
new HbsHelperService(
new Dictionary<string, Action<TextWriter, object, object[]>>
{
{
"spaces",
HandlebarsHelpers.SpacesHelper
},
{
"MyHelper",
MyHelper
}
}));
I've also tried the sample project and without changing anything, it is not generating the comments in the classes. I tried it with dotnet core sdks 2.1.300, 2.1.400 and 2.2.100-*
Fixed by PR #42. Marked AddHandlebarsHelpers
obsolete and added handlebarsHelpers
parameter to AddHandlebarsScaffolding
.
Fix will be available in v1.7.0 when it is released.
@ufetahu @Vizehase @IulianParaian This has been fixed in v1.7.0.
I've been trying to generate comments using helpers but it's not working (unlike comments added in .hbs like //comment). Its almost like if the Helper method is not being called. Also, if there is way to check the property name within i.e.: if(parameter == "CreatedOn"){ writer.write("//") } Using