sam. 01 novembre 2008, 17h12
Gregory
atoutfox.public.association
Re: .Net et macrosubstitution
Olivier,
Cette idee de macrosubstitution en est une mauvaise
(1) C'est lent - tres lent
(2) ne pourrais-tu pas les stocker comme un tableau ou autre ?
> for (int i = 1; i <= 10; i++)
> {
> // (oBoStat)("oBO.CP"+i.toString())=i
if( !oBO.TrySetProperty("CP"+i.toString()), i) )
; // erreur
> }
public static class ExtensionMethodsGeneric
{
#region TrySetProperty
const BindingFlags BindingFlagsProperty =
BindingFlags.Instance
| BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.SetField;
public static bool TrySetProperty<TOBJECT>(this TOBJECT parent, string
name, object value)
{
FieldInfo fieldInfo = parent.GetType().GetField(name,
BindingFlagsProperty);
if (fieldInfo == null)
return false;
// set the value
try
{
fieldInfo.SetValue((object) parent, value);
return true ;
}
catch
{
return false;
}
}
#endregion
//-------------------------------------------------------------------------
}
_______________________________________________________
"OlivierH" <"nospam[contact]"@planitron.com> wrote in message
news:gea2bm$2t4j$1@news.niouzes.net...
> Bonjour à tous,
>
> Savez vous s'il existe un equivalent de & en c#
>
> car j'ai besoin de manipuler les proprietes d'une class
> dans une boucle.
>
> Mon objet oBO possede des proprietes CP1 à CP10
> et j'aimerais les mettre à jour dans boucle
>
> for (int i = 1; i <= 10; i++)
> {
> (oBoStat)("oBO.CP"+i.toString())=i
> }
>
> ce code ne fonctionne pas.
>
> Si vous avez une idée ce serait super,
> car j'arrive à faire cela pour les objets control
> mais pour les variables ou propriete d'objet.
>
>
> Olivier,
--
Gregory
__
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000002602