473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why/How two objects require Widening/Narrowing conversions

!NoItAll
297 100+
I'm a bit lost...
I have two objects implemented as UserControls (compiled as separate DLLs). Both have implemented a specific property that is, in itself, an object. I need to pass this object between the two UserControls. Both of these internal properties are created separately and contain properties named the same and are typed the same. One, however is serializable, while the other is not. One contains two methods that the other does not. Otherwise each contain string properties that are, indeed, all the same.
VB.Net will not let me assign one to the other either directly or through TryCast without either a widening or narrowing conversion. I admit to not understanding what I should actually do in this conversion, so I am asking for some guidance. Here are my two properties:
First - the serializable one...
Expand|Select|Wrap|Line Numbers
  1. Public Class PanelInfo
  2.     <XmlElement("sourceowner")> Public Property SourceOwner As New String(String.Empty)
  3.     <XmlElement("locationname")> Public Property LocationName As New String(String.Empty)
  4.     <XmlElement("description")> Public Property Description As New String(String.Empty)
  5.     <XmlElement("secondarydescription")> Public Property SecondaryDescription As New String(String.Empty)
  6.     <XmlElement("misc")> Public Property Misc As New String(String.Empty)
  7.     <XmlElement("geolocation")> Public Property Geolocation As New GeolocationInfo_Type
  8.     <XmlElement("copyright")> Public Property Copyright As New String(String.Empty)
  9.  
  10.     Private _CameraType As New String("unknown")
  11.     <XmlElement("cameratype")> Public Property CameraType As String
  12.         Get
  13.             Return _CameraType
  14.         End Get
  15.         Set(value As String)
  16.             Select Case value.ToLower
  17.                 Case "ptz"
  18.                     _CameraType = value
  19.                 Case "fixed"
  20.                     _CameraType = value
  21.                 Case "unknown"
  22.                     _CameraType = value
  23.                 Case Else
  24.                     _CameraType = "unknown"
  25.                     Throw New Exception("Only 'ptz', 'fixed' or 'unknown' are valid camera types")
  26.             End Select
  27.         End Set
  28.     End Property
  29.     Public Function XML() As String
  30.         Using ser As New Serialization.Serializer
  31.             Return ser.Obj2XML(Me, GetType(PanelInfo))
  32.         End Using
  33.     End Function
  34.  
  35.     Public Sub LoadXML(XML As String)
  36.         Using ser As New Serialization.Serializer
  37.             Dim This As PanelInfo = ser.XML2Obj(XML, GetType(PanelInfo))
  38.             Me.SourceOwner = This.SourceOwner
  39.             Me.LocationName = This.LocationName
  40.             Me.Description = This.Description
  41.             Me.SecondaryDescription = This.SecondaryDescription
  42.             Me.Misc = This.Misc
  43.             Me.Geolocation = This.Geolocation
  44.             Me.Copyright = This.Copyright
  45.             Me.CameraType = This.CameraType
  46.         End Using
  47.     End Sub
  48.  
  49. End Class
  50.  
  51. Public Class GeolocationInfo_Type
  52.     <XmlAttribute("latitude")> Public Property Latitude As New String(String.Empty)
  53.     <XmlAttribute("longitude")> Public Property Longitude As New String(String.Empty)
  54.     <XmlAttribute("elevation")> Public Property Elevation As New String(String.Empty)
  55. End Class
  56.  
Now the non-serializable one (you can see it does not have the XML or LoadXML methods implemented - nor the serialization decorations)

Expand|Select|Wrap|Line Numbers
  1. Public Class PanelInfo
  2.     Public Property SourceOwner As New String(String.Empty)
  3.     Public Property LocationName As New String(String.Empty)
  4.     Public Property Description As New String(String.Empty)
  5.     Public Property SecondaryDescription As New String(String.Empty)
  6.     Public Property Misc As New String(String.Empty)
  7.     Public Property Geolocation As New Geolocation_Type
  8.     Public Property Copyright As New String(String.Empty)
  9.  
  10.     Private _CameraType As New String("unknown")
  11.     Public Property CameraType As String
  12.         Get
  13.             Return _CameraType
  14.         End Get
  15.         Set(value As String)
  16.             Select Case value.ToLower
  17.                 Case "ptz"
  18.                     _CameraType = value
  19.                 Case "fixed"
  20.                     _CameraType = value
  21.                 Case "unknown"
  22.                     _CameraType = value
  23.                 Case Else
  24.                     _CameraType = "unknown"
  25.                     Throw New Exception("Only 'ptz', 'fixed' or 'unknown' are valid camera types")
  26.             End Select
  27.         End Set
  28.     End Property
  29.  
  30.     Public Function XML() As String
  31.         Throw New NotImplementedException("Not Implemented - non serializable class")
  32.     End Function
  33.  
  34.     Public Sub LoadXML(XML As String)
  35.         Throw New NotImplementedException("Not Implemented - non serializable class")
  36.     End Sub
  37.  
  38. End Class
  39.  
  40. Public Class Geolocation_Type
  41.     Public Property Latitude As New String(String.Empty)
  42.     Public Property Longitude As New String(String.Empty)
  43.     Public Property Elevation As New String(String.Empty)
  44. End Class
  45.  
I can go through each of the properties and assign the values, but I would rather just pass one property to the other - but the IDE says I need a Widening Conversion if I pass it directly, or a Narrowing Conversion if I use TryCast. The IDE is helpful in that it offers to create the conversion for me, but it is pre-filled with a NotImplementedException - and I'm not clear on what I need to code inside this conversion...
Any help would be greatly appreciated.
Oct 9 '18 #1
0 2095

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ann Huxtable | last post by:
Hi, I am writing a nested table structure to mimic data returned from a database (actually, a heirarchical recordset). I am representing the cells where the actual data is stored, by a union:...
48
by: Andrew Quine | last post by:
Hi Just read this article http://www.artima.com/intv/choices.html. Towards the end of the dicussions, when asked "Did you consider including support for the concept of immutable directly in C#...
14
by: Erik Frey | last post by:
Hello, Say I have the following two classes: class Base { } class Inherited : Base {
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
9
by: Codemonkey | last post by:
Hi, Sorry for a stupid question, but is it possible to do a narrowing conversion with an object array with Option Strict On in VB? E.g: ------------------ Dim aBase as Base() = {New...
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
3
by: van6 | last post by:
code frag: int main() { float fval1 = 1.0f; float fval2 = 2.0f; double dsum =0.0; // here is the point ; // Are fval1 and fval2 both promoted to type of double prior to adding
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
4
by: jaime | last post by:
Hi all. Apologies, since this is more a tool question, than strictly a language question, but hey, it seemed like an appropriate place to ask... I'm a c newbie (and have been now for about 6...
1
by: Brad Pears | last post by:
I am using a function called "CreateSQLParam" which adds SQL parameters to a collection. The function is shown below... I add a parameter to a collection using the following line code... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.