protected void Prepare(string source, bool minimizeNames = true, bool expectErrors = false) {
			IProjectContent project = new CSharpProjectContent();
			var parser = new CSharpParser();

			using (var rdr = new StringReader(source)) {
				var pf = new CSharpUnresolvedFile { FileName = "File.cs" };
				var syntaxTree = parser.Parse(rdr, pf.FileName);
				syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
				project = project.AddOrUpdateFiles(pf);
			}
			project = project.AddAssemblyReferences(new[] { Files.Mscorlib });

			_errorReporter = new MockErrorReporter(!expectErrors);

			var compilation = project.CreateCompilation();
			var s = new AttributeStore(compilation, _errorReporter);
			RunAutomaticMetadataAttributeAppliers(s, compilation);
			s.RunAttributeCode();

			Metadata = new MetadataImporter(_errorReporter, compilation, s, new CompilerOptions { MinimizeScript = minimizeNames });

			Metadata.Prepare(compilation.GetAllTypeDefinitions());

			AllErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
			AllErrorTexts = _errorReporter.AllMessages.Select(m => m.FormattedMessage).ToList().AsReadOnly();
			if (expectErrors) {
				Assert.That(AllErrorTexts, Is.Not.Empty, "Compile should have generated errors");
			}
			else {
				Assert.That(AllErrorTexts, Is.Empty, "Compile should not generate errors");
			}

			AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);
		}
		public static Tuple<string, MockErrorReporter> Compile(string source, bool expectErrors = false) {
			var sourceFile = new MockSourceFile("file.cs", source);
			var er = new MockErrorReporter(!expectErrors);
			var n = new Namer();
			var references = new[] { Files.Mscorlib };
			var compilation = PreparedCompilation.CreateCompilation("x", new[] { sourceFile }, references, null);;
			var s = new AttributeStore(compilation.Compilation, er);
			var md = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
			var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);
			var l = new MockLinker();
			md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
			var compiler = new Compiler(md, n, rtl, er);

			var compiledTypes = compiler.Compile(compilation).ToList();

			if (expectErrors) {
				Assert.That(er.AllMessages, Is.Not.Empty, "Compile should have generated errors");
				return Tuple.Create((string)null, er);
			}

			Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

			var js = new OOPEmulatorInvoker(new OOPEmulator(compilation.Compilation, md, rtl, n, l, s, er), md, er).Process(compiledTypes, null);
			js = new Linker(md, n, s, compilation.Compilation).Process(js);

			string script = OutputFormatter.Format(js, allowIntermediates: false);

			return Tuple.Create(script, er);
		}
 protected ClassMapping(AttributeStore store)
     : base(store)
 {
     attributes = new AttributeStore<ClassMapping>(store);
     subclasses = new List<ISubclassMapping>();
     joins = new List<JoinMapping>();
 }
		private string Process(IList<JsStatement> stmts, IAssembly[] assemblies, IMetadataImporter metadata = null, INamer namer = null) {
			var compilation = new Mock<ICompilation>();
			compilation.SetupGet(_ => _.MainAssembly).Returns(assemblies[0]);
			compilation.SetupGet(_ => _.Assemblies).Returns(assemblies);
			var s = new AttributeStore(compilation.Object, new MockErrorReporter());
			var obj = new Linker(metadata ?? new MockMetadataImporter(), namer ?? new MockNamer(), s, compilation.Object);
			var processed = obj.Process(stmts);
			return OutputFormatter.Format(processed, allowIntermediates: false);
		}
        protected IdMapping(AttributeStore store, ColumnMapping columnMapping)
            : base(store)
        {
            _attributes = new AttributeStore<IdMapping>(store);
            _columns = new List<ColumnMapping>();

            if(columnMapping != null)
                AddIdColumn(columnMapping);
        }
		public void ConstructorsAreReportedAsJsonConstructors() {
			var compilation = new SimpleCompilation(new CSharpProjectContent());
			var er = new MockErrorReporter(true);
			var s = new AttributeStore(compilation, er);
			var md = new MetadataImporter(er, compilation, s, new CompilerOptions());
			Assert.That(er.AllMessages, Is.Empty, "Prepare should not generate errors");

			var t = CreateType(compilation);

			var c = md.GetConstructorSemantics(DefaultResolvedMethod.GetDummyConstructor(compilation, t));
			Assert.That(c.Type, Is.EqualTo(ConstructorScriptSemantics.ImplType.Json));
		}
		public void AnonymousTypePropertyNamesAreNotMinimized() {
			var compilation = new SimpleCompilation(new CSharpProjectContent());
			var er = new MockErrorReporter(true);
			var s = new AttributeStore(compilation, er);
			var md = new MetadataImporter(er, compilation, s, new CompilerOptions());
			Assert.That(er.AllMessages, Is.Empty, "Prepare should not generate errors");

			var t = CreateType(compilation);

			var p1 = md.GetPropertySemantics(t.GetProperties().Single(p => p.Name == "prop1"));
			Assert.That(p1.Type, Is.EqualTo(PropertyScriptSemantics.ImplType.Field));
			Assert.That(p1.FieldName, Is.EqualTo("prop1"));

			var p2 = md.GetPropertySemantics(t.GetProperties().Single(p => p.Name == "Prop2"));
			Assert.That(p2.Type, Is.EqualTo(PropertyScriptSemantics.ImplType.Field));
			Assert.That(p2.FieldName, Is.EqualTo("Prop2"));
		}
		protected Tuple<ICompilation, IOOPEmulator, List<JsType>> Compile(string source, IEnumerable<IAssemblyResource> resources = null, IErrorReporter errorReporter = null) {
			errorReporter = errorReporter ?? new MockErrorReporter(true);
			var sourceFile = new MockSourceFile("file.cs", source);
			var n = new Namer();
			var references = new[] { Files.Mscorlib };
			var compilation = PreparedCompilation.CreateCompilation("x", new[] { sourceFile }, references, null, resources);
			var s = new AttributeStore(compilation.Compilation, errorReporter);
			RunAutomaticMetadataAttributeAppliers(s, compilation.Compilation);
			s.RunAttributeCode();
			var md = new MetadataImporter(errorReporter, compilation.Compilation, s, new CompilerOptions());
			var rtl = new RuntimeLibrary(md, errorReporter, compilation.Compilation, n, s);
			md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
			var compiler = new Compiler(md, n, rtl, errorReporter);
			var compiledTypes = compiler.Compile(compilation).ToList();

			return Tuple.Create(compilation.Compilation, (IOOPEmulator)new OOPEmulator(compilation.Compilation, md, rtl, n, new MockLinker(), s, errorReporter), compiledTypes);

		}
		private void Prepare(string source, Action preparer) {
			IProjectContent project = new CSharpProjectContent();
			var parser = new CSharpParser();

			using (var rdr = new StringReader(source)) {
				var pf = new CSharpUnresolvedFile { FileName = "File.cs" };
				var syntaxTree = parser.Parse(rdr, pf.FileName);
				syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
				project = project.AddOrUpdateFiles(pf);
			}
			project = project.AddAssemblyReferences(new[] { Files.Mscorlib });

			var compilation = project.CreateCompilation();
			AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);

			var er = new MockErrorReporter(true);
			var s = new AttributeStore(compilation, er);
			Metadata = new MetadataImporter(er, compilation, s, new CompilerOptions());
			preparer();
			Metadata.Prepare(compilation.GetAllTypeDefinitions());
			Assert.That(er.AllMessages, Is.Empty, "Should not generate errrors");
		}
 public override void MergeAttributes(AttributeStore store)
 {
     attributes.Merge(new AttributeStore <SubclassMapping>(store));
 }
