Domanda

Like I said in the title, I'm trying to understand this assignment because I never saw something like this.

The fact is that I have a class which implements some generic types and its defined this way.

public abstract class BaseClass<T, R>
    where T : DataTable, new()
    where R : DataRow
{
    //some code here...

    protected internal R _entityData1;
    public R Data1
    {
        get { return _entityData1; }
        set { _entityData1 = value; }
    }

    //some other code here. (not relevant)
}

Then I have an inherited class defined this way, with a method which exposes the assignment that I mentioned in the title of this question:

public class InheritedClass : BaseClass<SomeOtherClass.InheritedFromDataTable, SomeOtherClass.InheritedFromDataRow>
{
      //some code here...

      public void SomeMethod()
      {
           //here I'm confused
           this.Data1.Table.Rows.Add(this.Data1);
      }

      //more code..
}

How can you do this without entering in a loop or something??... or this is because there exist a reference to the DataTable object stored outside the Data object?

I think that is important to say that what I've shown as a simplified model of the inheritance... in the project involves many other classes which I didn't expose because it would be unreadable.

Hope you understand my question.

È stato utile?

Soluzione

By definition, this.Data1 is a SomeOtherClass.InheritedFromDataRow, which is a DataRow. A DataRow has a Table property which refers to the containing DataTable.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top