Convert Structure in SerializationBinder - vb.net

Is there something special that needs to be done in order to convert a structure within a SerializationBinder?
Refer to my original question and "answer" to that: Type.GetType returns Nothing in SerializationBinder
The first time it comes to a list of a structure, I get:
Object of type 'System.Runtime.Serialization.TypeLoadExceptionHolder'
cannot be converted...

Well, I'm blind...it turns out the issue was that I was missing a couple brackets at the end in each of the statements to convert a list of something.
Ex: Change:
typeName = String.Format("System.Collections.Generic.List`1[[[my project].[type]], {0}", Assembly.GetExecutingAssembly().FullName)
To:
typeName = String.Format("System.Collections.Generic.List`1[[[my project].[type]], {0}]]", Assembly.GetExecutingAssembly().FullName)
WHY I didn't get an error until after it tried to convert a list of a structure specifically and everything before that seemed to work, I have NO IDEA.

Related

Proper Syntax When Using dot Operator in String Interpolation in Dart

In Dart/Flutter, suppose you have an instance a of Class Y.
Class Y has a property, property1.
You want to print that property using string interpolation like so:
print('the thing I want to see in the console is: $a.property1');
But you can't even finish typing that in without getting an error.
The only way I can get it to work is by doing this:
var temp = a.property1;
print ('the thing I want to see in the console is: $temp');
I haven't found the answer online... and me thinks there must be a way to just do it directly without having to create a variable first.
You need to enclose the property in curly braces:
print('the thing I want to see in the console is: ${a.property}');
That will then print the value of a.property.
It seems you can also do this, but it doesn't seem to be documented anywhere:
print('..... $a.$property1');

Only get DateTimeOriginal with exiftool

Hey community,
Since a few days I'm stuck while trying to get the date of a .jpg or .png image file, when the picture was taken.
I believe it was called DateTimeOriginal.
What I'm trying to do, is getting just this one specific info, DateTimeOriginal, not more, not less.
This is part of a selfmade project, a program to sort pictures by the date when they were taken.
I'm programming with VB, and for the exif data I'm calling a batch file.
So i know how to use the exiftool. It's common use is:
exiftool file.jpg
But I need something like:
exiftool -DateTimeOriginal file.jpg >> DateTaken.txt
I have tried this one, but I'm not getting the Date, I only got a list of any jpg found in the directory, but without metadata.
I was searching so long for any option like this, but I can't find anything useful. Perhaps there is another, more efficient way to get metadata of an image, only using VB.
Has anyone an advise or other idea?
Thanks
You have the correct command to get the DateTimeOriginal tag from a file (exiftool -DateTimeOriginal file.jpg). But you say you are getting a list of filenames in a directory, which sounds like you're passing a directory name, not a file name. If you wish to get DateTimeOriginal for only those files in a directory that have a value in the tag, use exiftool -if "$DateTimeOriginal" -DateTimeOriginal C:/path/to/dir. Any file that doesn't have a DateTimeOriginal will not be listed then.
One thing to note is that the windows "Date Taken" property will be filled by a variety of metadata tags depending upon the filetype. For example, in PNG files, Windows will use PNG:CreationTime. In jpg files, Windows will use, in order, EXIF:DateTimeOriginal, IPTC:DateCreated + IPTC:TimeCreated, XMP:CreateDate, EXIF:CreateDate, and then XMP:DateTimeOriginal tags.
After a bit of digging, I found that you can get a list of properties if a bitmap.
Unfortunately the property IDs are numeric and rather cryptic.
Have a look here to find out more
After a bit more digging, it seems that the propertyId &h132 (a hexadecimal number) is the date stored as an array of integers in ascii encoding. This function finds propertyid &h132 and returns the date info as a string in year:month:date hour:minute:second format.
You might get variations with localization.. for example using /,: or - for the date separators etc, so, to parse it as a date type, you might need to work around that.
Public Function GetImageTakenDate(theimage As Bitmap) As String
Dim propItems As List(Of PropertyItem) = theimage.PropertyItems.ToList
Dim dt As PropertyItem = propItems.Find(Function(x) x.Id = &H132)
Dim datestring As String = ""
For Each ch As Integer In dt.Value
datestring += Chr(ch)
Next
datestring = datestring.Remove(datestring.Length - 1)
Return datestring
End Function

