Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I dont understand this code, could you tell about it. Thank you so much.

C#
public abstract class EditXPart<TModel> : XPart
{
    [XPartOutParam("_CurrentPage", 0)]
    protected int _CurrentPage;
    protected TModel _entity;
}
Posted
Updated 27-Sep-10 0:23am
v5
Comments
Hiren solanki 27-Sep-10 5:03am    
edited vague code for readability.
OriginalGriff 27-Sep-10 5:55am    
Which bit(s) do you not understand? There is a lot of basic stuff there...

The "<>" indicates a 'Generic Collection' Google for an explanation.

The "[]" part is an Attribute, search on MSDN or google for that too.
 
Share this answer
 
This is a generic abstract class of type TModel and this class inherits from XPart.
Since this class is marked as abstract you cannot create an instance of it, but you can create an object for it.

There are also two fields with protected access modifier which instructs that these fields can be only used in this class and the classes inheriting from this class. XPartOutParam is the attribute applied to the property current page. and
the second property is an object from the type TModel.

Eg if i derive a class from the above mentioned then
public class InheritAbstract : EditXPart<Product>
{
}

the property TModel becomes Product _enity is the object of product
ie.,
C#
TModel = Product , _entity = objProduct (Product objProduct)


if TModel is Order then _entity = objOrder(Order objOrder) and so on. Hence the Type TModel is defined in compile time.
Regarding the Attribute it is a custom attribute created for some paging purposes I guess. Since the attribute takes the parameter name same as the property name, probably your Attribute code will be using System.Reflection to implement some common paging logic.

And as i mentioned earlier since this is an abstract class you cant create an instance i.e.
C#
EditXPart<Product> objProduct = new EditXPart<Product>();
is not possible but.

C#
EditXPart<Product> objProduct
is possible. So what is the use in case of our example you can create

C#
EditXPart<Product> objProduct =new InheritAbstract();

i.e. fill an instance of derived class in the object of your Generic one.
 
Share this answer
 
v2
The abstract part means you cannot instatiate the type, but must subclass it.

The : XPart indicates that EditXPart<TModel> subclasses XPart.

The protected part means that subclasses can access the fields, but consumers of the class and its subclasses can't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900