Exemple #1
0
        void EventEmit(IViewEvent viewEvent, List <MemberEmitter> ret)
        {
            string name        = viewEvent.Name.Replace("/", "").Replace(".", "");
            string genericType = (viewEvent.EventType() != null) ? $"<{GetTypeString(viewEvent.EventType())}>" : "";

            PropertyEmitter property = new PropertyEmitter();

            property.Name    = "On" + name;
            property.Type    = "event Action" + genericType;
            property.Summary = $"BindingPath : {viewEvent.Name}\nSender: {viewEvent.ToString()}";

            property.Getter = new DelegateEmitter(w =>
            {
                w.WriteLine("add");
                using (w.Bracket())
                {
                    w.WriteLine($"m_Event.Subscribe{genericType}(\"{viewEvent.Name}\", value);");
                }
            });
            property.Setter = new DelegateEmitter(w =>
            {
                w.WriteLine("remove");
                using (w.Bracket())
                {
                    w.WriteLine($"m_Event.Unsubscribe{genericType}(\"{viewEvent.Name}\", value);");
                }
            });
            ret.Add(property);
        }
Exemple #2
0
        void CommandEmit(IViewEvent viewEvent, List <MemberEmitter> ret)
        {
            string name        = viewEvent.Name.Replace("/", "").Replace(".", "");
            string genericType = (viewEvent.EventType() != null) ? $"<{GetTypeString(viewEvent.EventType())}>" : "";

            FieldEmitter field = new FieldEmitter();

            field.Accessibility = "private";
            field.Name          = "m_" + name + m_Config.CommandSuffix;
            field.Type          = "BindingCommand" + genericType;
            ret.Add(field);


            PropertyEmitter property = new PropertyEmitter();

            property.Name    = name + m_Config.CommandSuffix;
            property.Type    = "ICommand" + genericType;
            property.Summary = $"BindingPath : {viewEvent.Name}\nSender: {viewEvent.ToString()}";

            property.Getter = new DelegateEmitter(w =>
            {
                w.WriteLine("get");
                using (w.Bracket())
                {
                    w.WriteLine($"return m_{name}{m_Config.CommandSuffix}?.Get() ?? null;");
                }
            });
            property.Setter = new DelegateEmitter(w =>
            {
                w.WriteLine("set");
                using (w.Bracket())
                {
                    w.WriteLine($"if (m_{name}{m_Config.CommandSuffix} == null) m_{name}{m_Config.CommandSuffix} = new BindingCommand{genericType}(\"{viewEvent.Name}\", this);");
                    w.WriteLine($"m_{name}{m_Config.CommandSuffix}.Set(value);");
                }
            });
            ret.Add(property);
        }