public override Type GetChildDataContextType(Type dataContext, Type parentDataContext, RedwoodControl control)
 {
     var type = control.GetType();
     var property = type.GetProperty(PropertyName);
     if (property == null) throw new Exception($"property { PropertyName } does not exists on { type.FullName }.");
     return property.GetValue(control).GetType();
 }
 public static Type GetDataContextType(Type parentDataContext, RedwoodControl control)
 {
     var dataContext = (control as RedwoodBindableControl)?.DataContext?.GetType() ?? parentDataContext;
     var attributes = control.GetType().GetCustomAttributes<DataContextChangeAttribute>();
     foreach (var attribute in attributes)
     {
         dataContext = attribute.GetChildDataContextType(dataContext, parentDataContext, control);
     }
     return dataContext;
 }
Esempio n. 3
0
 /// <summary>
 /// Finds the method on control.
 /// </summary>
 private static MethodInfo FindMethodOnControl(RedwoodControl targetControl, InvocationExpressionSyntax node)
 {
     MethodInfo method;
     var methods = targetControl.GetType().GetMethods().Where(m => m.Name == node.Expression.ToString()).ToList();
     if (methods.Count == 0)
     {
         throw new Exception(string.Format("The control '{0}' does not have a function '{1}'!", targetControl.GetType().FullName, node.Expression));
     }
     else if (methods.Count > 1)
     {
         throw new Exception(string.Format("The control '{0}' has more than one function called '{1}'! Overloading in {{controlCommand: ...}} binding is not yet supported!", targetControl.GetType().FullName, node.Expression));
     }
     method = methods[0];
     return method;
 }