Esempio n. 1
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. 2
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);
        }
        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);
        }