Replies: 2 comments 6 replies
-
#7967 and others |
Beta Was this translation helpful? Give feedback.
-
Proposal: Enhancing Anonymous Types and Dynamic Objects with Metaprogramming in C# //example 1
class Class1{
public dynamic field1 where IEnumerable<{Prop1:int,Prop2:string /*...*/}> ;
//... some one method:
void M1(){
//...
this.field1 = from i in EntitySet1 join j in EntitySet2 on ... select new {...} ;
//...
}
//...
}
//example 2
dynamic x where {Prop1:int,Prop2:string,Method1->void} = somePerameter;
//or
dynamic x where {Prop1:int,Prop2:string,Method1->void} = default;
//example 3
void M(dynamic p1) where p1:{Prop1:int,Method1->string} { /*... */}
//example 4
dynamic interface IInterface1{
int Property1;
string Property2;
ref Entity1.Property1;
ref Entity2.Property1;
ref Entity3.Method1;
void M();
string M2(int id);
//...
} would constrain the dynamic object to have properties matching Entity1, Entity2, or a specific structure. |
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.
-
Because C # is not like JavaScript, as it is strongly typed, performance is prioritized and dynamic features are not easily added. Referring to TS's metaprogramming, its role is only limited to providing a friendly prompt to developers when editing. Originally, C # could also have these features because they are erased after compilation, such as in code like this:
dynamic x where IA|IB|IC = somePerameter;
This kind of thing allows x to enjoy the intelligent perception provided by where constraints, making the code easier to read and write; At the same time, it is completely erased after being compiled into plain C # code; Because it does not affect the original usage rules at all.Beta Was this translation helpful? Give feedback.
All reactions