小编jud*_*dek的帖子

索引器的扩展方法,它们会好吗?

索引器的扩展方法,它们会好吗?

我正在玩一些重新补充POCO的代码.

代码迭代从SqlDataReader返回的行,并使用反射从列值分配属性.在我的调用堆栈中,我有一个像这样的代码: -

poco.Set("Surname", "Smith"); // uses extension method ...
Run Code Online (Sandbox Code Playgroud)

Set方法被编写为扩展方法.

能够编写这样的代码会很棒

poco["Surname"] = "Smith";  // extension methods for indexers ?
Run Code Online (Sandbox Code Playgroud)

即我想为索引器编写扩展方法

有没有充分的理由说.Net没有索引器的扩展方法?其他人对扩展方法索引器有其他好的用途吗?

如果我们可以为索引器编写扩展方法,那么我们可以编写这样的代码......

var poco = PocoFactory();  
    poco.Surname = “Smith”; // is this JavaScript ...
    poco[Surname] = “Smith” ; // … or is this c# or both
Run Code Online (Sandbox Code Playgroud)

我的代码中的一些片段

/////////////////////////////////////////////
// Client calling code
IDab dab = DabFactory.Create( "Northwind" );
string sql = @"select * from Customers ";
var persons = dab.ExecuteReader<NorthwindCustomer>(sql);
if (dab != null{
   Assert.That(persons[0].CustomerID , Is.EqualTo("ALFKI"));} …
Run Code Online (Sandbox Code Playgroud)

c# methods indexer data-access-layer

23
推荐指数
1
解决办法
7714
查看次数

F#使用type作为属性名称

我需要像下面这样的课程

type BubbleChartSeriesDefaults()=
    let mutable _type:string  = "" 
    member t.type  with get() = _type and set v = _type <- v 
Run Code Online (Sandbox Code Playgroud)

F#不喜欢我使用关键字类型作为属性名称.我在http管道上发送了一些f#类型,供javascript客户端使用.消费者正在寻找名为type的属性名称.使用关键字作为属性名称并不是很好,但有没有办法偷偷摸摸这个.任何人都知道如何在af#class中获得一个名为type的属性?(有点像在c#中使用@case作为变量...)

f# properties names keyword

3
推荐指数
1
解决办法
394
查看次数

标签 统计

c# ×1

data-access-layer ×1

f# ×1

indexer ×1

keyword ×1

methods ×1

names ×1

properties ×1