w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
DynamicObject's dynamic property does not bind
Looks like there's a bug in Silverlight. Here's the report. The "Workarounds" tab of that page contain 4 different workarounds, each with its pros and cons.

Categories : Wpf

How to get ServiceStack to serialize a dynamic (ExpandoObject) property on request
You may have seen this announcement: The next major v4.0 will also be a "breaking-release", with new features protected under an "AGPL/FOSS License Exception" and include a number of breaking changes that have built up over time, including upgrading all projects (to .NET 4+), major code and NuGet package re-factoring, clean-up and removal of deprecated code, better consistency / simplification of some concepts and implementation of some roadmap features I've been wanting to add but never had time for. Fixes and releases will continue to v3.x and be maintained in a separate v3 branch until v4.0 comes out of beta. As there's no reason to fix dynamic object support in the current 3.x branch, which doesn't support .Net4.0, the answer is 'No, ServiceStack can't serialize the JSON request

Categories : Json

Attempting to create a read-only property attribute - getter returns initialized value, direct access returns changed value
I use property as decorator. It convenient for calculating data. May be for make read-only attribute better use magic function as __set__ and __get__?

Categories : Python

DynamicObject? How does the following code work?
When you try to access a property on a DynamicObect, the DLR calls its TryGetMember method at runtime (see how WebGridRow implements it). What you get back is that method's result, provided through its out parameter. A most important detail here is that your lambda function argument item is not typed as WebGridRow -- in that case this code would not compile. Dynamism is achieved because the signature of WebGrid.Column declares the format parameter as a Func<dynamic, object> -- it's the dynamic type of the argument that allows the DLR to take over.

Categories : C#

Is there something like DynamicObject.TryGetMember for "normal" properties?
You can define your setters and getters as you like. In the setters and getters of those properties you can implement your custom logic. Read more about properties in this tutorial.

Categories : C#

'System.Dynamic.DynamicObject' does not contain a definition for 'PropertyName'
I believe this is your problem from another stackoverflow answer: As we can see by your comments, you are setting the ViewBag.Message in another controller. The ViewBag is only for data for the view that was set by the controller that served the view. If you need to send it from another controller, you should use a parameter in your action method, then you can set the ViewBag.Message to the passed in parameter. ViewBag RuntimeBinderException (MVC 4, ASPX)

Categories : C#

