本文整理汇总了C#中CodeWriter.WriteCtor方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.WriteCtor方法的具体用法?C# CodeWriter.WriteCtor怎么用?C# CodeWriter.WriteCtor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.WriteCtor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteDataContextCtor
protected virtual bool WriteDataContextCtor(CodeWriter writer, Database schema, Type contextBaseType,
ParameterDefinition[] parameters, string[] baseCallParameterNames, Type[] baseCallParameterTypes,
GenerationContext context)
{
// if we have a contextBaseType, then check that we can do it
if (contextBaseType != null)
{
var ctor = contextBaseType.GetConstructor(baseCallParameterTypes);
if (ctor == null)
return false;
}
using (writer.WriteCtor(SpecificationDefinition.Public, schema.Class, parameters, baseCallParameterNames))
{
writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("OnCreated")));
}
writer.WriteLine();
return true;
}
示例2: WriteClassCtor
/// <summary>
/// Writes class ctor.
/// EntitySet initializations
/// </summary>
/// <param name="writer"></param>
/// <param name="table"></param>
/// <param name="schema"></param>
/// <param name="context"></param>
protected virtual void WriteClassCtor(CodeWriter writer, Table table, Database schema, GenerationContext context)
{
using (writer.WriteRegion("ctor"))
using (writer.WriteCtor(SpecificationDefinition.Public, table.Type.Name, new ParameterDefinition[0], null))
{
// children are EntitySet
foreach (var child in GetClassChildren(table))
{
// if the association has a storage, we use it. Otherwise, we use the property name
var entitySetMember = child.Storage ?? child.Member;
writer.WriteLine(writer.GetStatement(
writer.GetAssignmentExpression(
entitySetMember,
writer.GetNewExpression(writer.GetMethodCallExpression(
writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntitySet<>)), child.Type),
GetChildAttachMethodName(child),
GetChildDetachMethodName(child)
))
)
));
}
// the parents are the entities referenced by a FK. So a "parent" is an EntityRef
foreach (var parent in GetClassParents(table))
{
var entityRefMember = parent.Storage;
writer.WriteLine(writer.GetStatement(
writer.GetAssignmentExpression(
entityRefMember,
writer.GetNewExpression(writer.GetMethodCallExpression(
writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntityRef<>)), parent.Type)
))
)
));
}
writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("OnCreated")));
}
}