本文整理汇总了C#中CodeWriter.WriteMethod方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.WriteMethod方法的具体用法?C# CodeWriter.WriteMethod怎么用?C# CodeWriter.WriteMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.WriteMethod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteClassHeader
public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
{
using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanging).Name)))
{
const string eventName = "PropertyChanging"; // do not change, part of INotifyPropertyChanging
const string emptyArgs = "emptyChangingEventArgs";
// event
writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangingEventHandler).Name);
writer.WriteLine();
// empty event arg
writer.WriteField(SpecificationDefinition.Private | SpecificationDefinition.Static,
writer.GetAssignmentExpression(emptyArgs, writer.GetNewExpression(
writer.GetMethodCallExpression(typeof(PropertyChangingEventArgs).Name, "\"\""))),
typeof(PropertyChangingEventArgs).Name);
// method
using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual,
sendPropertyChangingMethod, null))
{
using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression())))
{
writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName,
writer.GetThisExpression(), emptyArgs)));
}
}
}
}
示例2: WriteDataContextProcedure
private void WriteDataContextProcedure(CodeWriter writer, Function procedure, GenerationContext context)
{
if (procedure == null || procedure.Name == null)
{
//Logger.Write(Level.Error, "CodeGenStoredProc: Error L33 Invalid storedProcedure object");
writer.WriteCommentLine("error L33 Invalid storedProcedure object");
return;
}
var functionAttribute = NewAttributeDefinition<FunctionAttribute>();
functionAttribute["Name"] = procedure.Name;
functionAttribute["IsComposable"] = procedure.IsComposable;
SpecificationDefinition specifications;
if (procedure.AccessModifierSpecified)
specifications = GetSpecificationDefinition(procedure.AccessModifier);
else
specifications = SpecificationDefinition.Public;
if (procedure.ModifierSpecified)
specifications |= GetSpecificationDefinition(procedure.Modifier);
using (writer.WriteAttribute(functionAttribute))
using (writer.WriteMethod(specifications, GetProcedureName(procedure),
GetProcedureType(procedure), GetProcedureParameters(procedure)))
{
string result = WriteProcedureBodyMethodCall(writer, procedure, context);
WriteProcedureBodyOutParameters(writer, procedure, result, context);
WriteProcedureBodyReturnValue(writer, procedure, result, context);
}
writer.WriteLine();
}
示例3: WriteClassHeader
public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
{
using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanged).Name)))
{
const string eventName = "PropertyChanged"; // do not change, part of INotifyPropertyChanged
const string propertyNameName = "propertyName";
// event
writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangedEventHandler).Name);
writer.WriteLine();
// method
using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual,
sendPropertyChangedMethod, null, new ParameterDefinition { Name = propertyNameName, Type = typeof(string) }))
{
using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression())))
{
writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName,
writer.GetThisExpression(),
writer.GetNewExpression(writer.GetMethodCallExpression(typeof(PropertyChangedEventArgs).Name,
propertyNameName)))));
}
}
}
}
示例4: WriteClassEqualsAndHash
protected virtual void WriteClassEqualsAndHash(CodeWriter writer, Table table, GenerationContext context)
{
List<DbLinq.Schema.Dbml.Column> primaryKeys = table.Type.Columns.Where(c => c.IsPrimaryKey).ToList();
if (primaryKeys.Count == 0)
{
writer.WriteLine("#warning L189 table {0} has no primary key. Multiple C# objects will refer to the same row.",
table.Name);
return;
}
using (writer.WriteRegion(string.Format("GetHashCode(), Equals() - uses column {0} to look up objects in liveObjectMap",
string.Join(", ", primaryKeys.Select(pk => pk.Member).ToList().ToArray()))))
{
// GetHashCode
using (writer.WriteMethod(SpecificationDefinition.Public | SpecificationDefinition.Override,
"GetHashCode", typeof(int)))
{
string hashCode = null;
foreach (var primaryKey in primaryKeys)
{
var member = writer.GetVariableExpression(primaryKey.Storage);
string primaryKeyHashCode = writer.GetMethodCallExpression(writer.GetMemberExpression(member, "GetHashCode"));
if (primaryKey.CanBeNull
|| GetType(primaryKey.Type, false).IsClass) // this patch to ensure that even if DB does not allow nulls,
// our in-memory object won't generate a fault
{
var isNullExpression = writer.GetEqualExpression(member, writer.GetNullExpression());
var nullExpression = writer.GetLiteralValue(0);
primaryKeyHashCode = "(" + writer.GetTernaryExpression(isNullExpression, nullExpression, primaryKeyHashCode) + ")";
}
if (string.IsNullOrEmpty(hashCode))
hashCode = primaryKeyHashCode;
else
hashCode = writer.GetXOrExpression(hashCode, primaryKeyHashCode);
}
writer.WriteLine(writer.GetReturnStatement(hashCode));
}
writer.WriteLine();
// Equals
string otherAsObject = "o";
using (writer.WriteMethod(SpecificationDefinition.Public | SpecificationDefinition.Override,
"Equals", typeof(bool), new ParameterDefinition { Type = typeof(object), Name = otherAsObject }))
{
string other = "other";
writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(
writer.GetDeclarationExpression(other, table.Type.Name),
writer.GetCastExpression(otherAsObject, table.Type.Name,
false))));
using (writer.WriteIf(writer.GetEqualExpression(other, writer.GetNullExpression())))
{
writer.WriteLine(writer.GetReturnStatement(writer.GetLiteralValue(false)));
}
string andExpression = null;
foreach (var primaryKey in primaryKeys)
{
var member = writer.GetVariableExpression(primaryKey.Storage);
string primaryKeyTest = writer.GetMethodCallExpression(
writer.GetMemberExpression(
writer.GetMemberExpression(
writer.GetGenericName("System.Collections.Generic.EqualityComparer", primaryKey.Type),
"Default"),
"Equals"),
member,
writer.GetMemberExpression(other, member));
if (string.IsNullOrEmpty(andExpression))
andExpression = primaryKeyTest;
else
andExpression = writer.GetAndExpression(andExpression, primaryKeyTest);
}
writer.WriteLine(writer.GetReturnStatement(andExpression));
}
}
}
示例5: WriteClassChildrenAttachment
/// <summary>
/// Writes attach/detach method
/// </summary>
/// <param name="writer"></param>
/// <param name="table"></param>
/// <param name="schema"></param>
/// <param name="context"></param>
protected virtual void WriteClassChildrenAttachment(CodeWriter writer, Table table, Database schema, GenerationContext context)
{
var children = GetClassChildren(table).ToList();
if (children.Count > 0)
{
using (writer.WriteRegion("Attachement handlers"))
{
foreach (var child in children)
{
// the reverse child is the association seen from the child
// we're going to use it...
var reverseChild = schema.GetReverseAssociation(child);
// ... to get the parent name
var memberName = reverseChild.Member;
var entityParameter = new ParameterDefinition { Name = "entity", LiteralType = child.Type };
// the Attach event handler sets the child entity parent to "this"
using (writer.WriteMethod(SpecificationDefinition.Private, GetChildAttachMethodName(child),
null, entityParameter))
{
writer.WriteLine(
writer.GetStatement(
writer.GetAssignmentExpression(
writer.GetMemberExpression(entityParameter.Name, memberName),
writer.GetThisExpression())));
}
writer.WriteLine();
// the Detach event handler sets the child entity parent to null
using (writer.WriteMethod(SpecificationDefinition.Private, GetChildDetachMethodName(child),
null, entityParameter))
{
writer.WriteLine(
writer.GetStatement(
writer.GetAssignmentExpression(
writer.GetMemberExpression(entityParameter.Name, memberName),
writer.GetNullExpression())));
}
writer.WriteLine();
}
}
}
}