?
Solved

Geometric Value not valid for enum error durring serialization

Posted on 2008-10-23
3
Medium Priority
?
331 Views
Last Modified: 2013-12-17
I have a class that has a property that represents a Geometric Enumeration value See the code example
and when serializing the error states that 7 is not a valid value for myEnum

Is there a way to set the member to be evaluated as an integer while leaving it strong typed. or to prevent the serialization from validating it.

Regards
Corey2
Public Enum myEnum
   item1 = 1
   item2 = 2
   item3 = 4
   item4 = 8
end enum
 
Private _val as myEnum  = 7 '(which equates to item1 + item2 + item3)
Property Val () as myEnum
    get
       return _val
   end get
    set (byval Value as myEnum)
        _val = value
    end set
end property

Open in new window

0
Comment
Question by:Corey2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 2000 total points
ID: 22787695
One option would be to add as legal values the various combinations you want to allow.  The enum would look something like the code snippet below.

The only other option I can thing of is to define a secondary enum that basicaly redefines the primary enum with the various combinations allowed.  When you want strong typed, use the primary enum, when you want weak typed, use the secondary enum, when you don't care about the type, drop down to integer.
Public Enum myEnum
   item1 = 1
   item2 = 2
   item3 = 4
   item4 = 8
 
   item123 = item1 + item2 + item3
   item34 = item3 + item4
   'etc
end enum

Open in new window

0
 
LVL 13

Author Closing Comment

by:Corey2
ID: 31509274
HooKooDooKu,

I ended up adding another Property that was typed as integer and it simply gets and sets the Strong Typed property and set the Strong typed property to be ignored by XML serialization, but your solution was feasible so I am giving you the points.

Thanks for your suggestions.

Corey2
0
 
LVL 13

Author Comment

by:Corey2
ID: 22825958
This is what I used
Public Enum myEnum
   item1 = 1
   item2 = 2
   item3 = 4
   item4 = 8
end enum
 
Private _val as myEnum  = 7 
<XMLIgnore(), SOAPIgnore()> _
Property Val () as myEnum
    get
       return _val
   end get
    set (byval Value as myEnum)
        _val = value
    end set
end property
 
Property Val2 () as Integer
    get
       return Val
   end get
    set (byval Value as myEnum)
        val = value
    end set
end property

Open in new window

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question