forked from loafle/openapi-generator-original
		
	[C#][netcore] Call static method without creating instance (#8889)
* call static method without creating instance * fix instance * fix missing equal sign * skip instance creation * cast to T * update httpclient apiclient.mustache
This commit is contained in:
		
							parent
							
								
									041d908963
								
							
						
					
					
						commit
						51a19e1c27
					
				@ -482,10 +482,7 @@ namespace {{packageName}}.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -602,10 +599,7 @@ namespace {{packageName}}.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -453,10 +453,7 @@ namespace {{packageName}}.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T) Activator.CreateInstance(typeof(T));
 | 
					                responseData = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] {response.Content});
 | 
					 | 
				
			||||||
                responseData = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -431,10 +431,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T) Activator.CreateInstance(typeof(T));
 | 
					                responseData = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] {response.Content});
 | 
					 | 
				
			||||||
                responseData = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -482,10 +482,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -597,10 +594,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -482,10 +482,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -597,10 +594,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -481,10 +481,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -596,10 +593,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -482,10 +482,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -597,10 +594,7 @@ namespace Org.OpenAPITools.Client
 | 
				
			|||||||
            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
					            // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
 | 
				
			||||||
            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
					            if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                T instance = (T)Activator.CreateInstance(typeof(T));
 | 
					                response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
 | 
				
			||||||
                MethodInfo method = typeof(T).GetMethod("FromJson");
 | 
					 | 
				
			||||||
                method.Invoke(instance, new object[] { response.Content });
 | 
					 | 
				
			||||||
                response.Data = instance;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (typeof(T).Name == "Stream") // for binary response
 | 
					            else if (typeof(T).Name == "Stream") // for binary response
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user