Comments (2)
I am a bit curious. In what situation are you using DynamicObject
? I can see someone using an ExpandoObject
, but I don't know in what context an actual instance of DynamicObject
is getting tossed around. Is this something another library is returning to your code?
Normally, projects use a DynamicObject
to provide access to an underlying dictionary items via properties. In many of the libraries I have used, you can get direct access to the dictionary (raw) representation, as well.
This is still definitely something I'd like to support at some point. I am actually debating whether it would make sense in my event handlers to expose key/variable scopes using a dynamic
object, a thin DynamicObject
wrapper around my Scope
class.
Just curious...
from mustache-sharp.
Sorry I hadn't gotten back to you sooner. DynamicObject
is an abstract type and the base object of ExpandoObject
. While I am not sure what higher level object of type DynamicObject
gets created when the dynamic
keyword is used, it is evident that all objects created out of the dynamic
keyword are some implementation of the DynamicObject
type.
The DynamicObject
type actually has three basic sets of operations in which it can be used. It can be used as a key-value container (such as an object with properties/attributes), via TryGetMember()
, TrySetMember()
, and TryDeleteMember()
; as an index-value container (such as a list or an array), via TryGetIndex()
, TrySetIndex()
, and TryDeleteIndex()
; or as a simple value container (such as a string or an integer or a boolean or any higher level object), via TryConvert()
, which should try to cast the value of a type out of the DynamicObject
instance.
But, alone, DynamicObject
doesn't implement these. It is up to the implementer to decide on how to store and retrieve this information. However the compiler does it, I do not know. However ExpandoObject works, we can presume that it uses a Dictionary<string, object>
type.
For my particular needs, I needed a DynamicObject
created at run-time, not at declaration-time, and it needed to behave as any of a value, object, or array type. ExpandoObject
simply does not do this. And since there is no specific implementation of DynamicObject
that really does anything like this, I decided to implement my own DynamicObject
type that does, and interestingly enough, called it Scope
--not to be confused with your Scope
type.
My end game was to be able to create a global variable Scope
object, be able to manipulate it by either setting an internal value; adding members, which also get wrapped by another Scope
instance; or adding indexed members, which also get wrapped by another Scope
instance. So, for every variable stored at any level, it will be at a minimum stored as a value-based Scope
instance. This then creates a tree of Scope
objects, which at their node-level contain some value object and at their tree level either use a Dictionary or a List to store either members or indexed members, respectively.
The final purpose was to be able to take input data from any data source and dump it into a variable of type Scope
and to be able to either assign that Scope
to the global scope or assign it to a member of any other Scope
within the global scope. So, for instance, I could import a data table Customers
into a Scope
instance of the indexed type, with at each indexed member a Scope
of the member type, with at each member, a Scope
of the value type. And when this DynamicObject
gets sent to your Generator.Render()
method that I have modified for supporting DynamicObject
objects, then template code that looks like {{#each Customers}}{{Name}}{{#newline}}{{Address1}}{{#newline}}...{{/each}}
would actually be able to retrieve data in a very systematic way. This is useful because I wanted to be able to import multiple data sources into the same object-property variable schema.
... And, it works. Hopefully you can see where I'm going with this.
from mustache-sharp.
Related Issues (20)
- If ... Or ... HOT 2
- ConditionTagDefinition HOT 2
- Remove line hop on unix systems HOT 7
- Library doesn't work with dynamic object
- JToken HOT 1
- Escaping string for json templating HOT 2
- Creation of a custom tag HOT 2
- {{ }} around property with spaces in the name HOT 2
- adding padding spaces to an identifier HOT 3
- Calculation in identifier HOT 1
- Exception 'After parsing a value an unexpected character was encountered' is raised for properties containing single braces or empty strings HOT 3
- Redundancy and differencies with mustach spec making it not compliant.
- IF does not work when using JOject HOT 3
- Removal of newlines in HtmlFormatCompiler actually causing a problem HOT 1
- Help creating custom tag HOT 1
- {{#if}} does not work with JObject
- how i add if condition like {{#if condition == true}} {{do somthing} {{/if} mustache sharp HOT 1
- Invalid handlebarsjs else tag
- Rendering of template simply doubles each {{#newline}} HOT 1
- Is it a safe assumption that this project is dead? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mustache-sharp.