private bool IsDerivedCollection(Type CollectionType) { var itemType = TypesUtil.GetGenericArgumentForBaseType(CollectionType, typeof(IEnumerable <>)); //if entityType is a non-entity, it will not have any mapping. return(typeTranslationUtil.GetMapping <IModelEntityMapping>(itemType) is IDerivedModelEntityMapping); }
public static TPOCO CreatePOCO <T, TPOCO>(this T source) where T : IModelEntity where TPOCO : IPOCO <T>, new() { Func <bool, object, bool, IPOCOContainer> getReferenceValue = (isEnumerable, propVal, isLoaded) => isEnumerable ? (IPOCOContainer) new POCOCollection(propVal as IEnumerable, isLoaded) : (IPOCOContainer) new POCOReference(propVal, isLoaded); TPOCO poco = new TPOCO(); foreach (var prop in typeof(TPOCO).GetProperties()) { var propOnSource = typeof(T).GetProperty(prop.Name); if (typeof(IPOCOContainer).IsAssignableFrom(prop.PropertyType)) { prop.SetValue(poco, getReferenceValue(TypesUtil.IsNonPrimitiveCollection(propOnSource.PropertyType), propOnSource.GetValue(source), source._getIntermediateEntity().IsLoaded(makeFieldSelector <T>(propOnSource)))); } else { prop.SetValue(poco, propOnSource.GetValue(source)); } } return(poco); }
public static object GetCollectionInstance(Type collectionType, List <object> collection) { //Arrays if (collectionType.IsArray) { var array = Activator.CreateInstance(collectionType, collection.Count) as Array; for (int i = 0; i < collection.Count; i++) { array.SetValue(collection[i], i); } return(array); } //lists with indexers else if (collectionType.IsGenericType && collectionType.IsInterface && TypesUtil.IsNonPrimitiveCollection(collectionType)) { var list = Activator.CreateInstance(typeof(List <>) .MakeGenericType(TypesUtil.GetGenericArgumentForBaseType(collectionType, typeof(ICollection <>)))) as IList; collection.ForEach(item => list.Add(item)); return(list); } //Custom generic collections .. assume they have default constructor and Add method else if (collectionType.IsGenericType && TypesUtil.IsNonPrimitiveCollection(collectionType) && collectionType.GetConstructor(Type.EmptyTypes) != null) { var customCollection = Activator.CreateInstance(collectionType); var addMethod = collectionType.GetMethod("Add"); collection.ForEach(item => addMethod.Invoke(customCollection, new object[] { item })); return(customCollection); } throw new NotSupportedException("Only Arrays, Lists, ICollection<> and Custom collection types with default constructor are supported."); }
//Fills an Enumerable (List, Collection etc) with items private object FillEnumerable(object enumerable, List <object> items) { var enumerableType = enumerable.GetType(); if (enumerableType.IsArray) //Array { for (int i = 0; i < items.Count; i++) { (enumerable as Array).SetValue(items[i], i); } } else if (typeof(IList).IsAssignableFrom(enumerableType)) //List and derived types .. which have indexers { for (int i = 0; i < items.Count; i++) { (enumerable as IList)[i] = items[i]; } } else if (enumerableType.IsGenericType && TypesUtil.IsNonPrimitiveCollection(enumerableType)) //Custom generic collections { enumerableType.GetMethod("Clear").Invoke(enumerable, null); var addMethod = enumerableType.GetMethod("Add"); foreach (var item in items) { addMethod.Invoke(enumerable, new object[] { item }); } } else { throw new NotSupportedException("The collection of type " + enumerableType.ToString() + " cannot be bound to the context."); } return(enumerable); }
private List <IUnprojectedBinding> GetUnprojectedBindings(IEnumerable <IRequestedBinding> requestedBindings) { var result = new List <IUnprojectedBinding>(); foreach (var target in requestedBindings.Where(b => TypesUtil.IsNonPrimitiveCollection(b.Type))) { if (target is UnprojectedIncludeInCollectionBinding) { result.Add(target as IUnprojectedBinding); } //If the target is a collection, and the type of collection is inherited, we will do its loading // via "Post-Projection Loader". Which reloads the inheritance chain by issuing a new query. //We will not handle this case here, instead just mark this for post projection loading. else if (TypesUtil.IsNonPrimitiveCollection(target.Type)) { if (IsManyToManyBinding(target)) { var unprojected = new UnprojectedManyToManyBinding(); unprojected.TargetBinding = target; result.Add(unprojected); } else { if (IsDerivedCollection(target.Type)) { var unprojected = new UnprojectedCollectionBinding(); unprojected.TargetBinding = target; result.Add(unprojected); } } } } return(result); }
public virtual IEnumerable <T> GetResultList(Expression expression) { var visitor = new QueryTranslationVisitor(new QueryAnalysisContext(entityContext._InternalServices.TypeTranslationUtil) { ModifyProjection = true }); var translationResults = visitor.GetTranslatedResults(expression); var tableEntityQuery = translationResults.AnalysisContext.RootEntityQuery.TableEntityQuery .Provider.CreateQuery(translationResults.TranslatedExpression); if (TypesUtil.IsPrimitiveDataType(typeof(T))) { return(tableEntityQuery as IEnumerable <T>); } else { var tableEntities = new List <object>(); foreach (object o in tableEntityQuery) { tableEntities.Add(o); } return(MakeResultList(tableEntities, translationResults.AnalysisContext.QueryableType.NonPrimitiveEnumerableItemType)); } }
public static SimpleType GetMember(SimpleType source, MemberExpression memberExp, MemberExpression translatedMemberExp, TypeTranslationUtil typeTranslationUtil) { SimpleType result; if (source != null) { result = source.GetMemberType(memberExp); if (result != null) { return(result); } } var includes = (source != null) ? source.GetMemberIncludes(memberExp) : new List <IncludeDirective>(); var memberIsCollection = TypesUtil.IsNonPrimitiveCollection(memberExp.Type); var classMapping = typeTranslationUtil.GetMapping <IModelEntityMapping>(memberExp.Member.DeclaringType); if (memberIsCollection && classMapping != null) { //Getting the many-to-many maps for the declaringType var manyToManyRelationship = classMapping.GetManyToManyRelationships() .FirstOrDefault(m => ((MemberExpression)m.RelatedEntitySelector.Body).Member.Name == memberExp.Member.Name); if (manyToManyRelationship != null) { var otherEndSelector = manyToManyRelationship.RelatedEntitySelectorFromMap.Body as MemberExpression; var param = Expression.Parameter(typeTranslationUtil.GetTranslatedType(manyToManyRelationship.MapType), "x"); var translatedOtherEndSelector = typeTranslationUtil.GetMemberExpression (manyToManyRelationship.MapType, otherEndSelector.Member.Name, param); var map = new ManyToManyMapType(manyToManyRelationship.MapType, param.Type, TypesUtil.GetGenericArgumentForBaseType(memberExp.Type, typeof(ICollection <>)), manyToManyRelationship, translatedOtherEndSelector.Member) { Includes = includes }; return(new SimpleType(memberExp.Type, translatedMemberExp.Type) { NonPrimitiveEnumerableItemType = map }); } } result = new SimpleType(memberExp.Type, translatedMemberExp.Type); if (memberIsCollection) { var itemType = TypesUtil.GetGenericArgumentForBaseType(memberExp.Type, typeof(IEnumerable <>)); var translatedItemType = TypesUtil.GetGenericArgumentForBaseType(translatedMemberExp.Type, typeof(IEnumerable <>)); var innerType = new SimpleType(itemType, translatedItemType) { Includes = includes }; result.NonPrimitiveEnumerableItemType = innerType; } else { result.Includes = includes; } return(result); }
protected override IValue VisitElementAccessExpression(ElementAccessExpressionSyntax node) { var expression = Visit(node.Expression); var aa = _internalVisitArgumentList(node.ArgumentList); Type elementType = TypesUtil.GetElementType(expression.ValueType); var g = new ElementAccessExpression(expression, aa, elementType); return(Simplify(g)); }
public void GetGenericArgumentForBaseType_ExceptionOnNonGenericInput() { Type finalType = typeof(ArgForGetGenericArgumentForBaseType); Type specificBaseType = typeof(IEnumerable); Type expected = typeof(int); Type actual; actual = TypesUtil.GetGenericArgumentForBaseType(finalType, specificBaseType); Assert.AreEqual(expected, actual); }
public void GetGenericArgumentForBaseType_BaseClass1() { Type finalType = typeof(ArgForGetGenericArgumentForBaseType); Type specificBaseType = typeof(ArgForGetGenericArgumentForBaseTypeBase <>); Type expected = typeof(string); Type actual; actual = TypesUtil.GetGenericArgumentForBaseType(finalType, specificBaseType); Assert.AreEqual(expected, actual); }
public Protocols.Response.CodeList Get() { return(new Protocols.Response.CodeList { Datas = TypesUtil.ToEnumerable <CrawlingType>() .Where(x => x != CrawlingType.Rss) .ToList() .ConvertAll(x => x.ToString()) }); }
public static void Deserialize <T, TIntermediate, TPOCO>(this TIntermediate source, SerializationInfo info) where T : IEntity <TIntermediate> where TIntermediate : IntermediateEntity <T> where TPOCO : IPOCO <T>, new() { foreach (PropertyInfo prop in typeof(TPOCO).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) .Where(p => !typeof(IPOCOContainer).IsAssignableFrom(p.PropertyType))) { var fieldOnIntermediate = TypesUtil.GetIntermediateContainer(typeof(TIntermediate), prop.Name).GetValue(source) as IEntityField; fieldOnIntermediate.MaterializeSet(info.GetValue(prop.Name, prop.PropertyType)); } }
private SimpleType GetQueryableType(Type originalType, Type translatedType) { if (!TypesUtil.IsNonPrimitiveCollection(originalType)) { return(new SimpleType(originalType, translatedType)); } else { var itemType = TypesUtil.GetGenericArgumentForBaseType(originalType, typeof(IEnumerable <>)); var translatedItemType = TypesUtil.GetGenericArgumentForBaseType(translatedType, typeof(IEnumerable <>)); return(RuntimeTypes.CreateEnumerable(new SimpleType(itemType, translatedItemType))); } }
//private IValue internalVisit_BoolBinaryExpression(BinaryExpressionSyntax node, string _operator) //{ // var symbolInfo = state.Context.RoslynModel.GetSymbolInfo(node); // if (symbolInfo.Symbol != null) // throw new NotSupportedException(); // var tmp = internalVisit_BinaryExpressionSyntax(node, _operator); // var l = Visit(node.Left); // var r = Visit(node.Right); // var g = new BinaryOperatorExpression(l, r, _operator, typeof(bool), null); // return g; //} private IValue InternalVisitTextIdentifier(string identifier) { var t = context.MatchTypes(identifier, 0); if (t.Length > 2) { throw new NotSupportedException(); } if (t.Length == 1) { return(new TypeValue(t.First())); } var lv = context.Arguments.Where(i => i.Name == identifier).ToArray(); if (lv.Length == 1) { return(new ArgumentExpression(lv.First().Name, lv.First().Type)); } var lv1 = context.LocalVariables.Where(i => i.Name == identifier).ToArray(); if (lv1.Length == 1) { return(new LocalVariableExpression(lv1.First().Name, lv1.First().Type)); } if ((object)_state.CurrentType != null) { var fi = TypesUtil.ListFields(_state.CurrentType, identifier); if (fi.Length == 1) { var tmp = fi[0]; if (tmp.IsStatic) { throw new NotSupportedException(); } var a = new InstanceFieldAccessExpression(fi[0], new ThisExpression(_state.CurrentType)); return(Simplify(a)); } } { var aaaa = _state.Context.MatchTypes(identifier, 0); if (aaaa.Length == 1) { return(new TypeValue(aaaa[0])); } } return(new UnknownIdentifierValue(identifier, new IValue[0])); }
protected override object VisitForEachStatement(ForEachStatementSyntax node) { var collection = InternalVisitExpression(node.Expression); #if ROSLYN var info1 = ModelExtensions.GetDeclaredSymbol(context.RoslynModel, node); var info = info1 as ILocalSymbol; if (info == null) { throw new ArgumentNullException("info"); } var rosType = context.Roslyn_ResolveType(info.Type); var loopVariableType = new LangType(rosType); var loopVariableName = info.Name; #else var type = _VisitExpression(node.Type); if (type is UnknownIdentifierValue) { var xx = type as UnknownIdentifierValue; if (xx.Identifier == "var") { var et = TypesUtil.GetEnumerateItemType(collection.ValueType); type = new TypeValue(et); } else { throw new NotSupportedException(); } } Debug.Assert(type is TypeValue); Debug.Assert((type as TypeValue).DotnetType == rosType); var loopVariableType = new LangType((type as TypeValue).DotnetType); var loopVariableName = _Name(node.Identifier); #endif var ps = new VariableDeclaration( loopVariableType, new[] { new VariableDeclarator(loopVariableName, null, null) } ); return(context.DoWithLocalVariables(ps, () => { var stat = Visit(node.Statement); Debug.Assert(stat is IStatement); var g = new ForEachStatement(loopVariableType, loopVariableName, collection, stat as IStatement); return g; })); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var candidateExistingElements = new List <ISymbolInfo>(); var table = GetSymbolTable(context); table?.ForAllSymbolInfos(info => { var declaredElement = info.GetDeclaredElement(); var type = declaredElement.Type(); if (type != null) { if (type.GetClassType().ConvertToString() == "Class:Moq.Mock`1") { IType typeParameter = TypesUtil.GetTypeArgumentValue(type, 0); if (typeParameter != null && context.ExpectedTypesContext != null && context.ExpectedTypesContext.ExpectedITypes != null && context.ExpectedTypesContext.ExpectedITypes.Select(x => x.Type).Where(x => x != null).Any(x => typeParameter.IsExplicitlyConvertibleTo(x, ClrPredefinedTypeConversionRule.INSTANCE))) { candidateExistingElements.Add(info); } } } }); foreach (var candidateExistingElement in candidateExistingElements) { var proposedCompletion = candidateExistingElement.ShortName + ".Object"; var lookupItem = GetLookupItem(context, proposedCompletion); collector.Add(lookupItem); } if (context.ExpectedTypesContext != null) { foreach (var expectedType in context.ExpectedTypesContext.ExpectedITypes) { if (expectedType.Type == null) { continue; } if (expectedType.Type.IsInterfaceType()) { string typeName = expectedType.Type.GetPresentableName(CSharpLanguage.Instance); var proposedCompletion = "new Mock<" + typeName + ">().Object"; var lookupItem = GetLookupItem(context, proposedCompletion); collector.Add(lookupItem); } } } return(true); }
private Func <EntityContext, object[], TResult> GetFunc <TResult>(LambdaExpression query) { var analyzer = new CompilableQueryAnalyzer(query, GetTypeTranslationUtil()); var analysisResult = analyzer.GetResult(); //Find L2S.CompiledQuery.Compile<...>() // and invoke the backend compiler; backendCompiledMethod is a Func<,..> var compiledBackendMethod = GetCompileMethod(analysisResult).Invoke(null, new object[] { analysisResult.TranslatedCompilableLambda }); //Compile the client-side part of the expression and get a Func<> // This function the materialized form and works on it (like call a ToList() for instance). object postMaterializationLambda = null; if (analysisResult.PostMaterializationLambda != null) { postMaterializationLambda = analysisResult.PostMaterializationLambda.Compile(); } //l2sCompileResult lambda can return two types // 1. IQueryable // 2. An Entity itself, as a result of the call to First(), Single() etc. if (!TypesUtil.IsNonPrimitiveCollection(analysisResult.MaterializableExpression.Type)) { return((context, args) => { var backendResults = InvokeCompiledMethod(compiledBackendMethod, context as EntityContext, args); var singleObjectMaterializer = Activator.CreateInstance(typeof(SingleObjectMaterializer <>) .MakeGenericType(analysisResult.MaterializableExpression.Type), new object[] { context }); var materializedResult = singleObjectMaterializer.GetType().GetMethod("MakeResult") .Invoke(singleObjectMaterializer, new object[] { backendResults, analysisResult.QueryableType }); return (TResult)InvokePostMaterializationLambda_IfExists(materializedResult, postMaterializationLambda); }); } else { return((context, args) => { var queryType = TypesUtil.GetGenericArgumentForBaseType(analysisResult.MaterializableExpression.Type, typeof(IQueryable <>)); var compiledQuery = Activator.CreateInstance(typeof(CompiledQuery <>).MakeGenericType(queryType), new object[] { GetQueryProvider(context as EntityContext), this, args, compiledBackendMethod, analysisResult.QueryableType.NonPrimitiveEnumerableItemType }); return (TResult)InvokePostMaterializationLambda_IfExists(compiledQuery, postMaterializationLambda); }); } }
private bool NeedsProjectionModification(Expression currentExpression) { //Get the T, when the query returns T or IQueryable<T> var genericTypeOfResult = typeof(IQueryable).IsAssignableFrom(currentExpression.Type) ? TypesUtil.GetGenericArgumentForBaseType(currentExpression.Type, typeof(IQueryable <>)) : currentExpression.Type; //If this is the outermost method, and it is a Non-Primitive Type, we need to modify the Projection // so that we can add implicit includes (like Inhertiance) and user-requested Includes (Prefetch Paths) //There are two cases: // 1) If IQueryable<NonPrimitiveType>, add a Select around translated mce (eg: Where, Select etc) // 2) If just NonPrimitiveType, add a Select around translatedFirstArg (eg: First, Single etc) return(AnalysisContext.ModifyProjection && //Don't modify if context.ModifyProjection is false !(AnalysisContext.QueryableType.NonPrimitiveEnumerableItemType is ProjectedType) && //Don't modify if already modified, that is - context.QueryableType is ProjectedType !TypesUtil.IsPrimitiveDataType(genericTypeOfResult)); //Don't modify if Primitive Type. }
//All Entities need to be bound to the context. public PropertyInfo[] GetPropertiesNeedingContextBinding() { if (source == null) { return(null); } if (source is IEntity) { return(source.GetType().GetProperties() .Where(p => typeof(IEntity).IsAssignableFrom(p.PropertyType) || typeof(IEntityCollection).IsAssignableFrom(p.PropertyType)).ToArray()); } else { return(source.GetType().GetProperties().Where(p => !TypesUtil.IsPrimitiveDataType(p.PropertyType)).ToArray()); } }
/// <summary>Reads the namespaces.</summary> /// <returns>The <see cref="List{T}"/>.</returns> public List <AssemblyScope.AssemblyScope> ReadNamespaces() { // Add all namespaces var namespacePaths = TypesUtil.GetNamespaces(Assembly.Location, Blacklist.Namespaces); var assemblyScopes = new List <AssemblyScope.AssemblyScope>(); foreach (string namespaceData in namespacePaths) { var split = namespaceData.Split(Path.DirectorySeparatorChar, NamespaceData.NamespacePathSeparator); // Breaks up the dn into a name member and namespace only string typeName = split[split.Length - 1]; // Construct namespace path StringBuilder namespaceTextBuilder = new StringBuilder(); int maxNamespaces = split.Length - 1; for (var i = 0; i < maxNamespaces; i++) { if (i != 0) { if (i == maxNamespaces - 1) { namespaceTextBuilder.Append($@"{split[i]}"); } else { // Add namespaces namespaceTextBuilder.Append($@"{split[i]}."); } } } string namespacePath = namespaceTextBuilder.ToString(); assemblyScopes.Add(new AssemblyScope.AssemblyScope(Assembly.Location, namespacePath, typeName)); } if ((Blacklist.Types != null) && (Blacklist.Types.Count > 0)) { foreach (string blackListItem in Blacklist.Types) { int unused = assemblyScopes.RemoveAll(x => x.FullName.ToString().Equals(blackListItem)); } } return(assemblyScopes); }
public Dictionary <MemberInfo, SimpleType> GetAllMembers() { if (TypesUtil.IsCompilerGeneratedAnonymousType(Type)) { var properties = Type.GetProperties(); var dic = new Dictionary <MemberInfo, SimpleType>(); for (int i = 0; i < properties.Length; i++) { dic.Add(properties[i], ConstructorArgs[i]); } return(dic); } else { return(Fields); } }
protected object LoadObject(IObjectGraph source, Dictionary <object, object> parsedObjects) { if (!source.IsAnonymous) { var instance = source.GetInstance(); if (instance is IEntity) { instance = GetCopyInContextOrAttach(instance as IEntity); } LoadIncludes(source, instance, parsedObjects); return(instance); } else { //Anonymous Types var anonType = source.GetInstanceType(); var ctor = anonType.GetConstructors().Single(); var deserializedIncludes = new Dictionary <PropertyInfo, object>(); foreach (var property in source.GetPropertiesNeedingContextBinding()) { if (!TypesUtil.IsNonPrimitiveCollection(property.PropertyType)) { var propertyValue = LoadObject(source.GetObjectGraphForProperty(property), parsedObjects); deserializedIncludes.Add(property, propertyValue); } else { var collectionItems = source.GetObjectGraphForCollection(property) .Select(itemInfo => LoadObject(itemInfo, parsedObjects)).ToList(); var propertyValue = MakeEnumerable(property.PropertyType, collectionItems); deserializedIncludes.Add(property, propertyValue); } } var ctorArgs = deserializedIncludes.Select(kvp => kvp.Value).ToArray(); return(Activator.CreateInstance(anonType, ctorArgs)); } }
public override PostProjectionLoadedResult GetResult(IUnprojectedBinding binding, List <object> objects) { var result = new PostProjectionLoadedResult(); result.ProjectionBinding = binding; var targetType = TypesUtil.GetGenericArgumentForBaseType(binding.TargetBinding.Type, typeof(IEnumerable <>)); Func <AnonymousType, object> valueGetter = ao => Get_GetProjectedValue_Computation(binding.TargetBinding)(new TableEntityRow(ao)); var query = GetQuery(objects, valueGetter, targetType); query = LoadIncludes(query, targetType, GetIncludes(binding)); result.Value = MethodFinder.EnumerableMethods.ToList(targetType).Invoke(null, new object[] { query }) as IList; return(result); }
protected override IValue VisitUnaryMinusExpression(PrefixUnaryExpressionSyntax node) { var operand = Visit(node.Operand); // Debug.Assert(node.OperatorToken.Kind == SyntaxKind.MinusToken); Type t; if (TypesUtil.IsNumberType(operand.ValueType)) { t = operand.ValueType; } else { throw new NotSupportedException(); } var a = new UnaryOperatorExpression(operand, "-", t); return(Simplify(a)); }
//Make an enumerable of type enumerableType and fill it with items. private object MakeEnumerable(Type enumerableType, List <object> items) { if (enumerableType.IsGenericType && TypesUtil.GenericTypeIsAssignableFrom(enumerableType, typeof(ICollection <>))) { return(MakeListOfType(TypesUtil.GetGenericArgumentForBaseType(enumerableType, typeof(ICollection <>)), items)); } else if (enumerableType.IsArray) { var list = MakeListOfType(enumerableType.GetElementType(), items); return(list.GetType().GetMethod("ToArray").Invoke(list, null)); } else { throw new NotSupportedException("The collection of type " + enumerableType.ToString() + " cannot be bound to the context."); } }
//Where the user has mentioned a specific constructor in the query. private Func <object, TableEntityRow, object> Get_CreateTypeWithConstructor_Computation(SimpleType trackedType, MaterializationData data) { var fields = new Dictionary <MemberInfo, KeyValuePair <Func <object, object>, Func <object, TableEntityRow, object> > >(); var constructorArgs = new Dictionary <MemberInfo, KeyValuePair <Func <object, object>, Func <object, TableEntityRow, object> > >(); if (TypesUtil.IsCompilerGeneratedAnonymousType(trackedType.Type)) { constructorArgs = Get_GetMembers_Computation(trackedType.GetAllMembers(), trackedType, data); } else { fields = Get_GetMembers_Computation(trackedType.Fields, trackedType, data); } Action <object, object, TableEntityRow> setCollectionItems = (newObj, projectedEntity, source) => { }; if (trackedType.NonPrimitiveEnumerableItemType != null) { var getOrCreateCollectionItem = Get_GetOrCreateEntityOrCollection_Computation(trackedType.NonPrimitiveEnumerableItemType, data); var addMethod = trackedType.Constructor.DeclaringType.GetMethod("Add", new Type[] { trackedType.NonPrimitiveEnumerableItemType.Type }); setCollectionItems = (newObj, projectedEntity, source) => { foreach (var tableCollectionItem in (projectedEntity as IEnumerable)) { var collItem = getOrCreateCollectionItem(tableCollectionItem, source); addMethod.Invoke(newObj, new object[] { collItem }); } }; } Action <object, MemberInfo, object> setMemberValue = (obj, m, val) => trackedType.Constructor.DeclaringType.GetProperty(m.Name).SetValue(obj, val); return((projectedEntity, source) => { var args = constructorArgs.Select(kvp => kvp.Value.Value(kvp.Value.Key(projectedEntity), source)).ToArray(); var newObj = trackedType.Constructor.Invoke(args); foreach (var fld in fields) { setMemberValue(newObj, fld.Key, fld.Value.Value(fld.Value.Key(projectedEntity), source)); } setCollectionItems(newObj, projectedEntity, source); return newObj; }); }
/// <summary>Initializes a new instance of the <see cref="BlacklistElements"/> struct.</summary> /// <param name="assemblyLocation">The assembly location.</param> public BlacklistElements(string assemblyLocation) { // Initialize variables Location = assemblyLocation; RootName = TypesUtil.DefaultNamespace(assemblyLocation); // Declare default blacklist filter item namespaces Namespaces = new List <string> { $@"{RootName}.Properties" }; // Declare default blacklist filter item types Types = new List <string> { $@"{RootName}.Properties", $@"{RootName}.Settings" }; }
public object SwitchContext(object objects) { var returnType = objects.GetType(); var parsedObjects = new Dictionary <object, object>(); if (!TypesUtil.IsNonPrimitiveCollection(returnType)) { return(LoadObject(new InMemoryInstanceGraph(objects), parsedObjects)); } else { var list = new List <object>(); foreach (var objSource in objects as IEnumerable) { list.Add(LoadObject(new InMemoryInstanceGraph(objSource), parsedObjects)); } return(FillEnumerable(objects, list)); } }
public virtual T GetResult(Expression expression) { var visitor = new QueryTranslationVisitor(new QueryAnalysisContext(entityContext._InternalServices.TypeTranslationUtil) { ModifyProjection = true }); var translationResults = visitor.GetTranslatedResults(expression); var tableEntityQuery = translationResults.AnalysisContext.RootEntityQuery.TableEntityQuery; var tableEntity = tableEntityQuery.Provider.Execute(translationResults.TranslatedExpression); if (TypesUtil.IsPrimitiveDataType(typeof(T))) { return((T)tableEntity); } else { return(MakeResult(tableEntity, translationResults.AnalysisContext.QueryableType)); } }
private List <IRelatedBinding> GetInheritanceBindings(IEnumerable <IRequestedBinding> requestedBindings) { var result = new List <IRelatedBinding>(); foreach (var target in requestedBindings.Where(b => !TypesUtil.IsNonPrimitiveCollection(b.Type))) { //Not a collection. Add Inheritance Bindings if there are any. var inheritanceExpressions = GetInheritanceExpressions(target.Type, target.TranslatedExpression); foreach (var expression in inheritanceExpressions) { var binding = new InheritanceBinding { TargetBinding = target, TranslatedExpression = expression }; result.Add(binding); } } return(result); }