예제 #1
0
        public static void CheckCompatibility(this ICase targetCase, AttributeSchema attribute)
        {
            var caseAttribute = targetCase.Schema.TryGetAttribute(attribute.Name) ??
                                throw new ArgumentException($"Cases are incompatible, attribute {attribute.Name} is missing.");

            if (caseAttribute.Type != attribute.Type)
            {
                throw new ArgumentException($"Cases are incompatible, expected {attribute.Type} type for attribute {attribute.Name}.");
            }
        }
예제 #2
0
        private AttributeDefinition GetSchemaDefinition(AttributeSchema schema, IEnumerable <PropertyInfo> properties)
        {
            var schemaProperty = properties.FirstOrDefault(p => p.Name == schema.Name);

            if (schemaProperty == null)
            {
                throw new InvalidOperationException($"Type {targetType} should contain public member {schema.Name}");
            }
            if (schemaProperty.PropertyType != schema.Type)
            {
                throw new ArgumentException($"Property type {schemaProperty.PropertyType} differs from schema type {schema.Type}");
            }

            return(new AttributeDefinition(schemaProperty.Name, schemaProperty.PropertyType, schemaProperty));
        }
예제 #3
0
        public static T GetAttribute <T>(this ICase targetCase, AttributeSchema attribute)
        {
            if (targetCase == null)
            {
                throw new ArgumentNullException(nameof(targetCase));
            }
            if (attribute.Type != typeof(T))
            {
                throw new ArgumentOutOfRangeException($"Attribute {attribute.Name} type is {attribute.Type}.");
            }

            T   value  = default;
            var getter = targetCase.GetAttributeGetter <T>(attribute);

            getter(ref value);
            return(value);
        }