When i define this:

[Xtensive.Orm.Field(DefaultValue=123456789.12M)]
public decimal MyField {get;set;}

Compiler throws error:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

But when i use Double type like this:

[Xtensive.Orm.Field(DefaultValue=123456789.12D)]
public double MyField {get;set;}

Everythink compiled and works.

When you look deeper at first example 123456789.12M is shorthand for decimal value, but cannot be used (by some reason that suffix M for decimal don't work same way like other numeric suffixes D-double,L-long,...) in Attribute as value of property DefaultValue. I found "workaround" for this situation here. Solution is to make something what is made in framework type System.ComponentModel.DefaultValueAttribute, where is constructor System.Type which define type of value.

My suggestion is to add another optional property to class FieldAttribute, maybe with name DefaultValueType of type System.Type. When user do not specify directly this type it will continue to work like now, but when user specify this DefaultValueType then you make type conversion (by TypeConverter?) to get the real typed value. In my case i would write this:

[Xtensive.Orm.Field(DefaultValueType=typeof(Decimal), DefaultValue="123456789.12")]
public decimal MyField {get;set;}

and DO converts string "123456789.12" to type Decimal specified in property DefaultValueType.

Update: Found same thing in attribute Xtensive.Orm.TypeDiscriminatorValue where property Value is of type object. Maybe there could be also new property ValueType of System.Type ?

asked Mar 30 '11 at 06:50

Peter%20%C5%A0ulek's gravatar image

Peter Šulek
492313236

edited Mar 30 '11 at 07:10

Btw i found this problem when testing my Entity Model Designer :-)

(Mar 30 '11 at 06:53) Peter Šulek Peter%20%C5%A0ulek's gravatar image

Should we set maximal priority to the issue then? :)

(Mar 30 '11 at 07:10) Dmitri Maximov Dmitri%20Maximov's gravatar image

If it is possible to set max priority it would be great, because my tool will then generate non-compilable code. Sure i can set my editor to not allow user to define decimal for a while, but i would like to avoid this.

(Mar 30 '11 at 07:29) Peter Šulek Peter%20%C5%A0ulek's gravatar image
1

This won't be complicated. Will implement soon.

(Mar 30 '11 at 07:34) Dmitri Maximov Dmitri%20Maximov's gravatar image

Thanks, will wait for it!

(Mar 30 '11 at 07:41) Peter Šulek Peter%20%C5%A0ulek's gravatar image

may be you can implement default for Entity Fields with Guid(and other) keys?

[Xtensive.Orm.Field(DefaultValue="6C539ECE-E02A-42C1-B6D3-BEC03A0A25EA")]

fails on convertion from string to guid

(Mar 30 '11 at 11:02) pil0t pil0t's gravatar image

This change will work either for Guids, you will specify:

[Xtensive.Orm.Field(DefaultValue="6C539ECE-E02A-42C1-B6D3-BEC03A0A25EA", DefaultValueType=typeof(Guid))]

if they implement such feature.

(Mar 30 '11 at 14:22) Peter Šulek Peter%20%C5%A0ulek's gravatar image

2 pil0t, Peter

Sure, will do

(Mar 31 '11 at 03:47) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Done in revision 7663 for fields of decimal & Guid types.

answered Nov 09 '11 at 08:06

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

nice, thanks

(Nov 09 '11 at 10:30) Peter Šulek Peter%20%C5%A0ulek's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573
×7
×5

Asked: Mar 30 '11 at 06:50

Seen: 4,925 times

Last updated: Nov 09 '11 at 10:30

powered by OSQA