Beispiel #11
0
 private ComponentPart(Type entity, Member property, AttributeStore attributes)
     : base(attributes, property)
 {
     this.attributes = attributes;
     this.entity     = entity;
 }
 public IdMapping()
 {
     attributes = new AttributeStore<IdMapping>();
     columns = new List<ColumnMapping>();
 }
		public bool Compile(CompilerOptions options) {
			string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
			var actualOut = Console.Out;
			var er = new ErrorReporterWrapper(_errorReporter, actualOut);
			try {
				Console.SetOut(new StringWriter());	// I don't trust the third-party libs to not generate spurious random messages, so make sure that any of those messages are suppressed.

				var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
				if (er.HasErrors)
					return false;

				if (!options.AlreadyCompiled) {
					// Compile the assembly
					var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
					var d = new Mono.CSharp.Driver(ctx);
					d.Compile();
					if (er.HasErrors)
						return false;
				}

				var references = LoadReferences(settings.AssemblyReferences, er);
				if (references == null)
					return false;

				PreparedCompilation compilation = PreparedCompilation.CreateCompilation(settings.AssemblyName, options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references.Select(r => r.Item1), options.DefineConstants, LoadResources(options.EmbeddedResources));

				IMethod entryPoint = FindEntryPoint(options, er, compilation);

				var container = new WindsorContainer();
				foreach (var plugin in TopologicalSortPlugins(references).Reverse())
					RegisterPlugin(container, plugin);

				var attributeStore = new AttributeStore(compilation.Compilation, er);

				container.Register(Component.For<IErrorReporter>().Instance(er),
				                   Component.For<CompilerOptions>().Instance(options),
				                   Component.For<IAttributeStore>().Instance(attributeStore),
				                   Component.For<ICompilation>().Instance(compilation.Compilation),
				                   Component.For<ICompiler>().ImplementedBy<Compiler.Compiler>()
				                  );

				InitializeAttributeStore(attributeStore, container, compilation.Compilation);

				container.Resolve<IMetadataImporter>().Prepare(compilation.Compilation.GetAllTypeDefinitions());

				var compiledTypes = container.Resolve<ICompiler>().Compile(compilation);

				foreach (var rewriter in container.ResolveAll<IJSTypeSystemRewriter>())
					compiledTypes = rewriter.Rewrite(compiledTypes);

				var invoker = new OOPEmulatorInvoker(container.Resolve<IOOPEmulator>(), container.Resolve<IMetadataImporter>(), container.Resolve<IErrorReporter>());

				var js = invoker.Process(compiledTypes.ToList(), entryPoint);
				js = container.Resolve<ILinker>().Process(js);

				if (er.HasErrors)
					return false;

				string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
				string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

				if (!options.AlreadyCompiled) {
					try {
						File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
					}
					catch (IOException ex) {
						er.Region = DomRegion.Empty;
						er.Message(Messages._7950, ex.Message);
						return false;
					}
					if (!string.IsNullOrEmpty(options.DocumentationFile)) {
						try {
							File.Copy(intermediateDocFile, options.DocumentationFile, true);
						}
						catch (IOException ex) {
							er.Region = DomRegion.Empty;
							er.Message(Messages._7952, ex.Message);
							return false;
						}
					}
				}

				if (options.MinimizeScript) {
					js = ((JsBlockStatement)Minifier.Process(JsStatement.Block(js))).Statements;
				}

				string script = options.MinimizeScript ? OutputFormatter.FormatMinified(js) : OutputFormatter.Format(js);
				try {
					File.WriteAllText(outputScriptPath, script, settings.Encoding);
				}
				catch (IOException ex) {
					er.Region = DomRegion.Empty;
					er.Message(Messages._7951, ex.Message);
					return false;
				}
				return true;
			}
			catch (Exception ex) {
				er.Region = DomRegion.Empty;
				er.InternalError(ex.ToString());
				return false;
			}
			finally {
				if (!options.AlreadyCompiled) {
					try { File.Delete(intermediateAssemblyFile); } catch {}
					try { File.Delete(intermediateDocFile); } catch {}
				}
				if (actualOut != null) {
					Console.SetOut(actualOut);
				}
			}
		}
        private void Prepare(string source, IRuntimeLibrary runtimeLibrary = null, bool expectErrors = false, bool MinimizeNames = false)
        {
            IProjectContent project = new CSharpProjectContent();
            var parser = new CSharpParser();

            using (var rdr = new StringReader(source)) {
                var pf = new CSharpUnresolvedFile() { FileName = "File.cs" };
                var syntaxTree = parser.Parse(rdr, pf.FileName);
                syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
                project = project.AddOrUpdateFiles(pf);
            }
            project = project.AddAssemblyReferences(new[] { Files.Mscorlib, Files.Web, Files.Knockout });

            _compilation = project.CreateCompilation();

            var options = new CompilerOptions { MinimizeScript = MinimizeNames };
            _errorReporter = new MockErrorReporter(!expectErrors);
            var s = new AttributeStore(_compilation, _errorReporter);
            s.RunAttributeCode();
            _metadata = new MetadataImporter(_errorReporter, _compilation, s, options);

            _metadata.Prepare(_compilation.GetAllTypeDefinitions());

            _allErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
            if (expectErrors) {
                Assert.That(_allErrors, Is.Not.Empty, "Compile should have generated errors");
            }
            else {
                Assert.That(_allErrors, Is.Empty, "Compile should not generate errors");
            }

            var rtl = new RuntimeLibrary(_metadata, _errorReporter, _compilation, new Namer(), s);
        }
 protected JoinedSubclassMapping(AttributeStore store)
     : base(store)
 {
     subclasses = new List<JoinedSubclassMapping>();
     attributes = new AttributeStore<JoinedSubclassMapping>(store);
 }
Beispiel #16
0
 protected ClassMap(AttributeStore <ClassMapping> attributes, MappingProviderStore providers);
 public ComponentMapping(AttributeStore store)
     : base(store)
 {
     attributes = new AttributeStore <ComponentMapping>(store);
 }
Beispiel #18
0
 protected override ComponentMapping CreateComponentMappingRoot(AttributeStore store)
 {
     return(new ExternalComponentMapping(ComponentType.Component, attributes.CloneInner()));
 }
Beispiel #19
0
 public NestedCompositeElementMapping(AttributeStore store)
     : base(store)
 {
     attributes = new AttributeStore <NestedCompositeElementMapping>(store);
 }
Beispiel #20
0
 internal ComponentMap(AttributeStore underlyingStore)
     : base(underlyingStore, "")
 {
     attributes = new AttributeStore <ComponentMapping>(underlyingStore);
 }
 protected abstract IComponentMapping CreateComponentMappingRoot(AttributeStore store);
 protected ComponentPartBase(AttributeStore underlyingStore, string propertyName)
 {
     attributes        = new AttributeStore <ComponentMappingBase>(underlyingStore);
     access            = new AccessStrategyBuilder <ComponentPartBase <T> >(this, value => attributes.Set(x => x.Access, value));
     this.propertyName = propertyName;
 }
 public override void MergeAttributes(AttributeStore store)
 {
     attributes.Merge(new AttributeStore <ComponentMapping>(store));
 }
 public CompositeElementMapping(AttributeStore store)
 {
     attributes    = new AttributeStore <CompositeElementMapping>(store);
     mappedMembers = new MappedMembers();
 }
 protected ComponentMappingBase(AttributeStore store)
     : base(store)
 {
     attributes = new AttributeStore<ComponentMappingBase>(store);
 }
 public ExternalComponentMapping(ComponentType componentType, AttributeStore underlyingStore, Member member)
     : base(componentType, underlyingStore, member)
 {
 }
 public OneToManyMapping(AttributeStore underlyingStore)
 {
     attributes = new AttributeStore <OneToManyMapping>(underlyingStore);
 }
