Dart元编程特性 [英] Dart meta programming features

查看:146
本文介绍了Dart元编程特性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dart中有一个等价的c#Reflection.Emit命名空间吗?

Will there be an equivelent of the c# Reflection.Emit namespace in dart?

Reflection.Emit有许多类用于在运行时构建类型并添加属性,在运行时配置他们的getter和setter和构建方法和事件处理程序,这是真正强大的,当它涉及元编程。

Reflection.Emit has a number of classes that are used to build types at run time and adding properties, configering their getters and setter and building methods and event handlers all at run time, which is really powerfull when it comes to metaprogramming.

我的想法是关于生成我的数据模型在运行时和缓存他们在一个映射,所以我可以创建实例在运行时,并添加新的方法和属性,当我需要,而不是经常在生成类后使用镜像,这可能是非常有用的,当编写ORM和更多动态应用程序,其中使用反射一次,而不是每次需要修改实例时使用它

my idea is about generating my data models at run time and caching them in a map so i can create instances at run time and add new methods and properties to them when i need to and not having to use mirrors often after generating the class, this could be really useful when writing ORMs and more dynamic applications where you use reflection once rather than using it every time you need to modify an instance

我的问题是:


  • 在未来版本的dart中会有这样的东西吗?他们提到
    关于镜像生成器,但我不知道如果是相同的
    的东西,可以有人请确认是什么镜像生成器是
    吗?

  • 另一个问题是,如果我能够在
    服务器上生成我的数据类型作为字符串,是否有一种方法来编译它们发送
    给客户端并将它们映射到Map中,并使用此Map创建实例?

  • Will there be such thing in the future versions of dart? they mention something about a Mirror Builder but i am not sure if does the same thing, can some one please confirm if thats what a Mirror Builder is about?
  • another question is, if i am able to generate my data types on the server as strings, is there a way to to compile them before sending them to the client and map them in a Map and use this Map to create instances?

推荐答案

我已经看到一些讨论,这应该支持在某些时候,但据我所知不会开始在不久的将来开始工作。

I have seen discussions that this should be supported at some time but as far as I know will not be started to work on in the near future.

类似的需求通常通过在构建时通过代码生成(Polymer,Angular,其他)通过变换器来解决,变换器分析代码并生成反射属性访问的代码或HTML中的代码片段。

Similar requirements are usually solved by code generation at build time (Polymer, Angular, others) by transformers which analyze the code and generated code for reflective property access or code snippets in HTML.

Smoke 是一个旨在简化此过程的软件包。

Smoke is a package that aims to simplify this.

代码生成的优点是客户端需要下载的代码量小得多。
当你在运行时生成代码时,你需要一个编译器,这是需要下载到浏览器中的很多代码。

Code generation has the advantage that the amount of code needed to be downloaded by the client is much smaller. When you do code generation at runtime you need a compiler and that is a lot of code that needs to be downloaded into the browser.

try.dartlang.org 采取这样的方法。来源可在此处 https://代码.google.com / p / dart / source / browse / branches / bleeding_edge / dart / site / try /
它包括dart2js(构建到JavaScript),并运行一个背景隔离,将Dart代码编译为JS。

try.dartlang.org takes a such an approach. The source is available here https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/site/try/ . It includes dart2js (built to JavaScript) and runs a background isolate that compiles the Dart code to JS.

这篇关于Dart元编程特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