Where I can find AssociatedMetadataProvider in .Net Core? Or is there a way to implement GetTypeDescriptor in DefaultModelMetadataProvider?
In MVC 5 the DataAnnotationsModelMetadataProvider inherits from AssociatedMetadataProvider which had a method GetTypeDescriptor.
It seems this class (AssociatedMetadataProvider ) was completly removed :-(
Any advice would be very nice.
How I did it in Mvc 5 ?
public class CustomMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ICustomTypeDescriptor GetTypeDescriptor(Type type)
{
if (WhatEver)
{ return new MyICustomTypeDescriptor();}
return base.GetTypeDescriptor(type);
}
}
Registration:
Global.asax
ModelMetadataProviders.Current = new CustomMetadataProvider();
Indeed, there is no
AssociatedMetadataProviderin .Net Core. However, they left usIModelMetadataProviderwith abstract classModelMetadataProviderthat you might use, especially if you need to override some of the methods. You might also notice there is an implementation providedDefaultModelMetadataProviderthat has a methodGetMetadataForType(Type). It will returnModelMetadatathat is still not what you need. But this class has a method calledGetModelExplorerForType()and it returns an instance ofModelExplorer. This instance should have all the information you need in a bit different format.I hope it helps :)