예제 #1
0
        internal ViewModelInstance(INotifyPropertyChanged viewModel, ViewModelDefinition viewModelDefinition, BrowserBridge browser)
        {
            this.viewModel = viewModel;
            this.browser = browser;
            this.viewModelDefinition = viewModelDefinition;
            scriptId = id.ToString().Replace("{", "").Replace("}", "").Replace("-", "");

            browser.ExecuteScriptFunction("createInstance", new string[] { viewModelDefinition.BindableName, scriptId });
        }
예제 #2
0
 public void BindViewModel(INotifyPropertyChanged viewModel, BrowserBridge browser)
 {
     ViewModelDefinition definition = GetViewModelDefinition(viewModel.GetType());
     if (definition == null)
     {
         definition = new ViewModelDefinition(viewModel.GetType(), viewModel.GetType().Name);
         StringBuilder sb = new StringBuilder();
         List<ViewModelDefinition> allDefs = new List<ViewModelDefinition>();
         definition.CollectViewModelDefinitions(allDefs);
         foreach (ViewModelDefinition child in allDefs)
             child.DefineInBrowser(sb);
         InjectFramework(sb);
         browser.InsertScript(sb.ToString());
     }
 }
예제 #3
0
 internal void RegisterViewModelDefinition(Type viewModelType, ViewModelDefinition definition)
 {
     viewModelDefinitions[viewModelType] = definition;
 }
예제 #4
0
        public ViewModelDefinition(Type viewModelType, string bindableName)
        {
            SpinnakerConfiguration.CurrentConfig.ViewModelManager.RegisterViewModelDefinition(viewModelType, this);

            this.viewModelType = viewModelType;
            this.bindableName = bindableName;

            foreach (PropertyInfo propInfo in viewModelType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                bool include = true;
                foreach(object o in propInfo.GetCustomAttributes(true))
                {
                    if (o is Newtonsoft.Json.JsonIgnoreAttribute)
                        include = false;
                    else
                    {
                        ViewModelBinding a = o as ViewModelBinding;
                        if (a != null)
                            include = a.Binding != Binding.NotBound;
                    }
                }
                if (include)
                {
                    ExposedProperty prop = new ExposedProperty(viewModelType, propInfo);

                    if (IsTypeEnumerableViewModels(prop.PropertyType))
                    {
                        Type itemType = propInfo.PropertyType.GetGenericArguments()[0];
                        prop.CollectionType = itemType;
                        ViewModelDefinition childDefinition = SpinnakerConfiguration.CurrentConfig.ViewModelManager.GetViewModelDefinition(itemType);
                        if (childDefinition == null)
                            childDefinition = new ViewModelDefinition(itemType, itemType.Name);
                        childViewModels[propInfo.Name] = childDefinition;
                    }
                    exposedProperties[prop.Name] = prop;
                    if (typeof(INotifyPropertyChanged).IsAssignableFrom(propInfo.PropertyType))
                    {
                        ViewModelDefinition childDefinition = SpinnakerConfiguration.CurrentConfig.ViewModelManager.GetViewModelDefinition(propInfo.PropertyType);
                        if (childDefinition == null)
                            childDefinition = new ViewModelDefinition(propInfo.PropertyType, propInfo.PropertyType.Name);
                        childViewModels[propInfo.Name] = childDefinition;
                        prop.Kind = ExposedProperty.PropertyKind.ViewModel;
                    }
                }
            }

            foreach (MethodInfo methodInfo in viewModelType.GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                if (!methodInfo.IsSpecialName)
                {
                    bool include = true;
                    foreach(object o in methodInfo.GetCustomAttributes(true))
                    {
                        if (o is Newtonsoft.Json.JsonIgnoreAttribute)
                            include = false;
                        else
                        {
                            ViewModelBinding a = o as ViewModelBinding;
                            if (a != null)
                                include = a.Binding != Binding.NotBound;
                        }
                    }
                    if (include)
                    {
                        if (methodInfo.GetParameters().Length == 0)
                        {
                            ExposedMethod exposedMethod = new ExposedMethod(methodInfo);
                            exposedMethods[methodInfo.Name] = exposedMethod;
                        }
                        else if (methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters()[0].ParameterType == typeof(string))
                        {
                            ExposedMethod exposedMethod = new ExposedMethod(methodInfo);
                            exposedMethod.IsParameterized = true;
                            exposedMethods[methodInfo.Name] = exposedMethod;
                        }
                    }
                }
            }
        }