コード例 #1
0
        private List <ProjectionMapping> GetMappings(List <RazorRange> razorRanges)
        {
            List <ProjectionMapping> list = new List <ProjectionMapping>();

            ServiceManager.GetService <ProjectionBufferManager>(_viewBuffer);
            ITextSnapshot currentSnapshot = _viewBuffer.CurrentSnapshot;
            string        fileName        = Path.GetFileName(_fullPath);

            foreach (KeyValuePair <int, int> current in _linePragmaReader.GetCodePositions(_code, fileName))
            {
                GeneratedCodeMapping generatedCodeMapping;
                if (_result.DesignTimeLineMappings.TryGetValue(current.Key, out generatedCodeMapping))
                {
                    int num        = currentSnapshot.GetLineFromLineNumber(generatedCodeMapping.StartLine - 1).Start.Position + generatedCodeMapping.StartColumn - 1;
                    int num2       = current.Value + generatedCodeMapping.StartGeneratedColumn - 1;
                    int codeLength = generatedCodeMapping.CodeLength;
                    foreach (RazorRange current2 in razorRanges)
                    {
                        if (current2.Start == num && current2.Length == codeLength)
                        {
                            ProjectionMapping item = new ProjectionMapping(num, num2, codeLength, current2.TrailingInclusion);
                            list.Add(item);
                            break;
                        }
                    }
                }
            }
            return(list);
        }
コード例 #2
0
            private IBsonSerializer BuildProjectedSerializer(ProjectionMapping mapping)
            {
                // We are building a serializer specifically for a projected type based
                // on serialization information collected from other serializers.
                // We cannot cache this in the serializer registry because the compiler reuses
                // the same anonymous type definition in different contexts as long as they
                // are structurally equatable. As such, it might be that two different queries
                // projecting the same shape might need to be deserialized differently.
                var          classMapType = typeof(BsonClassMap <>).MakeGenericType(mapping.Expression.Type);
                BsonClassMap classMap     = (BsonClassMap)Activator.CreateInstance(classMapType);

                foreach (var memberMapping in mapping.Members)
                {
                    var serializationExpression = memberMapping.Expression as ISerializationExpression;
                    if (serializationExpression == null)
                    {
                        var serializer        = Build(memberMapping.Expression);
                        var serializationInfo = new BsonSerializationInfo(
                            memberMapping.Member.Name,
                            serializer,
                            TypeHelper.GetMemberType(memberMapping.Member));
                        serializationExpression = new SerializationExpression(
                            memberMapping.Expression,
                            serializationInfo);
                    }

                    var memberMap = classMap.MapMember(memberMapping.Member)
                                    .SetSerializer(serializationExpression.SerializationInfo.Serializer)
                                    .SetElementName(memberMapping.Member.Name);

                    if (classMap.IdMemberMap == null && serializationExpression is IdExpression)
                    {
                        classMap.SetIdMember(memberMap);
                    }
                }

                var mappedParameters = mapping.Members
                                       .Where(x => x.Parameter != null)
                                       .OrderBy(x => x.Parameter.Position)
                                       .Select(x => x.Member)
                                       .ToList();

                if (mappedParameters.Count > 0)
                {
                    classMap.MapConstructor(mapping.Constructor)
                    .SetArguments(mappedParameters);
                }

                var serializerType = typeof(BsonClassMapSerializer <>).MakeGenericType(mapping.Expression.Type);

                return((IBsonSerializer)Activator.CreateInstance(serializerType, classMap.Freeze()));
            }
コード例 #3
0
ファイル: BufferGenerator.cs プロジェクト: skrutsick/RTVS
        public virtual string GenerateContent(ITextSnapshot snapshot, IEnumerable <ITextRange> languageBlocks, out ProjectionMapping[] mappings)
        {
            var mappingsList   = new List <ProjectionMapping>();
            var secondaryIndex = 0;

            var sb = new StringBuilder();

            foreach (var b in languageBlocks)
            {
                var text = snapshot.GetText(b.Start, b.Length);
                secondaryIndex = sb.Length;

                sb.AppendLine(text);
                var m = new ProjectionMapping(b.Start, secondaryIndex, b.Length);
                mappingsList.Add(m);
            }

            mappings = mappingsList.ToArray();
            return(sb.ToString());
        }
コード例 #4
0
            private BsonValue BuildMapping(ProjectionMapping mapping)
            {
                BsonDocument doc   = new BsonDocument();
                bool         hasId = false;

                foreach (var memberMapping in mapping.Members)
                {
                    var    value = BuildValue(memberMapping.Expression);
                    string name  = memberMapping.Member.Name;
                    if (!hasId && memberMapping.Expression is IdExpression)
                    {
                        name  = "_id";
                        hasId = true;
                        doc.InsertAt(0, new BsonElement(name, value));
                    }
                    else
                    {
                        doc.Add(name, value);
                    }
                }

                return(doc);
            }
コード例 #5
0
		private List<ProjectionMapping> GetMappings(List<RazorRange> razorRanges)
		{
			List<ProjectionMapping> list = new List<ProjectionMapping>();
			ServiceManager.GetService<ProjectionBufferManager>(_viewBuffer);
			ITextSnapshot currentSnapshot = _viewBuffer.CurrentSnapshot;
			string fileName = Path.GetFileName(_fullPath);
			foreach (KeyValuePair<int, int> current in _linePragmaReader.GetCodePositions(_code, fileName))
			{
				GeneratedCodeMapping generatedCodeMapping;
				if (_result.DesignTimeLineMappings.TryGetValue(current.Key, out generatedCodeMapping))
				{
					int num = currentSnapshot.GetLineFromLineNumber(generatedCodeMapping.StartLine - 1).Start.Position + generatedCodeMapping.StartColumn - 1;
					int num2 = current.Value + generatedCodeMapping.StartGeneratedColumn - 1;
					int codeLength = generatedCodeMapping.CodeLength;
					foreach (RazorRange current2 in razorRanges)
					{
						if (current2.Start == num && current2.Length == codeLength)
						{
							ProjectionMapping item = new ProjectionMapping(num, num2, codeLength, current2.TrailingInclusion);
							list.Add(item);
							break;
						}
					}
				}
			}
			return list;
		}