public static string Replace(this string template, ComponentData data, string contextName, EventData eventData)
        {
            var eventListener = data.EventListener(contextName, eventData);

            return(template
                   .Replace(data, contextName)
                   .Replace("${EventComponentName}", data.EventComponentName(eventData))
                   .Replace("${EventListenerComponent}", eventListener.AddComponentSuffix())
                   .Replace("${Event}", data.Event(contextName, eventData))
                   .Replace("${EventListener}", eventListener)
                   .Replace("${eventListener}", eventListener.LowercaseFirst())
                   .Replace("${EventType}", GetEventTypeSuffix(eventData)));
        }
        public static string Replace(this string template, ComponentData data, string contextName, EventData eventData)
        {
            var eventListener      = data.EventListener(contextName, eventData);
            var lowerEventListener = data.GetContextNames().Length > 1
                ? contextName.LowercaseFirst() + data.ComponentName() + GetEventTypeSuffix(eventData).AddListenerSuffix()
                : data.ComponentName().LowercaseFirst() + GetEventTypeSuffix(eventData).AddListenerSuffix();

            return(template
                   .Replace(data, contextName)
                   .Replace("${EventListenerComponent}", eventListener.AddComponentSuffix())
                   .Replace("${Event}", data.Event(contextName, eventData))
                   .Replace("${EventListener}", eventListener)
                   .Replace("${eventListener}", lowerEventListener)
                   .Replace("${EventType}", GetEventTypeSuffix(eventData)));
        }
Ejemplo n.º 3
0
        CodeGenFile[] generate(string contextName, ComponentData data)
        {
            return(data.GetEventData()
                   .Select(eventData => {
                var methodArgs = data.GetEventMethodArgs(eventData, ", " + (data.GetMemberData().Length == 0
                                                                            ? data.PrefixedComponentName()
                                                                            : getMethodArgs(data.GetMemberData())));

                var cachedAccess = data.GetMemberData().Length == 0
                        ? string.Empty
                        : "var component = e." + data.ComponentName().LowercaseFirst() + ";";

                if (eventData.eventType == EventType.Removed)
                {
                    methodArgs = string.Empty;
                    cachedAccess = string.Empty;
                }

                var template = eventData.eventTarget == EventTarget.Self
                        ? SELF_TARGET_TEMPLATE
                        : ANY_TARGET_TEMPLATE;

                var fileContent = template
                                  .Replace("${GroupEvent}", eventData.eventType.ToString())
                                  .Replace("${filter}", getFilter(data, contextName, eventData))
                                  .Replace("${cachedAccess}", cachedAccess)
                                  .Replace("${methodArgs}", methodArgs)
                                  .Replace(data, contextName, eventData);

                return new CodeGenFile(
                    "Events" + Path.DirectorySeparatorChar +
                    "Systems" + Path.DirectorySeparatorChar +
                    data.Event(contextName, eventData) + "EventSystem.cs",
                    fileContent,
                    GetType().FullName
                    );
            }).ToArray());
        }
 public static string EventListener(this ComponentData data, string contextName, EventData eventData)
 {
     return(data.Event(contextName, eventData) + "Listener");
 }
 public static string EventListener(this ComponentData data, string contextName, EventData eventData)
 {
     return(data.Event(contextName, eventData).AddListenerSuffix());
 }