c# - TypeDescriptor does not recongnise date -


I am experimenting with the TypeDisptor class.

I have a cookie in which a date - date is converted to a string and then comes back again using a few helpful methods.

One of my main expansion methods is used in conversion, though it throws a forced error as the date is not variable back to the string.

Here is the message that I output:

22/01/2015 14:29:15 can not be changed from time to time

It seems that I have a date time!

The problem can be overcome by using the convert.tDDateTime () , so the code in general is OK. I do not use it anywhere for dates.

The only difference is that I am converting this to the middle of a linq statement like this:

  set = new sorted & lt; TrackedItem & gt; (Set split (';'). Select (s = & gt; {var parts = s.Split (','); Return the new tracked item (part [0] .ConvertTo  (), Convert to date time (part [1]));}));  

Any ideas?

  convert public fixed T & gt; T & gt; (This object obj, bool throwInvalid = false) where T: IConvertible does not need to be changed if obj (obj is returned) (ob); // determine that the object can be changed var type = typef (t); Var converter = Typediscriptor. Gatecountry (type); Var is convertible = converter! = Null & amp; Amp; Converter.IsValid (obj); Var Error = string.Format ("'{0}' can not be changed to type {1}", obj, type.Name; // If no conversion is available, and the default is to throw an error Corrupt (error); // If the object is variable, change it, and then return the default (t) return variable? (T) converter. Convert frame (obj): default (T);}  

By your date example, I'm guessing that you n-GB culture to unfortunately, to attract generously, IsValid to always answer this CultureInfo.InvariantCulture uses (US date format), so when your example is running in N-GB , IsValid back False ; But ConvertFrom , which by default uses the current thread culture will be successful!

Interestingly, whether or not this is actually a bug, hedge out this question in a big way:

Instead of determining whether the value can be converted to the specified type, type The IsValid method is used to validate a value within. For example, IsValid can be used to determine whether a value is returned that is valid for the counting type.

So actually you should IsValid here - you should do the same documentation to give suggestions:

You can type your own WilcoressSubSSod method by wrapping the > in exception blocks

and convert And You can make sure to use CultureInfo in this method. You really care about


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -