Skip to content

DataTable, the result of the new operator is checked for null #78684

Description

@VasilievSerg

The code:

protected virtual XmlSchema? GetSchema()
{
    if (GetType() == typeof(DataTable))
    {
        return null;
    }
    MemoryStream stream = new MemoryStream();

    XmlWriter writer = new XmlTextWriter(stream, null); // <=
    if (writer != null)    // <=
    {
        (new XmlTreeGen(SchemaFormat.WebService)).Save(this, writer);
    }
    stream.Position = 0;
    return XmlSchema.Read(new XmlTextReader(stream), null);
}

The writer variable is checked for null after the object was created via the new operator. As a result, the writer != null expression is always true.

Is it an error or just redundant code?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions