Need to check if the propery of an object exits.

Need to check if the propery of an object exits.

am 01.01.2008 00:17:28 von Adrian

Hi All,

Need to check if the propery of an object exits.

oMyObject.Message

In some cases the Message property may not exists. I know the GetType() can
do it.
How would you check it?

Thanks,

Joe

Re: Need to check if the propery of an object exits.

am 01.01.2008 01:04:58 von info

System.Reflection and iterate through the PropertyInfo[].

The Type of the object has a .GetProperties method.

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials/aspnet/2a5222d8-3d69-4f 1c-b5ab-35ca33da0f65/net-setup-deployment--m.aspx



"JoeP" wrote in message
news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl...
> Hi All,
>
> Need to check if the propery of an object exits.
>
> oMyObject.Message
>
> In some cases the Message property may not exists. I know the GetType()
> can do it.
> How would you check it?
>
> Thanks,
>
> Joe
>

Re: Need to check if the propery of an object exits.

am 01.01.2008 01:41:50 von Adrian

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C84BE5.309452C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Robbin,

Thanks for your reply.

Here is the situation I have 2 objects such as: Execption or =
SMTPExecption
The SMTPExecption has the property StatusCode while the other does not.

I pass the the object into an error handle method where I log the =
properties into a text file.
Looking at the Watch window it seems that the Execption does not have =
System.Reflection etc...

Regards,

Joe

