public TypeScriptProperty(PropertyInfo propertyInfo) { PropertyInfo = propertyInfo; DataModelPropertyAttribute dataModelPropertyAttribute = propertyInfo.GetCustomAttribute <DataModelPropertyAttribute>(); Name = propertyInfo.Name; Comment = dataModelPropertyAttribute?.Description; Type propertyType = propertyInfo.PropertyType; if (!propertyType.IsGenericType) { Type = GetTypeScriptType(propertyType); } else { Type genericTypeDefinition = propertyType.GetGenericTypeDefinition(); if (genericTypeDefinition == typeof(Nullable <>)) { Type = GetTypeScriptType(propertyType.GenericTypeArguments[0]); Name += "?"; } else { string stripped = genericTypeDefinition.Name.Split('`')[0]; Type = $"{stripped}<{string.Join(", ", propertyType.GenericTypeArguments.Select(t => GetTypeScriptType(t)))}>"; } } }
public DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action <object, bool> updateCallback) { lock (_registeredDataModelEditors) { // Prefer a VM that natively supports the type DataModelVisualizationRegistration match = _registeredDataModelEditors.FirstOrDefault(d => d.SupportedType == propertyType); // Fall back on a VM that supports the type through conversion if (match == null) { match = _registeredDataModelEditors.FirstOrDefault(d => d.CompatibleConversionTypes.Contains(propertyType)); } // Lastly try getting an enum VM if the provided type is an enum if (match == null && propertyType.IsEnum) { match = _registeredDataModelEditors.FirstOrDefault(d => d.SupportedType == typeof(Enum)); } if (match != null) { DataModelInputViewModel viewModel = InstantiateDataModelInputViewModel(match, description, initialValue); viewModel.UpdateCallback = updateCallback; return(viewModel); } return(null); } }
internal DataModelStaticViewModel(Type targetType, DataModelPropertyAttribute targetDescription, IDataModelUIService dataModelUIService) { _dataModelUIService = dataModelUIService; _rootView = Application.Current.Windows.OfType <Window>().SingleOrDefault(x => x.IsActive); TargetType = targetType; TargetDescription = targetDescription; IsEnabled = TargetType != null; DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), TargetDescription, true); if (_rootView != null) { _rootView.MouseUp += RootViewOnMouseUp; _rootView.KeyUp += RootViewOnKeyUp; } }
/// <summary> /// Creates a new instance of the <see cref="DataModelInputViewModel{T}" /> class /// </summary> /// <param name="targetDescription">The description of the property this input VM is representing</param> /// <param name="initialValue">The initial value to set the input value to</param> protected DataModelInputViewModel(DataModelPropertyAttribute targetDescription, T initialValue) { TargetDescription = targetDescription; InputValue = initialValue; }
public IntDataModelInputViewModel(DataModelPropertyAttribute targetDescription, int initialValue) : base(targetDescription, initialValue) { }
public SKColorDataModelInputViewModel(DataModelPropertyAttribute targetDescription, SKColor initialValue) : base(targetDescription, initialValue) { }
private DataModelInputViewModel InstantiateDataModelInputViewModel(DataModelVisualizationRegistration registration, DataModelPropertyAttribute description, object initialValue) { // The view models expecting value types shouldn't be given null, avoid that if (registration.SupportedType.IsValueType) { if (initialValue == null) { initialValue = Activator.CreateInstance(registration.SupportedType); } } // This assumes the type can be converted, that has been checked when the VM was created if (initialValue != null && initialValue.GetType() != registration.SupportedType) { initialValue = Convert.ChangeType(initialValue, registration.SupportedType); } IParameter[] parameters = new IParameter[] { new ConstructorArgument("targetDescription", description), new ConstructorArgument("initialValue", initialValue) }; DataModelInputViewModel viewModel = (DataModelInputViewModel)registration.PluginInfo.Kernel.Get(registration.ViewModelType, parameters); viewModel.CompatibleConversionTypes = registration.CompatibleConversionTypes; return(viewModel); }
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription) { return(_kernel.Get <DataModelStaticViewModel>(new ConstructorArgument("targetType", targetType), new ConstructorArgument("targetDescription", targetDescription))); }
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, DataModelPropertyAttribute description, bool fallBackToDefault) { lock (_registeredDataModelDisplays) { DataModelDisplayViewModel result; DataModelVisualizationRegistration match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType); if (match != null) { result = (DataModelDisplayViewModel)match.PluginInfo.Kernel.Get(match.ViewModelType); } else if (!fallBackToDefault) { result = null; } else { result = _kernel.Get <DefaultDataModelDisplayViewModel>(); } if (result != null) { result.PropertyDescription = description; } return(result); } }
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription) { return(_dataModelVmFactory.DataModelStaticViewModel(targetType, targetDescription)); }
public EnumDataModelInputViewModel(DataModelPropertyAttribute targetDescription, Enum initialValue) : base(targetDescription, initialValue) { EnumValues = new BindableCollection <ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(initialValue.GetType())); }
private void DetermineDynamicType(object dynamicDataModel, DataModelPropertyAttribute attribute) { Type = DataModelPathSegmentType.Dynamic; _dynamicDataModelType = dynamicDataModel.GetType(); _dynamicDataModelAttribute = attribute; }