Solved

Geometric Value not valid for enum error durring serialization

Posted on 2008-10-23
3
329 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET - Refactor Class per SOLID principles 2 33
Get sourcecode path 14 48
vb.net datagrid scroll automatically to the first found row 11 28
Header Font Size in Grid View 6 27
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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