I am working on a method that takes an expression tree as a parameter along with the type (or instance) of a class.
The basic idea is that this method will add certain things to the collection that will be used for validation.
public interface ITestInterface { //Specify stuff here. } private static void DoSomething<T>(Expression<Func<T, object>> expression, params IMyInterface[] rule) { // Stuff is done here. }
The method is called as follows:
class TestClass { public int MyProperty { get; set; } } class OtherTestClass : ITestInterface { // Blah Blah Blah. } static void Main(string[] args) { DoSomething<TestClass>(t => t.MyProperty, new OtherTestClass()); }
I do it this way because I would like the names of the properties that were passed to be strong.
A few things I struggle with.
PropertyInfo
!
, expression.Body.ToString() DoSomething, , "Convert (t.MyProperty)", .
expression.Body.ToString()
, , , .
PropertyInfo Expression.Body .
, , , , .
, - , " ".
, , - , URL- MVC, -, , ... URL-. URL- , . , , , . , .
, , , , , , . , , .
-, , - (, , ) tress JavaScript. , JavaScript, .
, , , , , , - , , . , - .
, .
System.Reflection.Emit , , , , . , .
, , - - , , . , !
, . . :
DoSomething("MyProperty", new OtherClass());
- , . , , - , , , . , . "DoSomething".
, , - , , .
[DoSomething(typeof(OtherClass), typeof(OtherClass2))] public int MyProperty { get; set; }
(, ?) OtherClass OtherClass2 .
Source: https://habr.com/ru/post/1697755/More articles:Does Oracle have something like changing data collection in SQL Server 2008? - oracleFIPS-compatible password encryption for .NET. - securityColdFusion: select the first nonzero value from the list - idiomsExtending chart functionality in SSRS - visual-studioA quick way to find a specific string (or byte array) in another process memory in C #? - c #VB.Net MessageBox.Show() перемещает мою форму обратно - vb.nethttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1697757/how-can-you-limit-a-tfs-check-in-notes-to-a-custom-path&usg=ALkJrhgFmBW68iY6aPdaO9d_e45fVVzF3gSort ADO records text field as numeric - vbaSilverlight 2.0 DataGrid How to remove mouse effect - silverlight-2.0Is there a standard encoding for REQUIRED ELF entries? - binaryAll Articles