public void CreatePropertyFinder()
        {
            IPropertyFinder finder = BindableObjectMetadataFactory.Create().CreatePropertyFinder(typeof(TestClass));

            Assert.That(finder.GetType(), Is.SameAs(typeof(ReflectionBasedPropertyFinder)));
            Assert.That(new List <IPropertyInformation> (finder.GetPropertyInfos())[0].DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(TestClass))));
        }
Exemple #2
0
        private static IEnumerable <ITypeSymbol> InnerGetNestedCustomDeserializerTypes(
            IPropertyFinder finder,
            INamedTypeSymbol type,
            IList <ITypeSymbol> foundTypes,
            IList <ITypeSymbol> exploredTypes
            )
        {
            var writingProperties = finder.GetWritingProperties(type);
            var readingProperties = finder.GetReadingProperties(type);

            var firstLevelNestedTypes = writingProperties
                                        .Concat(readingProperties)
                                        .Select(p =>
            {
                var t = p.Property.FindCustomDeserializerType();

                if (t == null)
                {
                    return(p);
                }

                foundTypes.AddDistinct(t);
                return(null);
            })
                                        .Trim()
                                        .FilterTypes(exploredTypes);


            return(firstLevelNestedTypes.Concat(
                       firstLevelNestedTypes
                       .OfType <INamedTypeSymbol>()
                       .SelectMany(t => InnerGetNestedCustomDeserializerTypes(finder, t, foundTypes, exploredTypes))
                       .OfType <ITypeSymbol>()
                       ));
        }
Exemple #3
0
        protected IEnumerable <PropertyBase> GetProperties()
        {
            IPropertyFinder propertyFinder = _metadataFactory.CreatePropertyFinder(_concreteType);

            Dictionary <string, PropertyBase> propertiesByName = new Dictionary <string, PropertyBase>();

            foreach (IPropertyInformation propertyInfo in propertyFinder.GetPropertyInfos())
            {
                PropertyReflector propertyReflector = _metadataFactory.CreatePropertyReflector(_concreteType, propertyInfo, _businessObjectProvider);
                PropertyBase      property          = propertyReflector.GetMetadata();
                if (propertiesByName.ContainsKey(property.Identifier))
                {
                    string message = string.Format(
                        "Type '{0}' has two properties called '{1}', this is currently not supported.",
                        TargetType.FullName,
                        property.Identifier);
                    throw new NotSupportedException(message);
                }
                else
                {
                    propertiesByName.Add(property.Identifier, property);
                }
            }

            return(propertiesByName.Values);
        }
Exemple #4
0
        public static IEnumerable <ITypeSymbol> GetNestedTypes(this IPropertyFinder finder, ITypeSymbol[] types)
        {
            var nestedTypes = new List <ITypeSymbol>(types);

            return(types
                   .OfType <INamedTypeSymbol>()
                   .SelectMany(t => InnerGetNestedTypes(finder, t, nestedTypes)));
        }
 public Enums(string @namespace, bool useTryParseOrDefault, bool isMissingFallbackAllowed, SourceFileMetadata meta, IPropertyFinder codeAnalyzer, Dictionary <ITypeSymbol, TypedConstant> fallbackValueOverrides)
 {
     _nameSpace                = @namespace;
     _useTryParseOrDefault     = useTryParseOrDefault;
     _isMissingFallbackAllowed = isMissingFallbackAllowed;
     _meta                   = meta;
     _codeAnalyzer           = codeAnalyzer;
     _fallbackValueOverrides = fallbackValueOverrides;
 }
Exemple #6
0
        public static IEnumerable <ITypeSymbol> GetNestedCustomDeserializerTypes(this IPropertyFinder finder, ITypeSymbol[] types)
        {
            var foundTypes    = new List <ITypeSymbol>();
            var exploredTypes = new List <ITypeSymbol>(types);

            var sideEffect = types
                             .OfType <INamedTypeSymbol>()
                             .SelectMany(t => InnerGetNestedCustomDeserializerTypes(finder, t, foundTypes, exploredTypes))
                             .ToArray();    //force execution of whole chain.

            return(foundTypes);
        }