Beispiel #28
0
 public IdMapping(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
 }
 public ExternalComponentMapping(ComponentType componentType, AttributeStore underlyingStore)
     : base(componentType, underlyingStore)
 {}
Beispiel #30
0
        public bool Compile(CompilerOptions options)
        {
            string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
            var    actualOut = Console.Out;
            var    er = new ErrorReporterWrapper(_errorReporter, actualOut);

            try {
                Console.SetOut(new StringWriter());                     // I don't trust the third-party libs to not generate spurious random messages, so make sure that any of those messages are suppressed.

                var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
                if (er.HasErrors)
                {
                    return(false);
                }

                if (!options.AlreadyCompiled)
                {
                    // Compile the assembly
                    var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
                    var d   = new Mono.CSharp.Driver(ctx);
                    d.Compile();
                    if (er.HasErrors)
                    {
                        return(false);
                    }
                }

                var references = LoadReferences(settings.AssemblyReferences, er);
                if (references == null)
                {
                    return(false);
                }

                PreparedCompilation compilation = PreparedCompilation.CreateCompilation(settings.AssemblyName, options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references.Select(r => r.Item1), options.DefineConstants, LoadResources(options.EmbeddedResources));

                IMethod entryPoint = FindEntryPoint(options, er, compilation);

                var container = new WindsorContainer();
                foreach (var plugin in TopologicalSortPlugins(references).Reverse())
                {
                    RegisterPlugin(container, plugin);
                }

                var attributeStore = new AttributeStore(compilation.Compilation, er);

                container.Register(Component.For <IErrorReporter>().Instance(er),
                                   Component.For <CompilerOptions>().Instance(options),
                                   Component.For <IAttributeStore>().Instance(attributeStore),
                                   Component.For <ICompilation>().Instance(compilation.Compilation),
                                   Component.For <ICompiler>().ImplementedBy <Compiler.Compiler>()
                                   );

                InitializeAttributeStore(attributeStore, container, compilation.Compilation);

                container.Resolve <IMetadataImporter>().Prepare(compilation.Compilation.GetAllTypeDefinitions());

                var compiledTypes = container.Resolve <ICompiler>().Compile(compilation);

                foreach (var rewriter in container.ResolveAll <IJSTypeSystemRewriter>())
                {
                    compiledTypes = rewriter.Rewrite(compiledTypes);
                }

                var invoker = new OOPEmulatorInvoker(container.Resolve <IOOPEmulator>(), container.Resolve <IMetadataImporter>(), container.Resolve <IErrorReporter>());

                var js = invoker.Process(compiledTypes.ToList(), entryPoint);
                js = container.Resolve <ILinker>().Process(js);

                if (er.HasErrors)
                {
                    return(false);
                }

                string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
                string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

                if (!options.AlreadyCompiled)
                {
                    try {
                        File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
                    }
                    catch (IOException ex) {
                        er.Region = DomRegion.Empty;
                        er.Message(Messages._7950, ex.Message);
                        return(false);
                    }
                    if (!string.IsNullOrEmpty(options.DocumentationFile))
                    {
                        try {
                            File.Copy(intermediateDocFile, options.DocumentationFile, true);
                        }
                        catch (IOException ex) {
                            er.Region = DomRegion.Empty;
                            er.Message(Messages._7952, ex.Message);
                            return(false);
                        }
                    }
                }

                if (options.MinimizeScript)
                {
                    js = ((JsBlockStatement)Minifier.Process(JsStatement.Block(js))).Statements;
                }

                string script = options.MinimizeScript ? OutputFormatter.FormatMinified(js) : OutputFormatter.Format(js);
                try {
                    File.WriteAllText(outputScriptPath, script, settings.Encoding);
                }
                catch (IOException ex) {
                    er.Region = DomRegion.Empty;
                    er.Message(Messages._7951, ex.Message);
                    return(false);
                }
                return(true);
            }
            catch (Exception ex) {
                er.Region = DomRegion.Empty;
                er.InternalError(ex.ToString());
                return(false);
            }
            finally {
                if (!options.AlreadyCompiled)
                {
                    try { File.Delete(intermediateAssemblyFile); } catch {}
                    try { File.Delete(intermediateDocFile); } catch {}
                }
                if (actualOut != null)
                {
                    Console.SetOut(actualOut);
                }
            }
        }
 public OneToManyMapping()
 {
     attributes = new AttributeStore<OneToManyMapping>();
     attributes.SetDefault(x => x.ExceptionOnNotFound, true);
 }
 public CompositeElementMapping(AttributeStore attributes)
 {
     this.attributes = attributes;
     mappedMembers   = new MappedMembers();
 }
		private void InitializeAttributeStore(AttributeStore attributeStore, WindsorContainer container, ICompilation compilation) {
			var assemblies = compilation.Assemblies;
			var types = compilation.GetAllTypeDefinitions().ToList();
			foreach (var applier in container.ResolveAll<IAutomaticMetadataAttributeApplier>()) {
				foreach (var a in assemblies)
					applier.Process(a);
				foreach (var t in types)
					applier.Process(t);
			}
			attributeStore.RunAttributeCode();
		}
 public IndexMapping()
 {
     attributes = new AttributeStore<IndexMapping>();
 }
 protected ComponentMappingBase(AttributeStore attributes)
     : base(attributes)
 {
     this.attributes = attributes;
 }
 public abstract void MergeAttributes(AttributeStore store);
 public SubclassMapping(SubclassType subclassType, AttributeStore underlyingStore)
 {
     SubclassType = subclassType;
     attributes   = new AttributeStore <SubclassMapping>(underlyingStore);
 }
Beispiel #38
0
 private DynamicComponentPart(Type entity, Member member, AttributeStore underlyingStore, MappingProviderStore providers)
     : base(underlyingStore, member, providers)
 {
     this.entity    = entity;
     this.providers = providers;
 }
 protected CollectionMappingBase(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
     _attributes = new AttributeStore<ICollectionMapping>(underlyingStore);
     _attributes.SetDefault(x => x.Cascade, CollectionCascadeType.None);
 }
		public void TransparentIdentiferIsValidJavascriptIdentifierStartingWithDollar() {
			var compilation = new SimpleCompilation(new CSharpProjectContent());
			var er = new MockErrorReporter(true);
			var s = new AttributeStore(compilation, er);
			var md = new MetadataImporter(er, compilation, s, new CompilerOptions());
			Assert.That(er.AllMessages, Is.Empty, "Prepare should not generate errors");

			var t = CreateType(compilation, new[] { "<>Identifier" });

			var c = md.GetPropertySemantics(t.GetProperties().Single());
			Assert.That(c.Type, Is.EqualTo(PropertyScriptSemantics.ImplType.Field));
			Assert.That(c.FieldName, Is.EqualTo("$Identifier"));
		}
 public void OverrideAttributes(AttributeStore store)
 {
     attributes = new AttributeStore <SubclassMapping>(store);
 }
 protected BagMapping(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
     attributes = new AttributeStore<BagMapping>(underlyingStore);
 }
 public ManyToManyMapping()
 {
     attributes = new AttributeStore<ManyToManyMapping>();
 }
 public ComponentMapping(ComponentType componentType, AttributeStore attributes)
     : base(attributes)
 {
     ComponentType   = componentType;
     this.attributes = attributes;
 }
 public IdGeneratorMapping()
 {
     _attributes = new AttributeStore<IdGeneratorMapping>();
 }
 public NestedCompositeElementMapping(AttributeStore store)
     : base(store)
 {
     attributes = new AttributeStore<NestedCompositeElementMapping>(store);
 }
 public KeyMapping()
 {
     attributes = new AttributeStore<KeyMapping>();
 }
