Example #1
0
 /// <summary>
 /// Get Attribute for specified Typ
 /// </summary>
 /// <returns><see cref="Attribute{ValueType}"/></returns>
 public static IAttributeManagement GetAttributeManagementModel(IAttributeBase definition)
 {
     switch (definition.ControlledType)
     {
         case AttributeTypeEnum.Boolean:
             return new Attribute<bool?>(definition.Name, definition.Type, definition.IsTitle, definition.AttributeId, definition.SortOrder);
         case AttributeTypeEnum.DateTime:
             return new Attribute<DateTime?>(definition.Name, definition.Type, definition.IsTitle, definition.AttributeId, definition.SortOrder);
         case AttributeTypeEnum.Number:
             return new Attribute<decimal?>(definition.Name, definition.Type, definition.IsTitle, definition.AttributeId, definition.SortOrder);
         case AttributeTypeEnum.Entity:
             return new Attribute<EntityRelationship>(definition.Name, definition.Type, definition.IsTitle, definition.AttributeId, definition.SortOrder) { Values = new IValue[] { EntityRelationshipDefaultValue } };
         case AttributeTypeEnum.String:
         case AttributeTypeEnum.Hyperlink:
         case AttributeTypeEnum.Custom:
         default:
             return new Attribute<string>(definition.Name, definition.Type, definition.IsTitle, definition.AttributeId, definition.SortOrder);
     }
 }
 /// <summary>
 /// In case of an error, show a nicer, consistent message
 /// </summary>
 /// <param name="attributeDefinition"></param>
 /// <param name="foundValue"></param>
 private static Exception ValueMappingError(IAttributeBase attributeDefinition, object foundValue)
 => new Exception("Tried to create " + attributeDefinition.Name
                  + " and couldn't convert to correct "
                  + attributeDefinition.Type + ": '" +
                  foundValue + "'");
Example #3
0
 /// <summary>
 /// In case of an error, show a nicer, consistent message
 /// </summary>
 /// <param name="attributeDefinition"></param>
 /// <param name="foundValue"></param>
 private static void ThrowValueMappingError(IAttributeBase attributeDefinition, object foundValue)
 {
     throw new Exception("Tried to create " + attributeDefinition.Name + " and couldn't convert to correct " + attributeDefinition.Type + ": '" +
                         foundValue + "'");
 }