Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sort-of macro substitution but setting values
Message
De
20/08/2014 08:23:23
 
 
À
19/08/2014 16:48:46
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01606086
Message ID:
01606117
Vues:
68
>>I'm not calling a function, method, or external program using macro substitution but setting values. What I do in vfp is this:
>>
>>myfunction(mytable,setmyvalues)
>>
>>and I would pass something like this: myfunction('nametable",lcCommandToRun)
>>
>>so what would get passed is:
>>
>>myfunction('nametable","m.pkeyfield='RKS'+m.pkey2field")
>>
>>then myfunction:
>>
>>function myfunction
>>lparameters tctable, tcreplacemacro
>>select (tctable)
>>scan
>>   scatter memvar memo
>>   &tcreplacemacro
>>   gather memvar memo
>>endscan
>>
>>would scan the table, replace the pkeyfield column in the nametable with 'RMKS' plus the value in the pkey2field column and then return
>>
>>so in .net, I have an entity with properties: nameentity.pkeyfield or vehicleentity.pvkeyfield etc. the entity and property change
>>
>>I want to call a method that I can pass the entity name and property name and then how to determine the new value like:
>>
>>myfunction(nameBusinessResult, 'nameEntity.pkfield",'RKS'+'nameEntity.pk2field'")
>>or even
>>myfunction(nameBusinessResult,'nameEntity','pkfield',"RKS","nameEntity","pk2field")
>>etc
>>someway to pass the entity name, the property name to have the value changed, the way to get the new value (one of its properties plus a string), etc.
>>
>>so that in .net, we step through the entities passed and for each one, set the pkfield property value to 'RKS' plus that entity's pkf2field property value.
>>
>>
>>foreach ([type of passedEntity] pEntity in BR.Entities)
>>{
>>
>>  \\determine property value based on entity property name passed and whatever substitution rule is passed
>>
>>
>>only passedEntity would need to know what entity it is....
>>
>>there must be a way to do this in .net?
>>
>>it is macro substitution, but how???
>>
>>The "myfunction" function in vfp is called literally HUNDREDS of times in different prgs and so I would like to have the same utility class in .net instead of having to do the replacements, etc in each caller.
>>
>>I have been stumped on this one....
>>Any ideas?
>>THANKS!!!!!
>
>You could try something like this:
>
>public class MyClass
>{
>	public static void MyFunction< TEntityType>(IEnumerable< TEntityType> entityList, Action< TEntityType> replacementFunction)
>	{
>		foreach(TEntityType currentEntity in entityList)
>			replacementFunction(currentEntity);
>	}
>}
>
>
>And call it like so:
>
>MyClass.MyFunction(nameBusinessResult, currentEntity => currentEntity.pkeyfield = "RKS" + currentEntity.pk2field);
>
>
>See http://msdn.microsoft.com/en-us/library/0x6a29h6.aspx and http://msdn.microsoft.com/en-us/library/bb397687.aspx

This is very cool. Thank you so much -- I will give it a try!!!
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform