//---------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// Represents enum Member element from the CSDL.
///
internal class SchemaEnumMember : SchemaElement
{
///
/// Value for this member.
///
long? _value;
///
/// Initializes a new instance of the class.
///
///
/// Parent element.
///
public SchemaEnumMember(SchemaElement parentElement)
: base(parentElement)
{ }
///
/// Gets the value of this enum member. Possibly null if not specified in the CSDL.
///
public long? Value
{
get
{
return _value;
}
set
{
Debug.Assert(value != null, "value != null");
_value = value;
}
}
///
/// Generic handler for the Member element attributes
///
/// Xml reader positioned on an attribute.
/// true if the attribute is a known attribute and was handled. Otherwise false
protected override bool HandleAttribute(XmlReader reader)
{
Debug.Assert(reader != null, "reader != null");
bool handled = base.HandleAttribute(reader);
if (!handled && (handled = CanHandleAttribute(reader, XmlConstants.Value)))
{
HandleValueAttribute(reader);
}
return handled;
}
///
/// Handler for the Member Value attribute.
///
/// XmlReader positioned on the Member Value attribute.
private void HandleValueAttribute(XmlReader reader)
{
Debug.Assert(reader != null, "reader != null");
// xsd validation will report an error if the value is not a valid xs:long number. If the number is valid
// xs:long number then long.TryParse will succeed.
long tmpValue;
if (long.TryParse(reader.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out tmpValue))
{
_value = tmpValue;
}
}
}
}