Questions tagged [dynamic]

Dynamic is a widely used term that, in general, describes a decision made by the program at run-time rather than at compile time.

Programs that perform some common tasks based on program inputs in contrast with programs that predetermine the task beforehand. Dynamic is often used to mean:

  • The dynamic keyword
  • using JavaScript to manipulate web pages in the browser.
  • have features that allow the of a variable to be bound at run-time.
  • Program generated content, especially content in contrast with web pages created by a person and stored on disk, ready to serve.
27209 questions
203
votes
12 answers

How to detect if a property exists on an ExpandoObject?

In javascript you can detect if a property is defined by using the undefined keyword: if( typeof data.myProperty == "undefined" ) ... How would you do this in C# using the dynamic keyword with an ExpandoObject and without throwing an exception?
Softlion
  • 12,281
  • 11
  • 58
  • 88
198
votes
4 answers

Differences between ExpandoObject, DynamicObject and dynamic

What are the differences between System.Dynamic.ExpandoObject, System.Dynamic.DynamicObject and dynamic? In which situations do you use these types?
M4N
  • 94,805
  • 45
  • 217
  • 260
193
votes
7 answers

How to create own dynamic type or dynamic object in C#?

There is, for example, the ViewBag property of ControllerBase class and we can dynamically get/set values and add any number of additional fields or properties to this object, which is cool. I want to use something like that, beyond MVC application…
Dmytro
  • 16,668
  • 27
  • 80
  • 130
184
votes
3 answers

Django dynamic model fields

I'm working on a multi-tenanted application in which some users can define their own data fields (via the admin) to collect additional data in forms and report on the data. The latter bit makes JSONField not a great option, so instead I have the…
GDorn
  • 8,511
  • 6
  • 38
  • 37
167
votes
14 answers

How do I check if a property exists on a dynamic anonymous type in c#?

I have an anonymous type object that I receive as a dynamic from a method I would like to check in a property exists on that object. .... var settings = new { Filename="temp.txt", Size=10 } ... function void…
David MZ
  • 3,648
  • 6
  • 33
  • 50
162
votes
5 answers

Android - Dynamically Add Views into View

I have a layout for a view -
Josh
  • 16,286
  • 25
  • 113
  • 158
161
votes
12 answers

Dynamic Anonymous type in Razor causes RuntimeBinderException

I'm getting the following error: 'object' does not contain a definition for 'RatingName' When you look at the anonymous dynamic type, it clearly does have RatingName. I realize I can do this with a Tuple, but I would like to understand why the…
JarrettV
  • 18,845
  • 14
  • 46
  • 43
160
votes
4 answers

Javascript Regexp dynamic generation from variables?

How to construct two regex patterns into one? For example I have one long pattern and one smaller, I need to put smaller one in front of long one. var pattern1 = ':\(|:=\(|:-\('; var pattern2 =…
Somebody
  • 9,316
  • 26
  • 94
  • 142
157
votes
2 answers

How does having a dynamic variable affect performance?

I have a question about the performance of dynamic in C#. I've read dynamic makes the compiler run again, but what does it do? Does it have to recompile the whole method with the dynamic variable used as a parameter or just those lines with dynamic…
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
151
votes
6 answers

JavaScript: how to change form action attribute value based on selection?

I'm trying to change the form action based on the selected value from a dropdown menu. Basically, the HTML looks like this:
n00b0101
  • 6,863
  • 17
  • 42
  • 36
146
votes
5 answers

How do I reflect over the members of dynamic object?

I need to get a dictionary of properties and their values from an object declared with the dynamic keyword in .NET 4? It seems using reflection for this will not work. Example: dynamic s = new ExpandoObject(); s.Path = "/Home"; s.Name = "Home"; //…
Flatliner DOA
  • 6,128
  • 4
  • 30
  • 39
140
votes
4 answers

Call static method with reflection

I have several static classes in the namespace mySolution.Macros such as static class Indent{ public static void Run(){ // implementation } // other helper methods } So my question is how it will be possible to call…
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
139
votes
13 answers

How do I call a dynamically-named method in Javascript?

I am working on dynamically creating some JavaScript that will be inserted into a web page as it's being constructed. The JavaScript will be used to populate a listbox based on the selection in another listbox. When the selection of one listbox is…
Chris B
  • 5,311
  • 11
  • 45
  • 57
133
votes
5 answers

Compiling dynamic HTML strings from database

The Situation Nested within our Angular app is a directive called Page, backed by a controller, which contains a div with an ng-bind-html-unsafe attribute. This is assigned to a $scope var called 'pageContent'. This var gets assigned dynamically…
giraffe_sense
  • 1,333
  • 2
  • 9
  • 4
132
votes
15 answers

Automatically create an Enum based on values in a database lookup table?

How do I automatically create an enum and subsequently use its values in C# based on values in a database lookup table (using enterprise library data layer)? For example, If I add a new lookup value in the database, I don't want to have to manually…
billfredtom
  • 1,634
  • 2
  • 13
  • 11