Using DynamicObject (IDynamicMetaObjectProvider) as a component of a static type leads to infinite loop
I think the problem is that the Expression parameter passed to GetMetaObject represents the target of the dynamic invocation (i.e. the current object). You are passing the outer object to the call on component.GetMetaObject, so the returned meta object is trying to resolve the call to AMethod on the outer object instead of itself, hence the infinite loop. You can create your own meta object which delegates to the inner component when binding member invocations: public class AStaticComponent : VendorLibraryClass, IDynamicMetaObjectProvider { IDynamicMetaObjectProvider component = new DynamicComponent(); public DynamicMetaObject GetMetaObject(Expression parameter) { return new DelegatingMetaObject(component, parameter, BindingRestrictions.GetTypeRestriction(parameter,

Categories : C#

FormCollection to expandoObject
Well, not the most elegant code (probably better ways to do it), but one way could be something like this: [HttpPost] public ActionResult Test(FormCollection collection) { dynamic expando = new ExpandoObject(); var dictionary = (IDictionary<string, object>) expando; foreach (var item in collection.AllKeys.ToDictionary(key => key, value => collection[value])) { dictionary.Add(item.Key, item.Value); } // your expando will be populated here ... // do awesomeness } I hope this helps (at least it might give you an idea).

Categories : C#

How to access a javascript object's property, when it has a dynamic number as property title?
There is example, how you can access to properties of your object with loop: http://jsfiddle.net/Y7mHB/ var names = { 15: '15', 117: '117' }; for(var key in names) { alert(key + ' ' + names[key]); }

Categories : Javascript

Is it possible to query list of ExpandoObject?
Your suggestion is right, you would be able to query a collection of dynamic objects using the dot notation. var ids = generatedItems.Cast<dynamic>().Select(x => x.Id); However, keep in mind that there's no type safety here and, as you stated, IntelliSense is of no use, since you're using dynamic objects. If your code depends on whether one of those objects have an optional property (e.g., some have "Title", others don't), then it will require a little more manual labor. if((generatedItems as IDictionary<String, object>).ContainsKey("Title")) { }

Categories : C#

"'System.Dynamic.ExpandoObject' does not contain a definition for "PropertyName"
I gather this is expected behavior when using an ExpandoObject. I took a look at the IntelliTrace log for this code and the entries for the exceptions you are seeing are paired up: Exception:Thrown: "'System.Dynamic.ExpandoObject' does not contain a definition for 'clients'" (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) Exception:Caught: "'System.Dynamic.ExpandoObject' does not contain a definition for 'clients'" (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) i.e. The exception is being thrown and then caught. If you look at the Call Stack Window you will see that the throws and catches are within the .NET Framework. BTW, I did have to make a small change to your code to make it run: I changed: root.clients.client.Count to root.clients.Count in the for loop.

Categories : C#

Is property getter called even if I access property by name?
Oops. Just tried it. Apparently i use dot notation too much, and didn't realize just how much it was doing. :P #import "NSObject.h" #include <stdio.h> @interface Test : NSObject @property (getter=myStuff) int stuff; @end @implementation Test -(int)myStuff { return 42; } -(void)setStuff:(int)value { /* don't care */ } @end int main() { @autoreleasepool { Test* test = [[Test alloc] init]; /* All these work... */ printf("test.stuff == %d ", test.stuff); printf("[test myStuff] == %d ", [test myStuff]); printf("test.myStuff == %d ", test.myStuff); /* but here, there's an exception */ printf("[test stuff] == %d ", [test stuff]); return 0; } } When i compile this (using clang in Linux), there are two warnin

Categories : Objective C

How to access an object literal property from another property?
I think you can wrap the config object, e.g. var config = (function() { var _url = 'http://google.com'; return { url : _url, message : 'You must go to <a href="' + _url + '">Google</a> to search!' } })();

Categories : Javascript

How to use a lambda expression on an ExpandoObject C# to find an array element value?
I assume gifts is of the type List<Gift[]>. Then you would do: var test = ((List<Gift[]>)Model.moduleData.gifts).FirstOrDefault(item => item[index][0] == 99); The reason is that the type of gifts is not known at compile time, so the C# compiler has no way of resolving the type of lambda that's being specified.

Categories : C#

I can't access property on my object via Expression.Property unless the type of the fed expression is strongly-typed
Inner is declared as an object. And clearly, an object doesn't contain a Value property. You need to "convert" that expression to the expected type before you attempt to access that property. This is equivalent to adding a cast to the expression. Func<OuterClass, object> e = Expression.Lambda<Func<OuterClass, object>>( Expression.Property( Expression.Convert(Expression.Property(p, "Inner"), typeof(InnerClass)), "Value" ), p ).Compile();

Categories : C#

Implementing DynamicObject functionality on a class that extends another class
It's hard to say with such a very generic description. The common pattern I'm familiar with is: public class MainClass{ foo bar(); more stuff {get;set;} .... } public class ExtendedClass:MainClass{ protected class Helper:DynamicObject{ ...} private Helper _helper; public Extended(){ _helper= new Helper(this); } public dynamic Extend { get{ return _helper}; } } That way your dynamic properties or methods have their own namespace if you will by requiring to call Extend first to sort of trampoline.

Categories : C#

How to add a property to an entity dynamically?
The syntax is very simple for this, but the background info is more important, please read the whole answer before you reuse the snippet. The YourType can be extended with new fields using the YourType.addMember() function. See this example snippet: $data.Entity.extend('Product', { id: { type: 'int', key: true, computed: true }, Name: { type: 'string' } }); $data.EntityContext.extend('Northwind', { Products: { type: $data.EntitySet, elementType: Product}, }); Product.addMember('Description', { type:'string', key: false, computed: false, required: false }); var context = new Northwind({provider: 'webSql', databaseName: 'Northwind'}); context.onReady(function() { var product1 = new Product({ Name: 'Beer', Description: 'tasty'}); context.Products.add(pro

Categories : Javascript

Can I change property of panel dynamically in Ext JS?
You will want to add a member function to your panel class to do the actual work of updating what is shown on the screen: setSomeProperty: function(prop) { this.down('#someContainer').update({someProperty: prop}); }

Categories : Extjs

Struts 2.0 - dynamically append the s:property value
Maybe it is not the best way to handle such case, but what you asking for could be done something like so: <s:iterator value="animalsList" id="eachAnimal"> <s:property value="#attr[#eachAnimal].lifespan" /> </s:iterator>

Categories : Java

Dynamically setting a property in ndb object
What you are looking for is the Expando class (additionnal documentation here). You can safely replace ndb.Model with ndb.Expando in your model classes, your persisted entities will still be perfectly usable. Note: However, it might not work the other way around; ndb will crash if you try to manipulate (fetch/put) an ndb.Model entity that has attributes that are not declared in its class.

Categories : Python

Setting the onClick property dynamically
This will work: function gengrid() { var i=0; var num_stud=8; var newdiv; var divIdName; var maindiv; for(i=1;i<=num_stud;i++) { newdiv = document.createElement('div'); divIdName = '50'+i; newdiv.setAttribute('id',divIdName); (function(i){ newdiv.onclick= function(){addit(i);}; })(i) newdiv.innerHTML = '<img src=50'+i+'.jpg alt="a"></img>'; maindiv=document.getElementById('main'); maindiv.appendChild(newdiv); } } function addit(picno) { alert(picno+''); } window.onload = gengrid ; Have a look: http://jsfiddle.net/cherniv/9NdvA/1/ Few things: 1) Wait till DOM is ready ( window.onload ) 2) newdiv.onclick instead of

Categories : Javascript

How to have a dynamically added function access dynamically added properties
You've made addMethod a class method. Python class methods can be called on an instance, as you do here with obj.addMethod(toString), but in that case the instance is used only to get its class; the first argument passed to addMethod is the class of obj. Your addMethod call then makes the function passed as its second argument (in this example, toString) a bound method of the class. The instruction obj.toString() then first searches for the toString attribute of obj; that lookup process finds an attribute of the class that's also callable. But what you invoke then is not a bound method of the instance, but a bound method of the class. The method is then called with the class as the value of target and so it prints the attributes of the class, not those of the instance. I'm not sure

Categories : Python

Sencha set Ext.Panel 'scrollable' property dynamically
Rather than using Ext.get(), which returns a DOM element instead of a Sencha component, you likely want to just reference the view itself, which would have setScrollable(). onShow: function () { var me = this; // #canvasSignature is the id of the canvas that is loaded in the controller and placed in #canvasDiv $("#canvasSignature").mousedown(function() { me.setScrollable(false); //attempting to reference panel }).bind('mouseup mouseleave', function() { me.setScrollable(true); //attempting to reference panel }); } You could also override the Panel's initialize() method rather than needing to attach a listener. initialize: function () { this.callParent(arguments); var me = this; // #canvasSignature is the id of the canvas that is loaded i

Categories : Jquery

Dynamically read and filter an XML file
I am assuming you are using a DOM-based (NSXMLDocument?) approach to load your iTunes library. This would explain the memory consumption and slow startup behavior. To avoid loading the whole document into RAM at once, you should switch to a SAX parser and skip elements that you are not interested in. Cocoa's built in SAX Parser is NSXMLParser, which allows you to sequentially read and filter elements by conforming to NSXMLParserDelegate. As you seem to build a iTunes related app: Apple recently published documentation for the now public iTunesLibrary.framework.

Categories : Objective C

can not read value from dynamically create control
That's because you create the control when Button1 is clicked, and then try and access it when Button2 is clicked. Dynamic controls must be created on every post back because that state is not maintained. Instead of just building the control in Button1 click, set a flag in Session so you know to rebuild it on Load too. So, in Button1_Click, at the very end of the method, add this line: Session["BuildMyText"] = true; and then in Page_Load: if (Session["BuildMyText"] != null && (bool)Session["BuildMyText"]) { // build the text box here too } and then finally, wrap the construction of the text box in the Button1_Click like this: if (Session["BuildMyText"] != null && (bool)Session["BuildMyText"]) { ... }

Categories : C#

How is it possible to write what looks like a read only property?
If you define a class like this: public class YourClass { public string MyProperty { get; private set; } } It will appear as get-only to the outside. Exception probably looks something like this: public class Exception { public Exception(string message) { this.Message = message; } public string Message { get; private set; } }

Categories : C#

Cannot read property 'value' of null
See corrections needed below, lines 6 and 7: function login() { $("#login_box").append("logging you in...."); var u = $('#login_username').val(); var p = $('#login_password').val(); var al = $('#login_autologin').is(':checked'); console.log(u, p, al); $.post("user.php?mode=login", { username : u, password : p, autologin : al, }).done(function(data) { result = JSON.parse(data); if (result.status == 3) { $("#login_box").html( "Welcome back, " + result.user_row.username + "!"); } else { $("#login_box") .html("You was not logged in: , " + result.error_msg); } }); }

Categories : Javascript

cannot read property 'ntr' of undefined
You could check if your table is populated, and if not return: $('#example_table tbody td').live('mouseover mouseout', function(event) { if (event.type == 'mouseover') {// do something on mouseover console.log('inside mouseover'); // check if you have data in your table if (oTable.fnGetData().length <= 0) { // or some similar check return; } var iPos = oTable.fnGetPosition( this ); // getting error in this line if(iPos!=null){ console.log(iPos); var iCol= iPos [1]; } } });

Categories : Jquery

Cannot Read Property Javascript
You should do this (using this) data.response.results[0].followers.count; (And of course if you have more than 1 value - you should iterate).

Categories : Javascript

Should js Cannot read property 'should' of null
That's a known problem with the should library: As it extends object, of course it only works when you have a concrete object. As null, by definition, means that you don't have an object, you can not call any methods on it or access any of its properties. Hence, should is not available in this case. Basically, you have two options of how to deal with this: You could exchange actual and expected. This way, as long as you do not expect null, you have an object in the beginning and hence can access its should property. But, this is not nice, as it changes semantics, and does not work in all cases. You could exchange the should library by another assertion library that does not have this problem. Personally, I'd go with option 2, and my highly subjective personal favorite for this is nod

Categories : Node Js

Read property bag from a sharepoint app
The recommended way to access things in SharePoint 2013 when making an app (and in many other situations) is through the client side object model (CSOM) API. You can use them through REST endpoints from any server or client side code. For example, you can access the properties of a web through the URL: http://<sitecollection>/<site>/_api/web/allProperties Check out this page for a bit more of an intro to using REST. http://msdn.microsoft.com/en-us/library/fp142385.aspx As Dragan pointed out, when coding in .NET technologies you can access the CSOM API through the Microsoft.SharePoint.Client assembly. For more information on that, see: http://msdn.microsoft.com/en-us/library/fp179912.aspx

Categories : Sharepoint

dynamically set an instance property / memoized attribute in python?
You can alter python classes after the fact: @property def c(self): if self._c is None: self._c = DO EXPENSIVE STUFF HERE return self._c Example.c = c Example._c = None Now you've added a property c to your class, as well as add a _c attribute. You may need to override any existing methods on the class that assume they can assign to self.c, of course. The process of dynamically adding or replacing attributes of objects is often referred to as Monkey Patching.

Categories : Python

Add validation rule to model property dynamically in asp.net mvc2
You could use IValidatableObject interface. When properly implemented, you can show property level and custom error messages. Here's the question for further reading

Categories : Asp Net Mvc

Replacing property dynamically based on environments in ANT scripts
You can use property ant task on your env.properties file. This allows to access key=value pair based on your need. You can redirect your environment specific properties to file you want or write to one specific file. <property file="${base.dir}/env.properties"/> <for list="dev,sit" param="value"> <sequential> <echo message="@{value}.AddNETWORK_USER=${@{value}.AddNETWORK_USER}" append="true" file="${base.dir}/@{value}Any-File.prop"/> <echo message="${line.separator}" append="true" file="${para.home}/@{value}Any-File.prop"/> <echo message="@{value}.ADDPASS=${@{value}.ADDPASS}" append="true" file="${para.home}/@{value}Any-File.prop"/> </sequential> </for>

Categories : Ant

Changing CSS property (left position) dynamically on setInterval
I believe you need to parse the current value as a number before subtracting: var currentLeft = parseInt(document.getElementById("maindiv").style.left, 10); document.getElementById("maindiv").style.left = (currentLeft - 100) + "px"; Also, I recommend you pass a function reference to setInterval instead of a string: closemaindiv = setInterval(collapser, 1000);

Categories : Javascript

How to dynamically change a button title (When a bool has a certain property)
One solution is to not @synthesize the userIsInTheMiddleOfEnteringANumber property, and write the code for it yourself. Add a private BOOL variable to your class, and write the userIsInTheMiddleOfEnteringANumber and setUserIsInTheMiddleOfEnteringANumber: methods. The getter should return the "backing" variable; the setter should check the old and the new value to see if the old value is NO and the new value is YES. When this is the case, the setter should change the title of the button as appropriate.

Categories : C++

Set bean's property from dynamically generated HTML list
I don't see anything here that isn't simple JS and Ajax, but there are no "beans" on the client side. You can fake it with DWR, which is JS and Ajax. Without DWR it's a matter of sending the selected value to the server, getting back either JSON to build the new options with, or HTML and injecting it directly into the DOM. (It's actually the same with DWR, but it's wrapped up in Java-looking JS.) Depending in your needs it might be a good idea to investigate frameworks that wrap up this process for you, although IMO is important to understand what's going on underneath. It's not twisted, it's simply not possible: JS=client, bean=server. If you want to update the client with server-side data without a page refresh, Ajax is the option (ignoring long connections etc).

Categories : Jquery

Dynamically assign the getter for a dependent property in MATLAB
Check if this is what you want. The problem is that the user will need to get the properties using (), which may be quite boring, but anyway, I think this way you can change the variables. You can't change them directly on the class, but you can change the objects property values on demand. It doesn't need to change the values on the constructor, you can do that using another function that will be inherited by the classes. klass1.m classdef(InferiorClasses = {?klass2}) klass < handle methods function self = klass selfMeta = metaclass(self); names = {selfMeta.PropertyList.Name}; for name = names switch name{1} case 'prop_child_1' self.(name{1}) = @newGetChild1PropFcn; case 'prop_child_2' self.(name{1}) = @newGetChild2

Categories : Matlab

Dynamically Read the Format of a String, Python
To get around the punctuation problem, you can use regular expressions. >>> import re >>> def tokenize(s): ... return re.split('[^A-Za-z]+', s) # Split by anything that isn't a letter ... >>> tokens = tokenize('Alliaria petiolata (M. Bieb.) Cavara & Grande') >>> tokens ['Alliaria', 'petiolata', 'M', 'Bieb', 'Cavara', 'Grande'] To get around the capitalization problem, you can use >>> tokens = [s.lower() for s in tokens] From there, you could rewrite the entry in a standardized format, such as >>> import string >>> ## I'm not sure exactly what format you're looking for >>> first, second, third = [string.capitalize(s) for s in tokens[:3]] >>> "%s %s (%s)" % (first, second, third) 'Alliaria Petiol

Categories : Python

How to read from file and dynamically allocate an array of int
Use a std::vector rather that a raw array. That way you can add to the vector as you read each item, rather than having to read the file once in order to work out how many items are in the file and then again to populate the array. int main() { std::vector<int> data; int tmp; ifstream fin("inputfile"); while(fin >> tmp) { data.push_back(tmp) } return 0; }

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.