Proposals: generics, operators and other #1269
Replies: 25 comments
-
|
Beta Was this translation helpful? Give feedback.
-
The point is that it sometimes could help during debugging to find the source faster without need to use inner exceptions and changing exception type/reference if I don't want it. For example, I'm using it in expressions:
Also sometimes I want to rethrow the exception in another thread what waits some result and no need to check inner exceptions every time that simplifies exception constraints. |
Beta Was this translation helpful? Give feedback.
-
Number 3 is #339 |
Beta Was this translation helpful? Give feedback.
-
You can do 6 with try
{
return someCompiledExpression.DynamicInvoke(item);
}
catch (TargetInvocationException ex)
{
ExceptionDispatchInfo.Capture(ex.InnerException ?? ex).Throw();
} |
Beta Was this translation helpful? Give feedback.
-
@benaadams you often need a dummy return or throw after EDI.Throw, because the compiler doesn’t know that EDI.Throw does not return. |
Beta Was this translation helpful? Give feedback.
-
This is true 😢 |
Beta Was this translation helpful? Give feedback.
-
@benaadams Already did long time ago 😄
Yes, you even can see it in my example. My current implementation works so:
Would be nice to have rethrow operator.. |
Beta Was this translation helpful? Give feedback.
-
@DenisKudelin Thanks for all the passion and enthusiasm here. But for the future, could you please make unique proposals for each suggestion. Having them all be in one issue will effectively make it very difficult to actually keep track of the individual topics. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi ok, I just decided to avoid many duplicates with 2.5 lines description, if some ideas are good, I could create separate proposals. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@Joe4evr please, read comments above. |
Beta Was this translation helpful? Give feedback.
-
class Foo<T, U>
{
public bool Test() => true;
public T GenericFoo() => default(T);
public void GenericFoo(T value) { }
}
object obj = new Foo<int>();
((Foo<,>)obj).Test(); //GenericFoo methods of class Foo<,> should not be available in this case.
Foo<,> foo = (Foo<,>)obj;
((Foo<int,byte>)foo).GenericFoo() In the provided example, it is not clear what Also, and I'm admittedly nitpicking, the terminology is not correct. Specifically, there are no generic methods in the example. |
Beta Was this translation helpful? Give feedback.
-
There is no type leakage, in the same way that it could implement interface |
Beta Was this translation helpful? Give feedback.
-
@DenisKudelin Could you explain what you expect this to do? class Foo<T<U>> |
Beta Was this translation helpful? Give feedback.
-
We can use any generic class with one parameter as the generic parameter of new Foo<Predicate<byte[]>>() I've come across enough cases where I actually need it (as well as numbers 1 and 7) |
Beta Was this translation helpful? Give feedback.
-
I too can think of situations where interface IBar<T>{}
class Foo<T, U> where T : IBar<U> {} and then have every type that I'm going to use as IFuncWithHandler<IFuncMatcher<T1, T2, T3, T4, TResult>, T1, T2, T3, T4, TResult> could be simplified to: IFuncWithHandler<T<T1, T2, T3, T4, TResult>> using this idea. |
Beta Was this translation helpful? Give feedback.
-
I don't see how I think that issues like this are better solved through better generic inference, where the compiler could infer public void Foo<T, U>(T input) where T : IEnumerable<U> { ... }
List<Person> people = ...;
Foo(people); // infers T to List<Person> and U to Person |
Beta Was this translation helpful? Give feedback.
-
The And, this issue isn't better solved through better generic inference, as my example sort to show. Such generic inference would save having to casting in some situations, but it doesn't address avoiding duplication parameters. |
Beta Was this translation helpful? Give feedback.
-
Which, as I'm sure you're aware, isn't a constraint supported by the CLR. Nor is it one that makes sense, because that generic parameter arity doesn't mean anything enforceable. You'd still need additional constraints to actually declare the relationship between |
Beta Was this translation helpful? Give feedback.
-
I'll take your word for it. I know that C#'s generic constraints are frustratingly limited, but I've never looked into whether that's a language, or runtime, limitation. |
Beta Was this translation helpful? Give feedback.
-
They are runtime limitations. IIRC, the only CLR constraints not supported by C# are But even if such a constraint could be added to the CLR/language, what would it mean? Of what practical benefit is a |
Beta Was this translation helpful? Give feedback.
-
@HaloFour the benefit is obvious when you need to have both For example, you can have With higher-kinded types, you would be able to CRTP around that: public interface ISelectable<S<T>> where S: ISelectable<S<>>
{
S<U> Select<U>(Func<T,U> func);
}
public class MyList<T>: ISelectable<MyList<T>>
{
MyList<U> Select<U>(Func<T, U> func) => ...
} |
Beta Was this translation helpful? Give feedback.
-
Doesn't that become a constraint on |
Beta Was this translation helpful? Give feedback.
-
@HaloFour what doesn't become a constraint on And yes, implementing this at the CLR level would require changes not seen since .Net 2.0. |
Beta Was this translation helpful? Give feedback.
-
No, the fact that public static T<A> To<T, A>(this IEnumerable<A> xs)
where T : <>, new(), ICollection<> { ... } |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
deleted
Beta Was this translation helpful? Give feedback.
All reactions