Beispiel #48
0
 protected CollectionMappingBase(AttributeStore underlyingStore)
 {
     attributes = new AttributeStore <ICollectionMapping>(underlyingStore);
     attributes.SetDefault(x => x.Mutable, true);
 }
Beispiel #49
0
 public IdMapping(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
 }
        private Tuple<JsClass, MockErrorReporter> Compile(string source, bool expectErrors = false)
        {
            var sourceFile = new MockSourceFile("file.cs", source);
            var er = new MockErrorReporter(!expectErrors);
            var n = new Namer();
            var references = new[] { Mscorlib, QUnit };
            var compilation = PreparedCompilation.CreateCompilation("Test", new[] { sourceFile }, references, null);
            var s = new AttributeStore(compilation.Compilation, er);
            s.RunAttributeCode();
            var md = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);
            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler = new Compiler(md, n, rtl, er);

            var result = compiler.Compile(compilation).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should compile exactly one type");
            Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

            result = new TestRewriter(er, rtl, s).Rewrite(result).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should have one type after rewrite");
            Assert.That(result[0], Is.InstanceOf<JsClass>(), "Compiled type should be a class after rewrite");

            if (expectErrors) {
                Assert.That(er.AllMessages, Is.Not.Empty);
            }
            else {
                Assert.That(er.AllMessages, Is.Empty);
            }

            return Tuple.Create((JsClass)result[0], er);
        }
 public void CreateNewAttributeStore()
 {
     var store = new AttributeStore();
     var value = new object();
     store.Set("name1", value, new NameValueMapAttribute { Name = "A.B.C" });
     store.Get("name1").Layer.ShouldEqual(3);
     store.Get("name1").Value.ShouldEqual(value);
     store.Set("name1", value, new NameValueMapAttribute { Name = "A.B" });
     store.Get("name1").Layer.ShouldEqual(2);
     store.Get("name1").Value.ShouldEqual(value);
     store.Equals(store.Clone()).ShouldBeTrue();
 }
 public ArrayMapping(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
     attributes = new AttributeStore <ArrayMapping>(underlyingStore);
 }