brettr
asked on
Help with VB.NET to C# conversion.
I'm having problems with this VB.NET to C# conversion:
[VB.NET]
Dim UDCPrinter As New UDCWRAPPERLib.Printer
Dim UDCProfile As UDCWRAPPERLib.Profile
UDCPrinter.PrinterName = "Universal Document Converter"
UDCProfile = UDCPrinter.Profile(UDCPrin ter.Defaul tProfile)
[C#}
UDCWRAPPERLib.Printer UDCPrinter = new UDCWRAPPERLib.Printer();
UDCWRAPPERLib.Profile UDCProfile;
UDCPrinter.PrinterName = "Universal Document Converter";
UDCProfile = UDCPrinter.get_Profile();
Error is on the last line:
No overload for method 'get_Profile' takes '0' arguments
Object browser tree looks like this:
UDCWRAPPERLib
Printer (interface)
IPrinter (interface)
get_Profile(string) is a member of the last node.
I'm using get_Profile because .Profile isn't available in C#. Why does the above error occur is "string" type is required?
I have tried:
UDCProfile = UDCPrinter.get_Profile(UDC Printer.De faultProfi le);
and get:
Cannot implicitly convert type 'object' to 'UDCWRAPPERLib.Profile'
Any suggestions?
Thanks,
Brett
[VB.NET]
Dim UDCPrinter As New UDCWRAPPERLib.Printer
Dim UDCProfile As UDCWRAPPERLib.Profile
UDCPrinter.PrinterName = "Universal Document Converter"
UDCProfile = UDCPrinter.Profile(UDCPrin
[C#}
UDCWRAPPERLib.Printer UDCPrinter = new UDCWRAPPERLib.Printer();
UDCWRAPPERLib.Profile UDCProfile;
UDCPrinter.PrinterName = "Universal Document Converter";
UDCProfile = UDCPrinter.get_Profile();
Error is on the last line:
No overload for method 'get_Profile' takes '0' arguments
Object browser tree looks like this:
UDCWRAPPERLib
Printer (interface)
IPrinter (interface)
get_Profile(string) is a member of the last node.
I'm using get_Profile because .Profile isn't available in C#. Why does the above error occur is "string" type is required?
I have tried:
UDCProfile = UDCPrinter.get_Profile(UDC
and get:
Cannot implicitly convert type 'object' to 'UDCWRAPPERLib.Profile'
Any suggestions?
Thanks,
Brett
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the message: "Cannot implicitly convert type 'object' to 'UDCWRAPPERLib.Profile'"
it just says that .NET could not automatically convert it to the desired type. so we do manual conversion thus casting :)
good luck
it just says that .NET could not automatically convert it to the desired type. so we do manual conversion thus casting :)
good luck
ASKER
VB.NET seems to do much implied casting vs. C#. Is that true?
Nope, in VB.NET UDCPrinter.Profile(string) will return UDCWRAPPERLib.Profile object. But in C# get_Profile() just return object, then you must cast to UDCWRAPPERLib.Profile
Following code from 3Mann was right:
UDCProfile = (UDCWRAPPERLib.Profile)UDC Printer.ge t_Profile( UDCPrinter .DefaultPr ofile);
Following code from 3Mann was right:
UDCProfile = (UDCWRAPPERLib.Profile)UDC
ASKER
Why does C# return only an object and not UDCWRAPPERLib.Profile object?
object is the equivalent of VB's variant
i'm not familiar with UDCWRAPPERLib. I'm not sure why it returns object. maybe so you can cast it to compatible types other than UDCWRAPPERLib.Profile.
cheers :)
i'm not familiar with UDCWRAPPERLib. I'm not sure why it returns object. maybe so you can cast it to compatible types other than UDCWRAPPERLib.Profile.
cheers :)
ASKER
Additional information: Cannot receive name of the default profile
I don't have the VB version with me here but I believe the default is actually getting set. I'll check it tomorrow morning.
How did you know to cast the get_Profile() from the error given?