本文整理汇总了C#中CodeWriter.GetLiteralType方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.GetLiteralType方法的具体用法?C# CodeWriter.GetLiteralType怎么用?C# CodeWriter.GetLiteralType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.GetLiteralType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteClassParent
//.........这里部分代码省略.........
// 1.2. or HasLoadedOrAssignedValue is false (but why?)
// 2. implementations before change
// 3. if previous value not null
// 3.1. place parent in temp variable
// 3.2. set [Storage].Entity to null
// 3.3. remove it from parent list
// 4. assign value to [Storage].Entity
// 5. if value is not null
// 5.1. add it to parent list
// 5.2. set FK members with entity keys
// 6. else
// 6.1. set FK members to defaults (null or 0)
// 7. implementationas after change
//writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(storage, writer.GetPropertySetValueExpression())));
var entityMember = writer.GetMemberExpression(parent.Storage, "Entity");
// 1.1
using (writer.WriteIf(writer.GetDifferentExpression(writer.GetPropertySetValueExpression(),
entityMember)))
{
var otherAssociation = schema.GetReverseAssociation(parent);
// 2. code before the change
// TODO change interface to require a member instead of a column
//foreach (IImplementation implementation in context.Implementations())
// implementation.WritePropertyBeforeSet(writer, ???, context);
// 3.
using (writer.WriteIf(writer.GetDifferentExpression(entityMember, writer.GetNullExpression())))
{
var previousEntityRefName = "previous" + parent.Type;
// 3.1.
writer.WriteLine(writer.GetStatement(
writer.GetVariableDeclarationInitialization(parent.Type, previousEntityRefName, entityMember)
));
// 3.2.
writer.WriteLine(writer.GetStatement(
writer.GetAssignmentExpression(entityMember, writer.GetNullExpression())
));
// 3.3.
writer.WriteLine(writer.GetStatement(
writer.GetMethodCallExpression(
writer.GetMemberExpression(writer.GetMemberExpression(previousEntityRefName, otherAssociation.Member), "Remove"),
writer.GetThisExpression())
));
}
// 4.
writer.WriteLine(writer.GetStatement(
writer.GetAssignmentExpression(entityMember, writer.GetPropertySetValueExpression())
));
// 5. if value is null or not
writer.WriteRawIf(writer.GetDifferentExpression(writer.GetPropertySetValueExpression(), writer.GetNullExpression()));
// 5.1.
writer.WriteLine(writer.GetStatement(
writer.GetMethodCallExpression(
writer.GetMemberExpression(writer.GetMemberExpression(writer.GetPropertySetValueExpression(), otherAssociation.Member), "Add"),
writer.GetThisExpression())
));
// 5.2
var table = schema.Tables.Single(t => t.Type.Associations.Contains(parent));
var childKeys = parent.TheseKeys.ToArray();
var childColumns = (from ck in childKeys select table.Type.Columns.Single(c => c.Member == ck))
.ToArray();
var parentKeys = parent.OtherKeys.ToArray();
for (int keyIndex = 0; keyIndex < parentKeys.Length; keyIndex++)
{
writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(
childColumns[keyIndex].Storage ?? childColumns[keyIndex].Member,
writer.GetMemberExpression(writer.GetPropertySetValueExpression(), parentKeys[keyIndex])
)));
}
// 6.
writer.WriteRawElse();
// 6.1.
for (int keyIndex = 0; keyIndex < parentKeys.Length; keyIndex++)
{
var column = table.Type.Columns.Single(c => c.Member == childKeys[keyIndex]);
var columnType = System.Type.GetType(column.Type);
var columnLiteralType = columnType != null ? writer.GetLiteralType(columnType) : column.Type;
writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(
childColumns[keyIndex].Storage ?? childColumns[keyIndex].Member,
column.CanBeNull ? writer.GetNullExpression() : writer.GetNullValueExpression(columnLiteralType)
)));
}
writer.WriteRawEndif();
// 7. code after change
// TODO change interface to require a member instead of a column
//foreach (IImplementation implementation in context.Implementations())
// implementation.WritePropertyAfterSet(writer, ???, context);
}
}
}
writer.WriteLine();
}
示例2: GetTypeOrExtendedType
protected virtual string GetTypeOrExtendedType(CodeWriter writer, Column property)
{
object extendedType = property.ExtendedType;
var enumType = extendedType as EnumType;
if (enumType != null)
return writer.GetEnumType(enumType.Name);
return writer.GetLiteralType(GetType(property.Type, property.CanBeNull));
}
示例3: 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
|| primaryKey.ExtendedType == null
|| 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.GetLiteralType(typeof(object)), "Equals"),
member,
writer.GetMemberExpression(other, member));
if (string.IsNullOrEmpty(andExpression))
andExpression = primaryKeyTest;
else
andExpression = writer.GetAndExpression(andExpression, primaryKeyTest);
}
writer.WriteLine(writer.GetReturnStatement(andExpression));
}
}
}
示例4: WriteClassHeader
private const string ModifiedName = "IsModified"; // mandatory value, since the IModified interface requires this member
public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
{
writer.WriteCommentLine("IModified backing field");
writer.WritePropertyWithBackingField(SpecificationDefinition.Public, ModifiedName, writer.GetLiteralType(typeof(bool)));
writer.WriteLine();
}
示例5: WriteProcedureBodyReturnValue
protected virtual void WriteProcedureBodyReturnValue(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, string result, GenerationContext context)
{
Type returnType = GetProcedureType(procedure);
if (returnType != null)
writer.WriteLine(writer.GetReturnStatement(writer.GetCastExpression(writer.GetMemberExpression(result, "ReturnValue"), writer.GetLiteralType(returnType), true)));
}