Skip to content

Commit

Permalink
Reduce cognitive complexity in MetadataGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimontana82 committed Mar 23, 2024
1 parent 8cbfae9 commit a052d4b
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions src/FakeXrmEasy.Core/Metadata/MetadataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,46 @@ internal static AttributeMetadata CreateAttributeMetadata(Type propertyType)
}
else if (propertyType.IsGenericType)
{
Type genericType = propertyType.GetGenericArguments().FirstOrDefault();
return CreateAttributeMetadataFromGenericType(propertyType);
}
else if (typeof(BooleanManagedProperty) == propertyType)
{
var booleanManaged = new BooleanAttributeMetadata();
booleanManaged.SetSealedPropertyValue("AttributeType", AttributeTypeCode.ManagedProperty);
return booleanManaged;
}
#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013
else if (typeof(Guid) == propertyType)
{
return new UniqueIdentifierAttributeMetadata();
}
#endif
#if !FAKE_XRM_EASY
else if (typeof(byte[]) == propertyType)
{

return new ImageAttributeMetadata();
}
#endif
#if FAKE_XRM_EASY_9
else if (typeof(OptionSetValueCollection).IsAssignableFrom(propertyType))
{
return new MultiSelectPicklistAttributeMetadata();
}
else if (typeof(object) == propertyType)
{
return new FileAttributeMetadata();
}
#endif
else
{
throw new Exception($"Type {propertyType.Name} has not been mapped to an AttributeMetadata.");
}
}

internal static AttributeMetadata CreateAttributeMetadataFromGenericType(Type propertyType)
{
Type genericType = propertyType.GetGenericArguments().FirstOrDefault();
if (propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
if (typeof(int) == genericType)
Expand Down Expand Up @@ -262,43 +301,7 @@ internal static AttributeMetadata CreateAttributeMetadata(Type propertyType)
{
throw new Exception($"Type {propertyType.Name}{genericType?.Name} has not been mapped to an AttributeMetadata.");
}
}
else if (typeof(BooleanManagedProperty) == propertyType)
{
var booleanManaged = new BooleanAttributeMetadata();
booleanManaged.SetSealedPropertyValue("AttributeType", AttributeTypeCode.ManagedProperty);
return booleanManaged;
}
#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013
else if (typeof(Guid) == propertyType)
{
return new UniqueIdentifierAttributeMetadata();
}
#endif
#if !FAKE_XRM_EASY
else if (typeof(byte[]) == propertyType)
{

return new ImageAttributeMetadata();
}
#endif
#if FAKE_XRM_EASY_9
else if (typeof(OptionSetValueCollection).IsAssignableFrom(propertyType))
{
return new MultiSelectPicklistAttributeMetadata();
}
else if (typeof(object) == propertyType)
{

return new FileAttributeMetadata();
}
#endif
else
{
throw new Exception($"Type {propertyType.Name} has not been mapped to an AttributeMetadata.");
}
}

private static OneToManyRelationshipMetadata CreateOneToManyRelationshipMetadata(Type referencingEntity,
PropertyInfo referencingAttribute,
Type referencedEntity,
Expand Down

0 comments on commit a052d4b

Please sign in to comment.