ABB.Swum.ContextBuilder.BuildFieldContext C# (CSharp) Method

BuildFieldContext() public static method

Builds a FieldContext object based on the given field element.
Thrown if the passed XElement does not represent a decl element.
public static BuildFieldContext ( System.Xml.Linq.XElement declElement ) : FieldContext
declElement System.Xml.Linq.XElement An XElement representing the decl element of the field.
return FieldContext
        public static FieldContext BuildFieldContext(XElement declElement)
        {
            if (declElement == null)
            {
                throw new ArgumentNullException("declElement");
            }
            if (declElement.Name != SRC.Declaration)
            {
                throw new ArgumentException(string.Format("The passed XElement must represent a <decl> element. Received a <{0}> element.", declElement.Name.ToString()), "declElement");
            }

            FieldContext fc = new FieldContext();
            //Type of the field
            var typeElement = declElement.Element(SRC.Type);
            if (typeElement != null)
            {
                bool isPrimitive;
                fc.IdType = ConstructTypeName(typeElement, out isPrimitive);
                fc.IdTypeIsPrimitive = isPrimitive;
            }

            //Determine declaring class
            XElement classElement = FindEnclosingClassElement(declElement);
            if (classElement != null && classElement.Element(SRC.Name) != null)
            {
                fc.DeclaringClass = GetNameFromNameElement(classElement.Element(SRC.Name));
            }

            return fc;
        }