public FacadeType(Type viewType, Type modelType)
        {
            ViewType  = viewType;
            ModelType = modelType;
            var depprops = (from field in ViewType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                            where field.FieldType == typeof(DependencyProperty) && field.Name.EndsWith("Property")
                            select(DependencyProperty) field.GetValue(null)).ToList();
            var members = new List <FacadeMapping>();

            foreach (var dep in depprops)
            {
                FacadeMember member   = null;
                var          property = ModelType.GetProperty(dep.Name);
                if (property != null)
                {
                    member = new FacadeProperty(property);
                }
                var field = ModelType.GetField(dep.Name);
                if (field != null)
                {
                    member = new FacadeField(field);
                }
                if (member != null)
                {
                    member = FacadeObservable.Unwrap(member);
                    members.Add(FacadeCollection.TryMap(dep, member) ?? new FacadeScalar(dep, member));
                }
            }
            Members        = members.ToArray();
            ByViewProperty = members.ToDictionary(m => m.ViewProperty);
        }
Esempio n. 2
0
 public static FacadeMember Unwrap(FacadeMember member)
 {
     if (member.MemberType.IsGenericType && typeof(Observable <>).IsAssignableFrom(member.MemberType.GetGenericTypeDefinition()))
     {
         return(new FacadeObservable(member));
     }
     return(member);
 }
 public FacadeScalar(DependencyProperty controlProp, FacadeMember modelProp)
     : base(controlProp, modelProp)
 {
     if (ModelProperty.MemberType != ViewProperty.PropertyType)
     {
         throw new ArgumentException("Type in model is incompatible with type in view: " + this);
     }
     if (!ModelProperty.CanWrite)
     {
         throw new ArgumentException("Model field/property must be writable: " + this);
     }
 }
        public static FacadeMapping TryMap(DependencyProperty controlProp, FacadeMember modelProp)
        {
            if (typeof(IList).IsAssignableFrom(modelProp.MemberType))
            {
                return(new FacadeCollection(controlProp, modelProp, obj => obj as IList));
            }
            var iface = modelProp.MemberType.GetInterfaces().FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IList <>));

            if (iface != null)
            {
                var adaptorType = typeof(FacadeListAdaptor <>).MakeGenericType(iface.GetGenericArguments()[0]);
                return(new FacadeCollection(controlProp, modelProp, obj => obj != null ? (IList)Activator.CreateInstance(adaptorType, obj) : null));
            }
            return(null);
        }
 FacadeCollection(DependencyProperty controlProp, FacadeMember modelProp, Func <object, IList> targetConverter) : base(controlProp, modelProp)
 {
     TargetConverter = targetConverter;
 }
Esempio n. 6
0
 FacadeObservable(FacadeMember underlying)
 {
     UnderlyingMember = underlying;
     ValueProperty    = underlying.MemberType.GetProperty("Value");
 }
Esempio n. 7
0
 public FacadeMapping(DependencyProperty controlProp, FacadeMember modelProp)
 {
     ViewProperty  = controlProp;
     ModelProperty = modelProp;
 }