假设我有一些类似的对象,具有很多属性:
public class SomeObject
{
public SomeOtherObject1 Property1 { get; set; }
public SomeOtherObject2 Property2 { get; set; }
public SomeOtherObject3 Property3 { get; set; }
public SomeOtherObject4 Property4 { get; set; }
public SomeOtherObject5 Property5 { get; set; }
public SomeOtherObject6 Property6 { get; set; }
}
如果我可以创建一个构造函数并将属性复制到构造函数中,那将是非常酷的......
public class SomeObject
{
public SomeObject
{
public SomeOtherObject1 Property1 { get; set; }
public SomeOtherObject2 Property2 { get; set; }
public SomeOtherObject3 Property3 { get; set; }
public SomeOtherObject4 Property4 { get; set; }
public SomeOtherObject5 Property5 { get; set; }
public SomeOtherObject6 Property6 { get; set; }
}
public SomeOtherObject1 Property1 { get; set; }
public SomeOtherObject2 Property2 { get; set; }
public SomeOtherObject3 Property3 { get; set; }
public SomeOtherObject4 Property4 { get; set; }
public SomeOtherObject5 Property5 { get; set; }
public SomeOtherObject6 Property6 { get; set; }
}
并使用Visual Studio 的 Find And Replace with Regex将构造函数中突出显示的行从:
public SomeOtherObject1 Property1 { get; set; }
public SomeOtherObject2 Property2 { get; set; }
public SomeOtherObject3 Property3 { get; set; }
public SomeOtherObject4 Property4 { get; set; }
public SomeOtherObject5 Property5 { get; set; }
public SomeOtherObject6 Property6 { get; set; }
至:
this.Property1 = new SomeOtherObject1();
this.Property2 = new SomeOtherObject2();
this.Property3 = new SomeOtherObject3();
this.Property4 = new SomeOtherObject4();
this.Property5 = new SomeOtherObject5();
this.Property6 = new SomeOtherObject6();
首先我试过:
公共\s{:i}\s{:i}\s{\sget;\sset;\s}
这。\2 = 新 \1();
然后我想可能是线路问题,所以我尝试了:
^\s*public\s{:i}\s{:i}\s{\sget;\sset;\s}.$
这。\2 = 新 \1();
其他人对如何使它起作用有任何想法吗?