在C#中声明 [英] Declared in C #

查看:102
本文介绍了在C#中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不理解这段代码,您能告诉一下它吗?非常感谢.

I dont understand this code, could you tell about it. Thank you so much.

public abstract class EditXPart<TModel> : XPart
{
    [XPartOutParam("_CurrentPage", 0)]
    protected int _CurrentPage;
    protected TModel _entity;
}

推荐答案

<>"表示Google为"Generic Collection".

"[]"部分是Attribute,也在MSDN或google上搜索.
The "<>" indicates a ''Generic Collection'' Google for an explanation.

The "[]" part is an Attribute, search on MSDN or google for that too.


这是类型为TModel的通用抽象类,该类继承自.
由于此类标记为abstract,因此您不能创建它的实例,但是可以为其创建对象.

还有两个带有protected访问修饰符的字段,该修饰符指示只能在此类以及从该类继承的类中使用这些字段. XPartOutParam是应用于属性当前页面的属性.和
第二个属性是类型为TModel的对象.

例如,如果我从上面提到的派生一个类,那么
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>
{
}


属性TModel成为产品_enity是产品
的对象 即


the property TModel becomes Product _enity is the object of product
ie.,

TModel = Product , _entity = objProduct (Product objProduct)



如果TModel是Order,则_entity = objOrder(Order objOrder),依此类推.因此,类型TModel是在编译时定义的.
关于Attribute,我猜这是一个出于某些分页目的而创建的自定义属性.由于属性的参数名称与属性名称相同,因此您的Attribute代码可能会使用System.Reflection来实现一些常见的分页逻辑.

正如我之前提到的,由于这是一个抽象类,因此您无法创建实例,即



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.

EditXPart<Product> objProduct = new EditXPart<Product>();

是不可能的.

is not possible but.

EditXPart<Product> objProduct

是可能的.那么,在我们的示例中,您可以创建
有什么用?

is possible. So what is the use in case of our example you can create

EditXPart<Product> objProduct =new InheritAbstract();


即在您的泛型对象的对象中填充派生类的实例.


i.e. fill an instance of derived class in the object of your Generic one.


abstract部分表示您不能实例化类型,但必须将其子类化.

: XPart表示EditXPart<TModel>子类XPart.

protected部分意味着子类可以访问字段,但类及其子类的使用者不能访问.
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.


这篇关于在C#中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