List Info

Thread: Determine type default value




Determine type default value
user name
2006-08-11 10:34:28
Frans,

I have a web control similar to the workitem area in CAB (I
think that's
what it's called, were using UIP) When I'm about to render
a page I retrieve
the entity that the screen is bound to (defined within
web.config - I'm told
what entity to look at i.e. an object with a whole slew of
properties).

I also know what properties I have to attain (calculated by
navigation) so
for instance for screen x I know I need ClientName and
ClientType for screen
Y AccountType and Sequence etc (we have a complicated
algorithm for this as
pages are dependant upon other pages supply values).

I use reflection to look for the properties I need. They
should all be
simple types int, float, DateTime (not to sure about this
one) etc.

Now the issue I have is - Let's say I've calculated to
retrieve 'Sequence'
(which in this case is an int) if I get back 0 there is a
possibility that I
didn't get a value.

For properties that didn't return a value I have a
Mainframe service that
can resolve values for me (based on all the data/context I
have). So I need
some way to know that I retrieved the default value (or
possibly didn't get
a value)

So I can ask the mainframe to give me 'Sequence' if I get
back zero from it
I decide whether it's ok depending on whether I accept a
value which is
equal to the default for the property type (again defined
within config
allowDefault="true").

I'd rather not have the developer define within config what
is a
defaultvalue or non-value if I can.

Hope that helps.
Rob.

-----Original Message-----
From: Discussion of development on the .NET platform using
any managed
language [mailtoOTNET-CL
RDISCUSS.DEVELOP.COM] On Behalf Of Frans Bouma
Sent: Friday, August 11, 2006 7:14 PM
To: DOTNET-CLRDISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Determine type default value

> It should suffice that all I need to know is if the
property
> type is a value type that the value will be equal to 0
and
> null if a reference type I can safely assume that it's
the
> properties default value.

        then why not simply check the Type object returned
by the
PropertyType property of the property descriptor and check
its
IsValueType property? If true, it's a valuetype, and not
null, and otherwise
it's a reference type and thus can be null.

        Could you elaborate a bit about WHY you need that
default in the
first place?

                FB

>
> I wouldn't need to instantiate any given my simple
rule above?
>
> (Yes presumably in the future I could require some
other
> value to represent a default but that's another
requirement
> that will get scoped accordingly at the moment it's
clearly
> document as an assumption - oh I just love
> assumptions.)
>
>
> -----Original Message-----
> From: Discussion of development on the .NET platform
using
> any managed language [mailtoOTNET-CL
RDISCUSS.DEVELOP.COM]
> On Behalf Of Barry Kelly
> Sent: Friday, August 11, 2006 5:34 PM
> To: DOTNET-CLRDISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CLR] Determine type default value
>
> Robert Rolls <Robert.RollsDEVNET.ATO.GOV.AU>
wrote:
>
> > Is there anyway to determine what the default
value of a
> type will be?
>
> What do you mean by default? For value types, the
'default'
> value is all zeros. For reference types, the
'default' value
> is null. Do you have some different default in mind?
>
> > I don't need to know whether
> > zero was assigned all I need to know is whether
it's the
> types default
> > value.
>
> Compare it (using object.Equals(object,object)) with a
> default value, however you get one. For example, for
value
> types, you can instantiate a new one with
> Activator.CreateInstance(). ValueType overrides
> object.Equals(object) in order to do a field by field
> comparison. For reference types, either you take
'null' as
> being the default value, or you rely on it being safe
to
> construct a new instance, and rely on
> object.Equals(object) being correctly overridden.
>
> -- Barry
>
> --
> http://barrkel.blogspot.
com/
>
> ===================================
> This list is hosted by DevelopMentor.  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

>
> ===================================
> This list is hosted by DevelopMentor.  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )