private PropertyViewModel GetViewModelCore(IPropertyInfo property) { Type[] interfaces = property.GetType().GetInterfaces(); Type hasPredefinedValues = interfaces.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHavePredefinedValues <>)); if (hasPredefinedValues != null) { bool combinable = (bool)hasPredefinedValues.GetProperty(nameof(IHavePredefinedValues <bool> .IsValueCombinable)).GetValue(property); Type type = combinable ? typeof(CombinablePropertyViewModel <>).MakeGenericType(hasPredefinedValues.GenericTypeArguments[0]) : typeof(PredefinedValuesViewModel <>).MakeGenericType(hasPredefinedValues.GenericTypeArguments[0]); return((PropertyViewModel)Activator.CreateInstance(type, TargetPlatform, property, this.objEditors)); } else if (property.Type == typeof(object)) { return(new ObjectPropertyViewModel(EditorProvider, TargetPlatform, property, this.objEditors)); } if (ViewModelMap.TryGetValue(property.Type, out var vmFactory)) { return(vmFactory(TargetPlatform, property, this.objEditors)); } return(new StringPropertyViewModel(TargetPlatform, property, this.objEditors)); }
private PropertyViewModel CreateViewModel(IPropertyInfo property, PropertyVariation variant = null) { PropertyViewModel vm; Type[] interfaces = property.GetType().GetInterfaces(); Type hasPredefinedValues = interfaces.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHavePredefinedValues <>)); if (hasPredefinedValues != null) { bool combinable = (bool)hasPredefinedValues.GetProperty(nameof(IHavePredefinedValues <bool> .IsValueCombinable)).GetValue(property); Type type = combinable ? typeof(CombinablePropertyViewModel <>).MakeGenericType(hasPredefinedValues.GenericTypeArguments[0]) : typeof(PredefinedValuesViewModel <>).MakeGenericType(hasPredefinedValues.GenericTypeArguments[0]); vm = (PropertyViewModel)Activator.CreateInstance(type, TargetPlatform, property, this.objEditors, variant); } else if (ViewModelMap.TryGetValue(property.Type, out var vmFactory)) { vm = vmFactory(TargetPlatform, property, this.objEditors, variant); } else { vm = new StringPropertyViewModel(TargetPlatform, property, this.objEditors, variant); } vm.Parent = this; vm.VariantsChanged += OnVariantsChanged; return(vm); }