mamift / LinqToXsdCore

LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ for the code generator CLI tool).
Microsoft Public License
41 stars 15 forks source link

Missing null check in a ToXTypedElement of XTypedServices.cs #41

Open ttjorvi opened 2 years ago

ttjorvi commented 2 years ago

In line 36 of XTypedServices.cs there is missing a check for whether xe is null for ToXTypedElement.

Null is checked in other ToXTypedElement methods but is missing in this one. For example, a check for null is in line 75:

        public static T ToXTypedElement<T>(XElement xe) where T : XTypedElement
        {
            if (xe == null)
            {
                return null;
            }

            T xoSubType = GetAnnotation<T>(xe);

Such a check should be added to line 36:

        public static XTypedElement ToXTypedElement(XElement xe, ILinqToXsdTypeManager typeManager, Type rootType,
            Type contentType)
        {

            XTypedElement rootElement = GetAnnotation(rootType, xe);

So that it is like this:

        public static XTypedElement ToXTypedElement(XElement xe, ILinqToXsdTypeManager typeManager, Type rootType,
            Type contentType)
        {

            if (xe == null)
            {
                return null;
            }

            XTypedElement rootElement = GetAnnotation(rootType, xe);