Пример #1
0
        public static List <string> TranslateExpressionToMemberNames(Expression e,
                                                                     EntityPropertyConverterOptions options)
        {
            var translator = new AzureStorageQuerySelectTranslator();

            translator._options = options;

            translator.Visit(e);
            return(translator._memberNames);
        }
Пример #2
0
        public static List <PropertyRef <ICollection> > GatherPropertiesWithCollectionsRecursive(
            object obj, EntityPropertyConverterOptions opts,
            List <string> propertyPath = null, List <PropertyRef <ICollection> > collectedCollRefs = null, bool includeNulls = false)
        {
            if (propertyPath == null)
            {
                propertyPath = new List <string>();
            }

            if (collectedCollRefs == null)
            {
                collectedCollRefs = new List <PropertyRef <ICollection> >();
            }

            if (obj == null)
            {
                return(collectedCollRefs);
            }

            var objType         = obj.GetType();
            var properties      = objType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var collectionProps = properties.Where(x =>
                                                   typeof(IDictionary).IsAssignableFrom(x.PropertyType) ||
                                                   typeof(IList).IsAssignableFrom(x.PropertyType));

            var thisObjCollPropRefs = collectionProps.Select(x => new PropertyRef <ICollection>()
            {
                StoredInstance        = (ICollection)x.GetValue(obj),
                FlattenedPropertyName = string.Join(opts.PropertyNameDelimiter, propertyPath.Append(x.Name)),
                SourceObject          = obj,
                SourceObjectType      = objType,
                Property = x
            }).Where(x => includeNulls || x.StoredInstance != null);

            collectedCollRefs.AddRange(thisObjCollPropRefs);

            var otherProperties = properties.Where(x => !IsCollectionProperty(x) && !IsBlobRefProperty(x) && x.PropertyType.IsClass);

            foreach (var property in otherProperties)
            {
                var innerPropertyPath = new List <string>(propertyPath);
                innerPropertyPath.Add(property.Name);
                var propertyValue = property.GetValue(obj);
                if (propertyValue != null)
                {
                    GatherPropertiesWithCollectionsRecursive(propertyValue, opts, innerPropertyPath, collectedCollRefs);
                }
                else if (includeNulls)
                {
                    GatherPropertiesWithCollectionsRecursive(property.PropertyType, opts, innerPropertyPath, collectedCollRefs);
                }
            }

            return(collectedCollRefs);
        }
Пример #3
0
        public static string TranslateExpression(Expression e, string partitionKeyProperty, string rowKeyProperty, EntityPropertyConverterOptions options)
        {
            var translator = new AzureStorageQueryTranslator(partitionKeyProperty, rowKeyProperty);

            translator._options = options;
            translator.Visit(e);

            return(translator.Filter.ToString());
        }
Пример #4
0
        public static List <PropertyRef <LargeBlob> > GatherPropertiesWithBlobsRecursive(Type type, EntityPropertyConverterOptions opts,
                                                                                         List <string> propertyPath = null, List <PropertyRef <LargeBlob> > collectedBlobRefs = null)
        {
            if (propertyPath == null)
            {
                propertyPath = new List <string>();
            }

            if (collectedBlobRefs == null)
            {
                collectedBlobRefs = new List <PropertyRef <LargeBlob> >();
            }

            var objType    = type;
            var properties = objType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var blobProps  = properties.Where(IsBlobRefProperty);

            var thisObjBlobPropRefs = blobProps.Select(x => new PropertyRef <LargeBlob>()
            {
                StoredInstance        = null,
                FlattenedPropertyName = string.Join(opts.PropertyNameDelimiter, propertyPath.Append(x.Name)),
                SourceObject          = null,
                SourceObjectType      = objType,
                Property = x
            });

            collectedBlobRefs.AddRange(thisObjBlobPropRefs);

            var otherProperties = properties.Where(x => !IsBlobRefProperty(x) && !IsCollectionProperty(x) && x.PropertyType.IsClass);

            foreach (var property in otherProperties)
            {
                var innerPropertyPath = new List <string>(propertyPath);
                innerPropertyPath.Add(property.Name);
                GatherPropertiesWithBlobsRecursive(property.PropertyType, opts, innerPropertyPath, collectedBlobRefs);
            }

            return(collectedBlobRefs);
        }