private void InitListWidget(Widget widget) { var type = widget.ListType ?? ModelUtils.ResolveType(widget.ListId); var widgetOptionsType = typeof(WidgetOptions <>).MakeGenericType(type); var listOptionsType = typeof(ListOptions <>).MakeGenericType(type); var listResultType = typeof(ListResult <>).MakeGenericType(type); var listRecordType = typeof(ListRecord <>).MakeGenericType(type); var listNavigateCommandType = typeof(Command <>).MakeGenericType(listRecordType); var widgetOptions = Activator.CreateInstance(widgetOptionsType); var listOptions = Activator.CreateInstance(listOptionsType); var listResults = Activator.CreateInstance(listResultType); var listOptionsIsLoadingProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("IsLoading"); listOptionsIsLoadingProperty?.SetValue(listOptions, false); var listOptionsLoadedProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("Loaded"); listOptionsLoadedProperty?.SetValue(listOptions, false); var listOptionsListResultsProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("ListResults"); listOptionsListResultsProperty?.SetValue(listOptions, listResults); var widgetOptionslistOptionsProperty = widgetOptionsType.GetTypeInfo().GetDeclaredProperty("ListOptions"); widgetOptionslistOptionsProperty?.SetValue(widgetOptions, listOptions); WidgetOptions.Add(widgetOptions); }
private void LoadListWidget(Widget widget, int index) { var type = widget.ListType ?? ModelUtils.ResolveType(widget.ListId); var getListOptionsMethod = GetType().GetTypeInfo().DeclaredMethods.FirstOrDefault(s => s.Name == "GetListOptions"); var genericGetListOptionsMethod = getListOptionsMethod.MakeGenericMethod(type); var widgetOptionsType = typeof(WidgetOptions <>).MakeGenericType(type); var listOptionsType = typeof(ListOptions <>).MakeGenericType(type); var listResultType = typeof(ListResult <>).MakeGenericType(type); var listRecordType = typeof(ListRecord <>).MakeGenericType(type); var listNavigateCommandType = typeof(Command <>).MakeGenericType(listRecordType); var widgetOptions = Activator.CreateInstance(widgetOptionsType); var listOptions = Activator.CreateInstance(listOptionsType); var listResults = Activator.CreateInstance(listResultType); var views = new WidgetView[] { new WidgetView { TitleProperty = new WidgetProperty { PropertyName = "Title" } } }; var listOptionsIsLoadingProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("IsLoading"); listOptionsIsLoadingProperty?.SetValue(listOptions, false); var listOptionsLoadedProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("Loaded"); listOptionsLoadedProperty?.SetValue(listOptions, false); var listOptionsListResultsProperty = listOptionsType.GetTypeInfo().GetDeclaredProperty("ListResults"); listOptionsListResultsProperty?.SetValue(listOptions, listResults); var widgetOptionslistOptionsProperty = widgetOptionsType.GetTypeInfo().GetDeclaredProperty("ListOptions"); widgetOptionslistOptionsProperty?.SetValue(widgetOptions, listOptions); WidgetOptions.Add(widgetOptions); var result = genericGetListOptionsMethod.Invoke(this, new object[] { widget, index }); }