Exemplo n.º 1
0
        public void Handle(KAOSCoreElement element, ParsedElement attribute)
        {
            foreach (var builder in attributeBuilders)
            {
                var genericArguments = builder.GetType().BaseType.GetGenericArguments();

                if (genericArguments[0].IsAssignableFrom(element.GetType()) &&
                    genericArguments[1].IsAssignableFrom(attribute.GetType()))
                {
                    var method = builder.GetType().GetMethod("Handle", new[] { genericArguments[0], genericArguments[1], typeof(KAOSModel) });
                    if (method == null)
                    {
                        throw new Exception("Cannot find method Handle with generic parameters.");
                    }
                    try
                    {
                        method.Invoke(builder, new object[] { element, attribute, model });
                    }
                    catch (TargetInvocationException e)
                    {
                        Console.WriteLine(e.InnerException);
                        throw e.InnerException;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public UnsupportedValue(KAOSCoreElement element, ParsedAttribute attribute, object value)
     : base(string.Format("'{0}' is not supported in '{1}' on '{2}'",
                          value?.GetType()?.Name,
                          attribute?.GetType()?.Name,
                          element?.GetType()?.Name), attribute)
 {
 }
Exemplo n.º 3
0
        protected void Handle <U>(KAOSCoreElement element,
                                  U value,
                                  string propertyName)
        {
            var definitionProperty = element.GetType().GetProperty(propertyName);

            if (definitionProperty == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' has no property '{1}'",
                                                                  element.GetType(), propertyName));
            }

            if (definitionProperty.PropertyType != typeof(U))
            {
                throw new InvalidOperationException(string.Format("Type of property '{1}' in '{0}' is not '{2}'",
                                                                  element.GetType(), propertyName, typeof(T).Name));
            }

            definitionProperty.SetValue(element, value, null);
        }