Exemple #7
0
        private static IEnumerable <ITypeSymbol> InnerGetNestedTypes(IPropertyFinder finder, INamedTypeSymbol type, IList <ITypeSymbol> alreadyFoundTypes)
        {
            var writingProperties = finder.GetWritingProperties(type);
            var readingProperties = finder.GetReadingProperties(type);

            var firstLevelNestedTypes = writingProperties
                                        .Concat(readingProperties)
                                        .FilterTypes(alreadyFoundTypes);

            return(firstLevelNestedTypes
                   .Concat(firstLevelNestedTypes.OfType <INamedTypeSymbol>().SelectMany(t => InnerGetNestedTypes(finder, t, alreadyFoundTypes))));
        }
 public StaticJsonBuilderSerializerGenerator(
     RoslynMetadataHelper metadataHelper,
     string @namespace,
     bool disableToUpperCtor,
     IPropertyFinder propertyFinder,
     IEnumerable <IValueSerializationGenerator> valueGenerators,
     SourceFileMetadata generatedCodeMeta)
 {
     _metadataHelper     = metadataHelper;
     _namespace          = @namespace;
     _disableToUpperCtor = disableToUpperCtor;
     _propertyFinder     = propertyFinder;
     _valueGenerators    = valueGenerators;
     _generatedCodeMeta  = generatedCodeMeta;
     _propertyGenerator  = () => new GeneratorContext(
         _metadataHelper,
         new ReadContext(SerializerConstants.ReaderParameterName, _overChar),
         new WriteContext(_writer, _object),
         valueGenerators.ToArray()
         );
 }
Exemple #9
0
 internal PropertyReflector(object instance, IPropertyFinder propertyFinder)
     : base(instance, propertyFinder)
 {
 }
        public ConditionExpressionElement(ConditionElement element, IPropertyFinder finder)
            : base(TreeCode.Expression)
        {
            if (element.Left.Type == LexAnalyzer.TokenTypes.Id)
            {
                LeftName = element.Left.Value.ToUpper();
                LeftId   = finder.GetId(LeftName, out IsString);
            }
            else
            {
                throw new SyntacticException("Unexpected token " + element.Operation.ToString());
            }

            if (IsString)
            {
                RightString = element.Right.Value;
                switch (element.Operation.Type)
                {
                case LexAnalyzer.TokenTypes.Equal:
                    operation = ConditionOperations.Eq;
                    break;

                default:
                    throw new SyntacticException("Unexpected token " + element.Operation.ToString());
                }
            }
            else
            {
                GetRightNmr(element.Right);
                switch (element.Operation.Type)
                {
                case LexAnalyzer.TokenTypes.Equal:
                    operation = ConditionOperations.Eq;
                    break;

                case LexAnalyzer.TokenTypes.GE:
                    operation = ConditionOperations.GE;
                    break;

                case LexAnalyzer.TokenTypes.Greater:
                    operation = ConditionOperations.Greater;
                    break;

                case LexAnalyzer.TokenTypes.Less:
                    operation = ConditionOperations.Less;
                    break;

                case LexAnalyzer.TokenTypes.LE:
                    operation = ConditionOperations.LE;
                    break;

                case LexAnalyzer.TokenTypes.And:
                    operation = ConditionOperations.And;
                    break;

                case LexAnalyzer.TokenTypes.Or:
                    operation = ConditionOperations.Or;
                    break;

                default:
                    throw new SyntacticException("Unexpected token " + element.Operation.ToString());
                }
            }
            IsExpr = true;
        }
Exemple #11
0
 /// <summary>
 /// Create new syntactic analyzer
 /// </summary>
 /// <param name="lex">Lexical analyzer output</param>
 /// <param name="finder">Table with information about variables</param>
 public LLAnalyzer(LexAnalyzer lex, IPropertyFinder finder)
 {
     this.finder     = finder;
     this.TokenQueue = lex.Tokens;
     CreateInputQueue();
 }