date object prefixing with # vb.net

I am writing sample code for Date conversion using VB.net.
Problem i am facing that it is prefixing and suffixing with hash(#) symbol.
ex : #2010-12-12#.
How to remove # symbol so that i can only date.
Given your comment, it sounds like this is actually probably just an issue of displaying a DateTime in the debugger. It showing you the DateTime literal form that you could use in VB. This is a bit like C# developers who are concerned about their strings having double backslashes in, when actually that's just the debugger showing escaping.
The DateTime itself doesn't really contain the hashes, and none of the normal format strings will produce hashes either. If you want to see it without the hashes, add a watch for
arrTxLifeReq(0).TransExeDate.ToString()
Does the code which is part of your real program have any problems? If so, please post details of those problems rather than just what the debugger is showing.
Just replace # with ''
for example
string dt = "#2010-12-12#";
dt = dt.Replace ("#","");

Reporting Services - handling an empty date?

Hey, I have a report parameter which looks like this: 01.01.2009 00:00:00
Its a date (as string), as you might have guessed :). The problem is, this param can be an empty string as well. So I tried those expressions:
=IIf(IsDate(Parameters!DateTo.Value), CDate(Parameters!DateTo.Value), "")
=IIf(Len(Parameters!DateTo.Value) > 0, CDate(Parameters!DateTo.Value), "")
Both dont work and the value for the textfield where I print the expressions result is always #Error. As soon as I remove the CDate stuff, it works, but I have to use it. IS there another way to achieve that? What I want is to display nothing if its not a date or the date (format dd.mm.yyyy) if its a date.
Ideas?
Thanks :)
All arguments to the IIf are evaluated, which results in your error, since the CDate will fail for an empty string.
You can get around this by just writting a function along these lines, using a standard if statement:
Function FormatDate(ByVal s As String) As String
If (s <> "") Then
Return CDate(s).ToString()
Else
Return ""
End If
End Function
Then call it with: =Code.FormatDate(Parameters!DateTo.Value)
First, fix your database to properly store dates rather than doing these workarounds. You probably have bad data in there as well (Feb 30 2010 for example or my favorite, ASAP). Truly there is no excuse for not fixing this at the database level where it needs to be fixed except if this is vendor provided software that you can't change (I would yell at them though, well notify them really, and ask them to fix their data model or go to a new product designed by someone who knows what they are doing. A vendor who can't use dates properly is likely to have software that is very poor all around).
In the query that you use to select the infomation, have you considered just converting all non-dates to null?

Newbie issue with LINQ in vb.net

Here is the single line from one of my functions to test if any objects in my array have a given property with a matching value
Return ((From tag In DataCache.Tags Where (tag.FldTag = strtagname) Select tag).Count = 1)
WHERE....
DataCache.Tags is an array of custom objects
strtagname = "brazil"
and brazil is definitely a tag name stored within one of the custom objects in the array.
However the function continually returns false.
Can someone confirm to me that the above should or should not work.
and if it wont work can someone tell me the best way to test if any of the objects in the array contain a property with a specific value.
I suppose in summary I am looking for the equivalent of a SQL EXISTS statement.
Many thanks in hope.
Your code is currently checking whether the count is exactly one.
The equivalent of EXISTS in LINQ is Any. You want something like:
Return DataCache.Tags.Any(Function(tag) tag.FldTag = strtagname)
(Miraculously it looks like that syntax may be about right... it looks like the docs examples...)
Many Thanks for the response.
Your code did not work. Then I realised that I was comparing to an array value so it would be case sensitive.
However glad I asked the question, as I found a better way than mine.
Many thanks again !