generics

Amazon API Gateway Import From Swagger Error - Not taking Generics

随声附和 提交于 2021-02-07 14:22:44
问题 I'm trying to create new APIGateway via import from Swagger, but having validation errors: The particular class causing the issue is our PaginationModel class. Code model definition: public class PaginationModel<T> { public IEnumerable<T> items { get; set; } public int offset { get; set; } public int totalCount { get; set; } } Swagger file section representing Generic PaginationModel for a particular type: *"PaginationModel[DepartmentUIModel]":{"type":"object","properties":{"items": {"type":

Amazon API Gateway Import From Swagger Error - Not taking Generics

人盡茶涼 提交于 2021-02-07 14:21:35
问题 I'm trying to create new APIGateway via import from Swagger, but having validation errors: The particular class causing the issue is our PaginationModel class. Code model definition: public class PaginationModel<T> { public IEnumerable<T> items { get; set; } public int offset { get; set; } public int totalCount { get; set; } } Swagger file section representing Generic PaginationModel for a particular type: *"PaginationModel[DepartmentUIModel]":{"type":"object","properties":{"items": {"type":

List of generic delegates (e.g. System.Converter<TInput, TOutput>)

社会主义新天地 提交于 2021-02-07 14:18:23
问题 Is it possible to create a list of generic delegates, like System.Converter<TInput, TOutput> ? In java that could be List<Converter<?,?>> , but with Java's type erasure that's not very useful. Seems like in C# it should be possible to query the generic types after retrieval from the list and use the obtained instance to perform the desired conversion. Elaborating on the question: I have user supplied data in user provided formats which I know nothing about at compile time. Algorithms in my

Is it possible to detect class context in an inherited static method?

廉价感情. 提交于 2021-02-07 13:59:53
问题 OK, that title is a little unclear, but I can't think of a better way of putting it, other than explaining it... Say I have a class Animal , with a static, generic method: public static T Create<T>() where T : Animal { // stuff to create, initialize and return an animal of type T } And I have subclasses Dog , Cat , Hamster etc. In order to get a Dog , I can write: Dog d = Animal.Create<Dog>(); or Dog d = Dog.Create<Dog>(); which is really the same thing. But it seems kinda silly to have to

Is it possible to detect class context in an inherited static method?

我怕爱的太早我们不能终老 提交于 2021-02-07 13:58:16
问题 OK, that title is a little unclear, but I can't think of a better way of putting it, other than explaining it... Say I have a class Animal , with a static, generic method: public static T Create<T>() where T : Animal { // stuff to create, initialize and return an animal of type T } And I have subclasses Dog , Cat , Hamster etc. In order to get a Dog , I can write: Dog d = Animal.Create<Dog>(); or Dog d = Dog.Create<Dog>(); which is really the same thing. But it seems kinda silly to have to

How can I Build a Generic Method in c# to Query a Partition in a Given Azure Table

ぃ、小莉子 提交于 2021-02-07 13:52:12
问题 I'm trying to build a generic method to return entries in a partition in a given Azure table. This is how it looks: public class Table : ITable { private CloudStorageAccount storageAccount; public Table() { var storageAccountSettings = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString(); storageAccount = CloudStorageAccount.Parse(storageAccountSettings); } public async Task<IEnumerable<T>> RetrieveAllInPartition<T>(string tableReference, string partitionKey) where T :

How to make one generic type closely dependent on another in TypeScript?

丶灬走出姿态 提交于 2021-02-07 13:31:46
问题 I'm looking for a way to make my code more type-safe and would like to define a close relationship between some of my types when passing them to generic functions. For example, for the given set of types: interface FooParam {} interface FooReturn {} interface BarParam {} interface BarReturn {} and the following function: function action<T, R>(foo: T): R I'd like to closely bind FooParam with FooReturn , and BarParam with BarReturn , so the compiler allows the call only if a pair of associated

How to make one generic type closely dependent on another in TypeScript?

别等时光非礼了梦想. 提交于 2021-02-07 13:26:18
问题 I'm looking for a way to make my code more type-safe and would like to define a close relationship between some of my types when passing them to generic functions. For example, for the given set of types: interface FooParam {} interface FooReturn {} interface BarParam {} interface BarReturn {} and the following function: function action<T, R>(foo: T): R I'd like to closely bind FooParam with FooReturn , and BarParam with BarReturn , so the compiler allows the call only if a pair of associated

How to explain this “call is ambiguous” error?

半世苍凉 提交于 2021-02-07 13:14:51
问题 The Problem Consider these two extension methods which are just a simple map from any type T1 to T2 , plus an overload to fluently map over Task<T> : public static class Ext { public static T2 Map<T1, T2>(this T1 x, Func<T1, T2> f) => f(x); public static async Task<T2> Map<T1, T2>(this Task<T1> x, Func<T1, T2> f) => (await x).Map(f); } Now, when I use the second overload with a mapping to a reference type... var a = Task .FromResult("foo") .Map(x => $"hello {x}"); // ERROR var b = Task

Specify that an interface can only be implemented by reference types C#

橙三吉。 提交于 2021-02-07 12:31:10
问题 If I declare an interface in C#, is there any way I can explicitly declare that any type implementing that interface is a reference type? The reason I want to do this is so that wherever I use the interface as a type parameter, I don't have to specify that the implementing type also has to be a reference type. Example of what I want to accomplish: public interface IInterface { void A(); int B { get; } } public class UsingType<T> where T : IInterface { public void DoSomething(T input) {