本文整理汇总了C#中MethodData.ToCode方法的典型用法代码示例。如果您正苦于以下问题:C# MethodData.ToCode方法的具体用法?C# MethodData.ToCode怎么用?C# MethodData.ToCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodData
的用法示例。
在下文中一共展示了MethodData.ToCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToCode_given_ConstructorDataWithoutParameters_should_ReturnDefaultConstructorCode
public void ToCode_given_ConstructorDataWithoutParameters_should_ReturnDefaultConstructorCode()
{
// # Arrange.
var sut = new MethodData();
sut.Comment = new CommentData("Default constructor.");
sut.IsConstructor = true;
sut.Scope = Common.VisibilityScope.Public;
sut.Name = "MyClassName";
// # Act.
var res = sut.ToCode();
// # Assert.
Assert.AreEqual(5, res.Count);
CollectionAssert.AreEqual(
new[]
{
"/// <summary> Default constructor.",
"/// </summary>",
"public MyClassName()",
"{",
"}",
},
res.ToList());
}
示例2: ToCode_given_ConstructorDataWithBody_should_ReturnProper
public void ToCode_given_ConstructorDataWithBody_should_ReturnProper()
{
// # Arrange.
const string ClassName = "Customer";
var sut = new MethodData
{
IsConstructor = true,
Scope = Common.VisibilityScope.Internal,
Name = ClassName,
Parameters = new List<ParameterData>
{
new ParameterData
{
Name=ClassName,
SystemTypeString = ClassName
}
},
Body = new BodyData
{
Lines= new List<string>
{
"this.CustomerId = customer.CustomerId;",
"this.CustomerName = customer.CustomerName;"
}
}
};
// # Act.
var res = sut.ToCode();
// # Assert.
CollectionAssert.AreEqual(
new[]
{
"internal Customer( Customer customer )",
"{",
"\tthis.CustomerId = customer.CustomerId;",
"\tthis.CustomerName = customer.CustomerName;",
"}"
},
res.ToList());
}
示例3: ToCode_given_ConstructorDataWithParameters_should_ReturnProperConstrutor
public void ToCode_given_ConstructorDataWithParameters_should_ReturnProperConstrutor()
{
// # Arrange.
var sut = new MethodData
{
IsConstructor = true,
Scope = Common.VisibilityScope.Internal,
Name = "Customer",
Parameters = new List<ParameterData>
{
new ParameterData
{
Name="CustomerId",
SystemTypeString = typeof(int).ToString()
},
new ParameterData
{
Name="CustomerName",
SystemTypeString = typeof(string).ToString()
}
}
};
// # Act.
var res = sut.ToCode();
// # Assert.
CollectionAssert.AreEqual(
new[]
{
"internal Customer( System.Int32 customerId, System.String customerName )",
"{",
"\tthis.CustomerId = customerId;",
"\tthis.CustomerName = customerName;",
"}"
},
res.ToList());
}