=20
"Robbe Morris - [MVP] C#" wrote in message =
news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl...
> System.Reflection and iterate through the PropertyInfo[].
>=20
> The Type of the object has a .GetProperties method.
>=20
> --=20
> Robbe Morris [Microsoft MVP - Visual C#]
> .NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
> =
http://www.eggheadcafe.com/tutorials/aspnet/2a5222d8-3d69-4f 1c-b5ab-35ca3=
3da0f65/net-setup-deployment--m.aspx
>=20
>=20
>=20
> "JoeP" wrote in message=20
> news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl...
>> Hi All,
>>
>> Need to check if the propery of an object exits.
>>
>> oMyObject.Message
>>
>> In some cases the Message property may not exists. I know the =
GetType()=20
>> can do it.
>> How would you check it?
>>
>> Thanks,
>>
>> Joe
>>=20
>
------=_NextPart_000_0015_01C84BE5.309452C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



charset=3Diso-8859-1">




Hi Robbin,

 

Thanks for your reply.

 

Here is the situation I have 2 objects =
such as:=20
Execption or SMTPExecption

The SMTPExecption has the property =
StatusCode while=20
the other does not.

 

I pass the the object into an error =
handle=20
method where I log the properties into a text file.

Looking at the Watch window it =
seems that=20
the Execption does not have System.Reflection etc...

 

Regards,

 

Joe

 

  

"Robbe Morris - [MVP] C#" <
href=3D"mailto:info@eggheadcafe.com"> size=3D2>info@eggheadcafe.com
> =
wrote in=20
message
href=3D"news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl"> face=3DArial =
size=3D2>news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl
face=3DArial size=3D2>...
> =
System.Reflection=20
and iterate through the PropertyInfo[].
>
> The Type of the =
object=20
has a .GetProperties method.
>
> --
> Robbe Morris=20
[Microsoft MVP - Visual C#]
> .NET Setup Deployment - MSI, =
Cassini, SQL=20
Server, NTFS
>
href=3D"http://www.eggheadcafe.com/tutorials/aspnet/2a5222d8 -3d69-4f1c-b5=
ab-35ca33da0f65/net-setup-deployment--m.aspx"> face=3DArial=20
size=3D2>http://www.eggheadcafe.com/tutorials/aspnet/2a5222d 8-3d69-4f1c-b=
5ab-35ca33da0f65/net-setup-deployment--m.aspx
face=3DArial size=3D2>>
>
>
> "JoeP" =
< href=3D"mailto:NoSpam@Hotmail.com"> size=3D2>NoSpam@Hotmail.com> =
wrote in=20
message
>
href=3D"news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl"> size=3D2>news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl face=3DArial=20
size=3D2>...
>> Hi All,
>>
>> Need to check =
if the=20
propery of an object exits.
>>
>>=20
oMyObject.Message
>>
>> In some cases the Message =
property may=20
not exists. I know the GetType()
>> can do it.
>> How =
would=20
you check it?
>>
>> Thanks,
>>
>>=20
Joe
>>
>


------=_NextPart_000_0015_01C84BE5.309452C0--

Re: Need to check if the propery of an object exits.

am 02.01.2008 21:03:46 von info

This is a multi-part message in MIME format.

------=_NextPart_000_0032_01C84D50.AC4562D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

And when you performed an

Type myType =3D myException.GetType();

PropertyInfo[] properties =3D myType.GetProperties();

what did you get?

--=20
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web surveys
http://www.equalssolved.com/default.aspx




"JoeP" wrote in message =
news:O8Pjv7ATIHA.4656@TK2MSFTNGP03.phx.gbl...
Hi Robbin,

Thanks for your reply.

Here is the situation I have 2 objects such as: Execption or =
SMTPExecption
The SMTPExecption has the property StatusCode while the other does =
not.

I pass the the object into an error handle method where I log the =
properties into a text file.
Looking at the Watch window it seems that the Execption does not have =
System.Reflection etc...

Regards,

Joe

=20
"Robbe Morris - [MVP] C#" wrote in message =
news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl...
> System.Reflection and iterate through the PropertyInfo[].
>=20
> The Type of the object has a .GetProperties method.
>=20
> --=20
> Robbe Morris [Microsoft MVP - Visual C#]
> .NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
> =
http://www.eggheadcafe.com/tutorials/aspnet/2a5222d8-3d69-4f 1c-b5ab-35ca3=
3da0f65/net-setup-deployment--m.aspx
>=20
>=20
>=20
> "JoeP" wrote in message=20
> news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl...
>> Hi All,
>>
>> Need to check if the propery of an object exits.
>>
>> oMyObject.Message
>>
>> In some cases the Message property may not exists. I know the =
GetType()=20
>> can do it.
>> How would you check it?
>>
>> Thanks,
>>
>> Joe
>>=20
>
------=_NextPart_000_0032_01C84D50.AC4562D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



charset=3Diso-8859-1">




And when you performed an

 

Type myType =3D =
myException.GetType();

 

PropertyInfo[] properties =
myType.GetProperties();

 

what did you get?


--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL =
Server,=20
Designer, and Data Analyzer
Convert cell ranges in Excel to rule =
driven web=20
surveys
href=3D"http://www.equalssolved.com/default.aspx">http://www .equalssolved=
..com/default.aspx

 

 

 

 

style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
"JoeP" < href=3D"mailto:NoSpam@Hotmail.com">NoSpam@Hotmail.com>=20
wrote in message =
href=3D"news:O8Pjv7ATIHA.4656@TK2MSFTNGP03.phx.gbl">news:O8P jv7ATIHA.4656=
@TK2MSFTNGP03.phx.gbl...

Hi Robbin,

 

Thanks for your reply.

 

Here is the situation I have 2 =
objects such as:=20
Execption or SMTPExecption

The SMTPExecption has the property =
StatusCode=20
while the other does not.

 

I pass the the object into an error =
handle=20
method where I log the properties into a text file.

Looking at the Watch window it=20
seems that the Execption does not have System.Reflection=20
etc...

 

Regards,

 

Joe

 

  

"Robbe Morris - [MVP] C#" =
<
href=3D"mailto:info@eggheadcafe.com"> size=3D2>info@eggheadcafe.com size=3D2>> wrote in=20
message
href=3D"news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl"> face=3DArial =
size=3D2>news:eEpD5nATIHA.4880@TK2MSFTNGP03.phx.gbl
face=3DArial size=3D2>...
> =

System.Reflection and iterate through the PropertyInfo[].
> =

> The=20
Type of the object has a .GetProperties method.
>
> -- =

>=20
Robbe Morris [Microsoft MVP - Visual C#]
> .NET Setup Deployment =
- MSI,=20
Cassini, SQL Server, NTFS
>
=
href=3D"http://www.eggheadcafe.com/tutorials/aspnet/2a5222d8 -3d69-4f1c-b5=
ab-35ca33da0f65/net-setup-deployment--m.aspx"> face=3DArial=20
=
size=3D2>http://www.eggheadcafe.com/tutorials/aspnet/2a5222d 8-3d69-4f1c-b=
5ab-35ca33da0f65/net-setup-deployment--m.aspx
face=3DArial size=3D2>>
>
>
> "JoeP" =
< href=3D"mailto:NoSpam@Hotmail.com"> size=3D2>NoSpam@Hotmail.com> =
wrote in=20
message
>
href=3D"news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl">
size=3D2>news:OfntlMATIHA.6036@TK2MSFTNGP03.phx.gbl
face=3DArial=20
size=3D2>...
>> Hi All,
>>
>> Need to check =
if the=20
propery of an object exits.
>>
>>=20
oMyObject.Message
>>
>> In some cases the Message =
property=20
may not exists. I know the GetType()
>> can do =
it.
>> How=20
would you check it?
>>
>> =
Thanks,
>>
>>=20
Joe
>>
>


------=_NextPart_000_0032_01C84D50.AC4562D0--