Пример #1
0
        /// <summary>
        /// Should be call manually.
        /// </summary>
        public virtual void SetUpViewInfo()
        {
            ViewManager = Her.Resolve <IViewManager>();

            DataBindings = GetComponentsInChildren <DataBindingBase>();
            ViewId       = ViewManager.Register(this);
        }
Пример #2
0
        protected (Component component, MemberInfo memberInfo) ParseViewEntry(Component viewProvider,
                                                                              string entry)
        {
            var(typeName, memberName) = ParseEntry2TypeMember(entry);

            var component = viewProvider.GetComponent(typeName);

            if (component == null)
            {
                Her.Error($"Can't find component of type: {typeName} on {viewProvider}.");
                return(null, null);
            }

            var viewMemberInfos = component.GetType().GetMember(memberName);

            if (viewMemberInfos.Length <= 0)
            {
                Her.Error($"Can't find member of name: {memberName} on {component}.");
                return(null, null);
            }

            var memberInfo = viewMemberInfos[0];

            return(component, memberInfo);
        }
Пример #3
0
        protected (string typeName, string memberName) ParseEntry2TypeMember(string entry)
        {
            var lastPeriodIndex = entry.LastIndexOf('.');

            if (lastPeriodIndex == -1)
            {
                throw new Exception($"No period was found[{entry}] on {name}");
            }

            var typeName   = entry.Substring(0, lastPeriodIndex);
            var memberName = entry.Substring(lastPeriodIndex + 1);

            //Due to (undocumented) unity behaviour, some of their components do not work with the namespace when using GetComponent(""), and all of them work without the namespace
            //So to be safe, we remove all namespaces from any component that starts with UnityEngine
            if (typeName.StartsWith("UnityEngine."))
            {
                typeName = typeName.Substring(typeName.LastIndexOf('.') + 1);
            }

            if (typeName.Length == 0 || memberName.Length == 0)
            {
                Her.Error($"Bad formatting! Expected [<type-name>.<member-name>]: {entry} ");
                return(null, null);
            }

            return(typeName, memberName);
        }
Пример #4
0
        public void SetViewModel(object context)
        {
            if (context is TViewModel viewModel)
            {
                DataContext = viewModel;
            }
            else
            {
                Her.Warn($"{context} is not matching {typeof(TViewModel)}");
            }

            DataReadyEvent?.Invoke();
        }
Пример #5
0
        protected MemberInfo ParseViewModelEntry(ViewModel viewModel, string entry)
        {
            var(_, memberName) = ParseEntry2TypeMember(entry);

            var viewMemberInfos = viewModel.GetType().GetMember(memberName);

            if (viewMemberInfos.Length <= 0)
            {
                Her.Error($"Can't find member of name: {memberName} on {viewModel}.");
                return(null);
            }

            var memberInfo = viewMemberInfos[0];

            return(memberInfo);
        }
 public DefaultCollectionChangedHandler()
 {
     ViewManager = Her.Resolve <IViewManager>();
 }