public void Provide(Type type, ComponentData data) { var isUnique = Attribute .GetCustomAttributes(type) .OfType <UniqueAttribute>() .Any(); data.IsUnique(isUnique); }
CodeGenFile generateComponentClass(ComponentData data) { var fullComponentName = data.GetFullTypeName().RemoveDots(); var contexts = string.Join(", ", data.GetContextNames()); var unique = data.IsUnique() ? "[Entitas.CodeGeneration.Attributes.UniqueAttribute]" : string.Empty; if (!string.IsNullOrEmpty(contexts)) { contexts = "[" + contexts + "]"; } return(new CodeGenFile( "Components" + Path.DirectorySeparatorChar + fullComponentName + ".cs", COMPONENT_TEMPLATE .Replace("${FullComponentName}", fullComponentName) .Replace("${Type}", data.GetObjectType()) .Replace("${Contexts}", contexts) .Replace("${Unique}", unique), GetType().FullName )); }
ComponentData[] createDataForEvents(ComponentData data) { var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces); return(data.GetContextNames() .SelectMany(contextName => data.GetEventData().Select(eventData => { var dataForEvent = new ComponentData(data); dataForEvent.IsEvent(false); dataForEvent.IsUnique(false); var eventTypeSuffix = eventData.GetEventTypeSuffix(); var optionalContextName = dataForEvent.GetContextNames().Length > 1 ? contextName : string.Empty; var listenerComponentName = optionalContextName + componentName + eventTypeSuffix + "Listener"; dataForEvent.SetTypeName(listenerComponentName.AddComponentSuffix()); dataForEvent.SetMemberData(new[] { new MemberData("System.Collections.Generic.List<I" + listenerComponentName + ">", "value") }); dataForEvent.SetContextNames(new[] { contextName }); return dataForEvent; }).ToArray() ).ToArray()); }