Home > Net >  For c # function to achieve loose coupling variable input way
For c # function to achieve loose coupling variable input way

Time:09-17

Normal function call is:

 
//define
Function (string a and string b, string c) {... }

//call method1
The function (" haha ", "hehe", "hoho")

//call an this is the way to their support c #
Function (a: "haha," c: "hehe" b: "hoho")


But I want to achieve the following way:

 
String the parm="a:" haha, c: 'hehe' b: 'hoho "
The function (parm)


The parm variable as a string type, the inside of the assignment operation is not limited to the above expression

Such as at the moment, I think it is the most simple

String variable written as "{a: 'haha' c: 'hehe' b: 'hoho'}"

JSON deserialization become objects to preach and

Don't know whether there is a more opportunistic or better solution?

CodePudding user response:

Json is very sweet, but also a dynamic, don't need to write entity class, but the feeling of individual or entity class are easier to understand,

CodePudding user response:

I think, you instead in the tight coupling of the road, more walk more far,,,

CodePudding user response:

refer to the second floor is nu month god reply:
, I think, you instead in the tight coupling of the road, more walk more far,,,


The front-end CSS is background: red;" Border: 1 px black "this

I just want to know in addition to write a lexical analyzer, there is no other feasible methods.

CodePudding user response:

reference raynors reply: 3/f
Quote: refer to the second floor is nu month god reply:

I think, you instead in the tight coupling of the road, more walk more far,,,


The front-end CSS is background: red;" Border: 1 px black "this

I just want to know in addition to write a lexical analyzer, there is no feasible way to.

This and Json is almost no difference,
And many of the front-end frameworks using Json format setting style

CodePudding user response:

Expression

Call XXX. Call (()=& gt; New} {a=1, b=2)

, of course, how to solve the Expression is another thing (not necessary, personally, I don't want to study the Expression, even if occasionally use him, also simply look up data, finished just forget)

Ps: if you just want to string concatenation, above the dynamicobject directly, reflection properties is good, also do not have to with the expression parsing

CodePudding user response:

In fact you this kind of requirement at present there are a lot of things, you can directly use the

A casual baidu "json generated entity" "yaml generated entity object" of course we are in the design phase of the code is generated by the automation tool, but don't want to get the run-time dynamic proxy for run-time dynamic proxy to good, just asked, he must have a unified form of abstraction, similar yaml plug-in, json configuration, webapi submitted, this class will be in the form of the existing unified agreement, so can use dynamic proxy, let the machine agent directly generate uniform conventions

Ps: personally, I don't want to use dynamic proxy there is another reason, difficult to debug, the generated code, the code is there, there is a problem can be adjustable, dynamic proxy out bugs, the pitch is difficult, after all the code at run time, he gave me a generated what, I don't know.

CodePudding user response:

Actually now already has this tendency, many people use XX garden recommended framework, big dynamic proxy and injection

Then we have a problem, to come over to ask? We can't answer, because can't answer this kind of problem,
The proxy class dynamically generated for you, once he does not meet your expectations, we didn't also the way to deal with, after all, the code is generated out of thin air, he is not in line with expectations, we can only answer, to study the inner mechanism of the framework itself, we can do
  •  Tags:  
  • C #
  • Related