You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to implement the code below because I thought it would be straight forward to do. Basically I had some means where by for each type I could generate meaningful property values (the implementation details are not important).
The problem is, that no matter how hard I try AddSwaggerExamplesFromAssemblyOf() would try to include the AutoExample class (many instances Like AutoExample<string>, AutoExample<SomethingElse>, etc..). This happens even though the class is private.
Maybe the methodology should be it should ignore private/protected classes, classes that have generic type parameters, or classes with a certain attribute? Or maybe there is an easier way for what I'm trying to do?
publicstaticclassAutoExampleExtensions{// please skip me AddSwaggerExamplesFromAssemblyOf!privateclassAutoExample<T>:IExamplesProvider<T>{publicTGetExamples(){/** **/}}publicstaticIServiceCollectionAddAutoExamples(thisIServiceCollectionservices,paramsType[]types){foreach(Typetypeintypes){TypeexampleType=typeof(AutoExample<>).MakeGenericType(type);objectexample=Activator.CreateInstance(exampleType)!;services.AddSingleton(exampleType.GetInterfaces().First(x =>typeof(IExamplesProvider<>)==x.GetGenericTypeDefinition()),example);}returnservices;}}
The text was updated successfully, but these errors were encountered:
I was trying to implement the code below because I thought it would be straight forward to do. Basically I had some means where by for each type I could generate meaningful property values (the implementation details are not important).
The problem is, that no matter how hard I try
AddSwaggerExamplesFromAssemblyOf()
would try to include the AutoExample class (many instances Like AutoExample<string>, AutoExample<SomethingElse>, etc..). This happens even though the class is private.Maybe the methodology should be it should ignore private/protected classes, classes that have generic type parameters, or classes with a certain attribute? Or maybe there is an easier way for what I'm trying to do?
The text was updated successfully, but these errors were encountered: