Esempio n. 1
0
        EntityIndexData createCustomEntityIndexData(Type type)
        {
            var data = new EntityIndexData();

            var attribute = (CustomEntityIndexAttribute)type.GetCustomAttributes(typeof(CustomEntityIndexAttribute), false)[0];

            data.SetEntityIndexType(type.ToCompilableString());
            data.IsCustom(true);
            data.SetEntityIndexName(type.ToCompilableString().RemoveDots());
            data.SetHasMultiple(false);
            data.SetContextNames(new[] { attribute.contextType.ToCompilableString().ShortTypeName().RemoveContextSuffix() });

            var getMethods = type
                             .GetMethods(BindingFlags.Public | BindingFlags.Instance)
                             .Where(method => Attribute.IsDefined(method, typeof(EntityIndexGetMethodAttribute)))
                             .Select(method => new MethodData(
                                         method.ReturnType.ToCompilableString(),
                                         method.Name,
                                         method.GetParameters()
                                         .Select(p => new MemberData(p.ParameterType.ToCompilableString(), p.Name))
                                         .ToArray()
                                         )).ToArray();

            data.SetCustomMethods(getMethods);

            return(data);
        }
Esempio n. 2
0
        private EntityIndexData                 createCustomEntityIndexData(INamedTypeSymbol type)
        {
            var data = new EntityIndexData();

            var attribute = type.GetAttributes(  ).First(attr => attr.AttributeClass.ToString(  ) == typeof(CustomEntityIndexAttribute).FullName);
            var attrArg0  = attribute.ConstructorArguments[0].Value as INamedTypeSymbol;                                // FIXME: get string contextName

            data.SetEntityIndexType(type.ToString(  ));
            data.IsCustom(true);
            data.SetEntityIndexName(type.ToString(  ).RemoveDots(  ));
            data.SetHasMultiple(false);
            data.SetContextNames(new[] { attrArg0.Name.ShortTypeName(  ).RemoveContextSuffix(  ) });

            var getMethods = type
                             .GetMembers(  )
                             .Where(m => m.Kind == SymbolKind.Method &&
                                    m is IMethodSymbol &&
                                    m.DeclaredAccessibility == Accessibility.Public &&
                                    m.HasAttribute(typeof(EntityIndexGetMethodAttribute)))
                             .Select(m => new MethodData(
                                         (m as IMethodSymbol).ReturnType.ToDisplayString(  ),
                                         (m as IMethodSymbol).Name,
                                         (m as IMethodSymbol).Parameters
                                         .Select(p => new MemberData(p.Type.ToString(  ), p.Name))
                                         .ToArray( )))
                             .ToArray();

            data.SetCustomMethods(getMethods);

            return(data);
        }
Esempio n. 3
0
        EntityIndexData createEntityIndexData(Type type, List <PublicMemberInfo> infos)
        {
            var data = new EntityIndexData();

            var info      = infos.Single(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1);
            var attribute = (AbstractEntityIndexAttribute)info.attributes.Single(attr => attr.attribute is AbstractEntityIndexAttribute).attribute;

            data.SetEntityIndexType(getEntityIndexType(attribute));
            data.IsCustom(false);
            data.SetEntityIndexName(type.ToCompilableString().RemoveComponentSuffix().RemoveDots());
            data.SetKeyType(info.type.ToCompilableString());
            data.SetComponentType(type.ToCompilableString());
            data.SetComponentName(type.ToCompilableString().ShortTypeName().RemoveComponentSuffix());
            data.SetMemberName(info.name);

            var contextNames = ContextsComponentDataProvider.GetContextNames(type);

            if (contextNames.Length == 0)
            {
                contextNames = new [] { _defaultContextName };
            }
            data.SetContextNames(contextNames);

            return(data);
        }
