Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8d80436

Browse files
committed
Use HasAttributeCached
1 parent d9c72dc commit 8d80436

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

src/ServiceStack.OrmLite.MySql/MySqlDialectProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public override string ToCreateSchemaStatement(string schemaName)
500500

501501
public override string GetColumnDefinition(FieldDefinition fieldDef)
502502
{
503-
if (fieldDef.PropertyInfo?.HasAttribute<TextAttribute>() == true)
503+
if (fieldDef.PropertyInfo?.HasAttributeCached<TextAttribute>() == true)
504504
{
505505
var sql = StringBuilderCache.Allocate();
506506
sql.AppendFormat("{0} {1}", GetQuotedName(NamingStrategy.GetColumnName(fieldDef.FieldName)), TextColumnDefinition);

src/ServiceStack.OrmLite.Oracle/Converters/OracleEnumConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class OracleEnumConverter : EnumConverter
88
{
99
public override string ToQuotedString(Type fieldType, object value)
1010
{
11-
if (fieldType.HasAttribute<EnumAsIntAttribute>())
11+
if (fieldType.HasAttributeCached<EnumAsIntAttribute>())
1212
{
1313
return this.ConvertNumber(fieldType.GetEnumUnderlyingType(), value).ToString();
1414
}
@@ -39,7 +39,7 @@ public override object ToDbValue(Type fieldType, object value)
3939
value = fieldType.GetEnumName(value);
4040
}
4141

42-
if (fieldType.HasAttribute<EnumAsIntAttribute>())
42+
if (fieldType.HasAttributeCached<EnumAsIntAttribute>())
4343
{
4444
if (value is string)
4545
{

src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public override object ToDbValue(object value, Type type)
178178
if (value == null || value is DBNull)
179179
return null;
180180

181-
if (type.IsEnum && !type.HasAttribute<EnumAsIntAttribute>())
181+
if (type.IsEnum && !type.HasAttributeCached<EnumAsIntAttribute>())
182182
return EnumConverter.ToDbValue(type, value);
183183

184184
if (type.IsRefType())

src/ServiceStack.OrmLite/Converters/SpecialConverters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void InitDbParam(IDbDataParameter p, Type fieldType)
2727

2828
public override string ToQuotedString(Type fieldType, object value)
2929
{
30-
var isEnumAsInt = fieldType.HasAttribute<EnumAsIntAttribute>();
30+
var isEnumAsInt = fieldType.HasAttributeCached<EnumAsIntAttribute>();
3131
if (isEnumAsInt)
3232
return this.ConvertNumber(Enum.GetUnderlyingType(fieldType), value).ToString();
3333

@@ -74,7 +74,7 @@ public static bool IsIntEnum(Type fieldType)
7474
{
7575
var isIntEnum = intEnums.GetOrAdd(fieldType, type =>
7676
type.IsEnumFlags() ||
77-
type.HasAttribute<EnumAsIntAttribute>() ||
77+
type.HasAttributeCached<EnumAsIntAttribute>() ||
7878
!type.IsEnum &&
7979
type.IsNumericType()); //i.e. is real int && not Enum)
8080

src/ServiceStack.OrmLite/OrmLiteConfigExtensions.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
7575
var objProperties = modelType.GetProperties(
7676
BindingFlags.Public | BindingFlags.Instance).ToList();
7777

78-
var hasPkAttr = objProperties.Any(p => p.HasAttribute<PrimaryKeyAttribute>());
78+
var hasPkAttr = objProperties.Any(p => p.HasAttributeCached<PrimaryKeyAttribute>());
7979

8080
var hasIdField = CheckForIdField(objProperties);
8181

@@ -107,15 +107,17 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
107107
: propertyInfo.PropertyType;
108108

109109
Type treatAsType = null;
110-
if (propertyType.IsEnumFlags() || propertyType.HasAttribute<EnumAsIntAttribute>())
110+
if (propertyType.IsEnumFlags() || propertyType.HasAttributeCached<EnumAsIntAttribute>())
111111
treatAsType = Enum.GetUnderlyingType(propertyType);
112+
else if (propertyType.HasAttributeCached<EnumAsCharAttribute>())
113+
treatAsType = typeof(char);
112114

113115
var isReference = referenceAttr != null && propertyType.IsClass;
114-
var isIgnored = propertyInfo.HasAttribute<IgnoreAttribute>() || isReference;
116+
var isIgnored = propertyInfo.HasAttributeCached<IgnoreAttribute>() || isReference;
115117

116118
var isFirst = !isIgnored && i++ == 0;
117119

118-
var isAutoId = propertyInfo.HasAttribute<AutoIdAttribute>();
120+
var isAutoId = propertyInfo.HasAttributeCached<AutoIdAttribute>();
119121

120122
var isPrimaryKey = (!hasPkAttr && (propertyInfo.Name == OrmLiteConfig.IdField || (!hasIdField && isFirst)))
121123
|| propertyInfo.HasAttributeNamed(typeof(PrimaryKeyAttribute).Name)
@@ -149,21 +151,21 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
149151
IsPrimaryKey = isPrimaryKey,
150152
AutoIncrement =
151153
isPrimaryKey &&
152-
propertyInfo.HasAttribute<AutoIncrementAttribute>(),
154+
propertyInfo.HasAttributeCached<AutoIncrementAttribute>(),
153155
AutoId = isAutoId,
154156
IsIndexed = !isPrimaryKey && isIndex,
155157
IsUniqueIndex = isUnique,
156158
IsClustered = indexAttr?.Clustered == true,
157159
IsNonClustered = indexAttr?.NonClustered == true,
158160
IndexName = indexAttr?.Name,
159161
IsRowVersion = isRowVersion,
160-
IgnoreOnInsert = propertyInfo.HasAttribute<IgnoreOnInsertAttribute>(),
161-
IgnoreOnUpdate = propertyInfo.HasAttribute<IgnoreOnUpdateAttribute>(),
162-
ReturnOnInsert = propertyInfo.HasAttribute<ReturnOnInsertAttribute>(),
162+
IgnoreOnInsert = propertyInfo.HasAttributeCached<IgnoreOnInsertAttribute>(),
163+
IgnoreOnUpdate = propertyInfo.HasAttributeCached<IgnoreOnUpdateAttribute>(),
164+
ReturnOnInsert = propertyInfo.HasAttributeCached<ReturnOnInsertAttribute>(),
163165
FieldLength = stringLengthAttr?.MaximumLength,
164166
DefaultValue = defaultValueAttr?.DefaultValue,
165167
CheckConstraint = chkConstraintAttr?.Constraint,
166-
IsUniqueConstraint = propertyInfo.HasAttribute<UniqueAttribute>(),
168+
IsUniqueConstraint = propertyInfo.HasAttributeCached<UniqueAttribute>(),
167169
ForeignKey = fkAttr == null
168170
? referencesAttr != null ? new ForeignKeyConstraint(referencesAttr.Type) : null
169171
: new ForeignKeyConstraint(fkAttr.Type, fkAttr.OnDelete, fkAttr.OnUpdate, fkAttr.ForeignKeyName),

0 commit comments

Comments
 (0)