本文整理汇总了C#中CodeWriter.WriteAutomaticPropertyGetSet方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.WriteAutomaticPropertyGetSet方法的具体用法?C# CodeWriter.WriteAutomaticPropertyGetSet怎么用?C# CodeWriter.WriteAutomaticPropertyGetSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.WriteAutomaticPropertyGetSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteClassChild
private void WriteClassChild(CodeWriter writer, Association child, bool hasDuplicates, Database schema, GenerationContext context)
{
// the following is apparently useless
DbLinq.Schema.Dbml.Table targetTable = schema.Tables.FirstOrDefault(t => t.Type.Name == child.Type);
if (targetTable == null)
{
//Logger.Write(Level.Error, "ERROR L143 target table class not found:" + child.Type);
return;
}
var storageAttribute = NewAttributeDefinition<AssociationAttribute>();
storageAttribute["Storage"] = child.Storage;
storageAttribute["OtherKey"] = child.OtherKey;
storageAttribute["ThisKey"] = child.ThisKey;
storageAttribute["Name"] = child.Name;
SpecificationDefinition specifications;
if (child.AccessModifierSpecified)
specifications = GetSpecificationDefinition(child.AccessModifier);
else
specifications = SpecificationDefinition.Public;
if (child.ModifierSpecified)
specifications |= GetSpecificationDefinition(child.Modifier);
var propertyName = hasDuplicates
? child.Member + "_" + string.Join("", child.OtherKeys.ToArray())
: child.Member;
var propertyType = writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntitySet<>)), child.Type);
if (child.Storage != null)
writer.WriteField(SpecificationDefinition.Private, child.Storage, propertyType);
using (writer.WriteAttribute(storageAttribute))
using (writer.WriteAttribute(NewAttributeDefinition<DebuggerNonUserCodeAttribute>()))
using (writer.WriteProperty(specifications, propertyName,
writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntitySet<>)), child.Type)))
{
// if we have a backing field, use it
if (child.Storage != null)
{
// the getter returns the field
using (writer.WritePropertyGet())
{
writer.WriteLine(writer.GetReturnStatement(
child.Storage
));
}
// the setter assigns the field
using (writer.WritePropertySet())
{
writer.WriteLine(writer.GetStatement(
writer.GetAssignmentExpression(
child.Storage,
writer.GetPropertySetValueExpression())
));
}
}
// otherwise, use automatic property
else
writer.WriteAutomaticPropertyGetSet();
}
writer.WriteLine();
}
示例2: WriteClassPropertyAccessors
/// <summary>
/// Writes property accessor
/// </summary>
/// <param name="writer"></param>
/// <param name="property"></param>
/// <param name="relatedAssociations"></param>
/// <param name="context"></param>
protected virtual void WriteClassPropertyAccessors(CodeWriter writer, Column property, IEnumerable<Association> relatedAssociations, GenerationContext context)
{
//generate [Column(...)] attribute
var column = NewAttributeDefinition<ColumnAttribute>();
column["Storage"] = property.Storage;
column["Name"] = property.Name;
column["DbType"] = property.DbType;
// be smart: we only write attributes when they differ from the default values
var columnAttribute = new ColumnAttribute();
if (property.IsPrimaryKey != columnAttribute.IsPrimaryKey)
column["IsPrimaryKey"] = property.IsPrimaryKey;
if (property.IsDbGenerated != columnAttribute.IsDbGenerated)
column["IsDbGenerated"] = property.IsDbGenerated;
if (property.AutoSync != DbLinq.Schema.Dbml.AutoSync.Default)
column["AutoSync"] = new EnumFullname("AutoSync", property.AutoSync);
if (property.CanBeNull != columnAttribute.CanBeNull)
column["CanBeNull"] = property.CanBeNull;
if (property.Expression != null)
column["Expression"] = property.Expression;
var specifications = property.AccessModifierSpecified
? GetSpecificationDefinition(property.AccessModifier)
: SpecificationDefinition.Public;
if (property.ModifierSpecified)
specifications |= GetSpecificationDefinition(property.Modifier);
//using (WriteAttributes(writer, context.Parameters.MemberExposedAttributes))
using (WriteAttributes(writer, GetAttributeNames(context, context.Parameters.MemberAttributes)))
using (writer.WriteAttribute(NewAttributeDefinition<DebuggerNonUserCodeAttribute>()))
using (writer.WriteAttribute(column))
using (writer.WriteProperty(specifications, property.Member, GetTypeOrExtendedType(writer, property)))
{
// on auto storage, we're just lazy
if (property.Storage == null)
writer.WriteAutomaticPropertyGetSet();
else
{
using (writer.WritePropertyGet())
{
writer.WriteLine(writer.GetReturnStatement(writer.GetVariableExpression(property.Storage)));
}
using (writer.WritePropertySet())
{
WriteClassPropertyAccessorSet(writer, property, relatedAssociations, context);
}
}
}
}