Esempio n. 4
0
        private EntityIndexData[]               createEntityIndexData(INamedTypeSymbol type, List <ISymbol> infos)
        {
            var hasMultiple = infos.Count(i => i.CountAttribute(typeof(AbstractEntityIndexAttribute)) == 1) > 1;

            return(infos
                   .Where(i => i.CountAttribute(typeof(AbstractEntityIndexAttribute)) == 1)
                   .Select(info => {
                var data = new EntityIndexData();
                var attribute = info.GetAttribute(typeof(AbstractEntityIndexAttribute));
                var entityIndexType = GetEntityIndexType(attribute.AttributeClass);
                var typeName = (info is IFieldSymbol fieldSymbol)
                                                ? fieldSymbol.Type.ToDisplayString(  )
                                                : (info is IPropertySymbol symbol)
                                                        ? symbol.Type.ToDisplayString(  )
                                                        : null;

                data.SetEntityIndexType(entityIndexType.ToString(  ));
                data.IsCustom(false);
                data.SetEntityIndexName(type.ToString().ToComponentName(_contexts.Get <Settings>().Is <IgnoreNamespaces>()));
                data.SetKeyType(typeName);
                data.SetComponentType(type.ToString(  ));
                data.SetMemberName(info.Name);
                data.SetHasMultiple(hasMultiple);
                data.SetContextNames(type.GetContextNames(  ).ToArray(  ));

                return data;
            }).ToArray());
        }
        private EntityIndexData[] CreateEntityIndexData(ICachedNamedTypeSymbol cachedNamedTypeSymbol, IEnumerable <MemberData> memberData)
        {
            var hasMultiple = memberData
                              .Count(i => i.memberFieldSymbol.GetAttributes()
                                     .HasAttribute(nameof(AbstractEntityIndexAttribute), canInherit: true)) > 1;

            return(memberData
                   .Where(i => i.memberFieldSymbol.GetAttributes()
                          .HasAttribute(nameof(AbstractEntityIndexAttribute), canInherit: true))
                   .Select(
                       info =>
            {
                var data = new EntityIndexData();
                var attribute = info.memberFieldSymbol.GetAttributes()
                                .GetAttributes(nameof(AbstractEntityIndexAttribute), canInherit: true)
                                .Single();

                data.SetEntityIndexType(GetEntityIndexType(attribute));
                data.IsCustom(false);
                data.SetEntityIndexName(cachedNamedTypeSymbol.FullTypeName.ToComponentName());
                data.SetKeyType(info.compilableTypeString);
                data.SetComponentType(cachedNamedTypeSymbol.FullTypeName);
                data.SetMemberName(info.name);
                data.SetHasMultiple(hasMultiple);
                data.SetContextNames(_contextsComponentDataProvider.GetContextNamesOrDefault(cachedNamedTypeSymbol));

                return data;
            })
                   .ToArray());
        }
        private EntityIndexData CreateCustomEntityIndexData(ICachedNamedTypeSymbol cachedNamedTypeSymbol)
        {
            var data        = new EntityIndexData();
            var attribute   = cachedNamedTypeSymbol.GetAttributes(nameof(CustomEntityIndexAttribute)).Single();
            var contextType = (ITypeSymbol)attribute.ConstructorArguments[0].Value;

            var fullTypeName = cachedNamedTypeSymbol.FullTypeName;

            data.SetEntityIndexType(fullTypeName);
            data.IsCustom(true);
            data.SetEntityIndexName(fullTypeName.RemoveDots());
            data.SetHasMultiple(false);
            data.SetContextNames(
                new[]
            {
                contextType.GetFullTypeName().ShortTypeName().RemoveContextSuffix()
            });

            var getMethods = cachedNamedTypeSymbol
                             .NamedTypeSymbol
                             .GetAllMembers()
                             .Where(method => method.HasAttribute <EntityIndexGetMethodAttribute>())
                             .Select(
                method => new MethodData(
                    method.GetReturnType().GetFullTypeName(),
                    method.Name,
                    method.GetParameters()
                    .Select(p => new MemberData(p.Type.GetFullTypeName(), p.Name))
                    .ToArray()))
                             .ToArray();

            data.SetCustomMethods(getMethods);

            return(data);
        }
Esempio n. 7
0
        private EntityIndexData[] CreateEntityIndexData(Type type, List <PublicMemberInfo> infos)
        {
            var hasMultiple = infos.Count(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1) >
                              1;

            return(infos
                   .Where(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1)
                   .Select(
                       info =>
            {
                var data = new EntityIndexData();
                var attribute = (AbstractEntityIndexAttribute)info.attributes
                                .Single(attr => attr.attribute is AbstractEntityIndexAttribute)
                                .attribute;

                data.SetEntityIndexType(GetEntityIndexType(attribute));
                data.IsCustom(false);
                data.SetEntityIndexName(type.ToCompilableString().ToComponentName());
                data.SetKeyType(info.type.ToCompilableString());
                data.SetComponentType(type.ToCompilableString());
                data.SetMemberName(info.name);
                data.SetHasMultiple(hasMultiple);
                data.SetContextNames(_contextsComponentDataProvider.GetContextNamesOrDefault(type));

                return data;
            })
                   .ToArray());
        }
        EntityIndexData createEntityIndexData(Type type, List <PublicMemberInfo> infos)
        {
            var data = new EntityIndexData();

            var info      = infos.Single(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1);
            var attribute = (AbstractEntityIndexAttribute)info.attributes.Single(attr => attr.attribute is AbstractEntityIndexAttribute).attribute;

            data.SetEntityIndexType(getEntityIndexType(attribute));
            data.IsCustom(false);
            data.SetEntityIndexName(type.ToCompilableString().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces));
            data.SetKeyType(info.type.ToCompilableString());
            data.SetComponentType(type.ToCompilableString());
            data.SetMemberName(info.name);
            data.SetContextNames(_contextsComponentDataProvider.GetContextNamesOrDefault(type));

            return(data);
        }
Esempio n. 9
0
        private EntityIndexData[]               createEntityIndexData(Type type, List <PublicMemberInfo> infos)
        {
            var hasMultiple = infos.Count(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1) > 1;

            return(infos
                   .Where(i => i.attributes.Count(attr => attr.attribute is AbstractEntityIndexAttribute) == 1)
                   .Select(info => {
                var data = new EntityIndexData();
                var attribute = (AbstractEntityIndexAttribute)info.attributes.Single(attr => attr.attribute is AbstractEntityIndexAttribute).attribute;

                data.SetEntityIndexType(getEntityIndexType(attribute));
                data.IsCustom(false);
                data.SetEntityIndexName(type.ToCompilableString().ToComponentName(_contexts.settings.isIgnoreNamespaces));
                data.SetKeyType(info.type.ToCompilableString());
                data.SetComponentType(type.ToCompilableString());
                data.SetMemberName(info.name);
                data.SetHasMultiple(hasMultiple);
                data.SetContextNames(ReflectionToCompsSystem.TypeToContextNames[type].ToArray(  ));

                return data;
            }).ToArray());
        }
 string generateAddMethod(EntityIndexData data, string contextName)
 {
     return(data.IsCustom()
                ? generateCustomMethods(data)
                : generateMethods(data, contextName));
 }