dynamic

Linq - Dynamic GroupBy with IEnumerable<T>

醉酒当歌 提交于 2019-12-22 08:41:44
问题 I have a collection that is IEnumerable<Transaction> . Transaction has several properties such as TransactionId (Int64), PaymentMethod(string) and TransactionDate(DateTime) I'd like to be able to accomplish this transactions.GroupBy(x => x.PaymentMethod) dynamically at run time based on whatever grouping field the user has decided to use. I found most of the answer I'm looking for in dtb's answer here Linq GroupBy - how to specify the grouping key at runtime? This works well: var arg =

C# WPF How to set Property setter method dynamically?

和自甴很熟 提交于 2019-12-22 06:59:13
问题 I've been searching around but I just can't seem to find what I'm looking for, so I'll give it a go here. Situation: I have the class MainWindow and MainWindowData. In MainWindowData are only public properties defined with the attribute UpdateGUI. public class UpdateGUI : Attribute { } public class MainWindowData { [UpdateGUI] public string TESTVAR { get; set; } } Now I want to add a method to each property's setter method in MainWindowData. More specific: void OnPropertyChanged(String

How to create dynamic external javascript files?

别等时光非礼了梦想. 提交于 2019-12-22 06:56:02
问题 I am thinking about how some online services create dynamic JavaScript files. These files have the .js extension, but their content is not static. I found a sample file here. It seems that this script is generated with a higher level programming language. I think it is done with PHP or something similar, but I am not sure, and I have not found any documentation about this topic. Is there any well known way to create these kind of dynamic JavaScript files? 回答1: Consider carefully whether

How can dynmically change a line of a JavaScript function?

♀尐吖头ヾ 提交于 2019-12-22 06:51:09
问题 Suppose I had the following function: function alertMesg() { alert("This ok function alerts message!"); } Now at run time I would like to change the alertMesg function to do something else. My thought was to do somehting like this. var temp = window.alertMesg.toString.replace("ok","great") temp = temp.replace('function alertMesg()',""); window.alertMesg = new Function(temp); Basically, the problem is I have no control over the source in the alertMesg function. I would like to change the

DynamicObject implicit casting

僤鯓⒐⒋嵵緔 提交于 2019-12-22 06:39:50
问题 I have a subclass of DynamicObject and I would like to implement implicit casting for primitive types similarly as DO's explicit casting method TryConvert; that is, without writing multiple implicit operator [type] functions. Usage: dynamic myDynamicObject = new MyDynamicObject("1"); int sum = 1 + myDynamicObject; // instead of int i = 1 + (int)myDynamicObject; Is that possible and if so, how? 回答1: There are several things going on here. First, you are performing a binary operation. So, you

Change order of for loops?

老子叫甜甜 提交于 2019-12-22 06:36:40
问题 I have a situation where i need to loop though xyz coordinates in different orders depending on a users input. So i an area in 3D space then a set of for loops like so. for(int x = 0; x < build.getWidth(); x++){ for(int y = 0; y < build.getHeight(); y++){ for(int z = 0; z < build.getLength(); z++){ //do stuff } } } but depending on the users input, the order may be like this. for(int z = 0; z < build.getLenght(); z++){ for(int y = 0; y < build.getHeight(); y++){ for(int x = 0; x < build

Can't Reference Dynamic Objects in Embedded ASPX code

喜你入骨 提交于 2019-12-22 05:33:33
问题 I'm creating a List member variable during my Page_Init event. I'm having a problem referencing the objects in the list from my embedded C# code in the *.aspx page. The error is a Runtime Binder Exception that says "'object' does not contain a definition for 'JobID'". When the debugger is invoked, I can see that the foreach loop's variable j does indeed have a dynamic property named JobID and it's filled with an int value. So, my question is why my embedded C# code can't work with the dynamic

Scala - Dynamic class loading - class A can not be cast to class A

强颜欢笑 提交于 2019-12-22 05:27:58
问题 I have a simple jar file containing class A : public class A {} Then I load it in runtime: var classLoader = new URLClassLoader(Array(my_jar_file.toURI.toURL)) var clazz = classLoader.loadClass("A") It is ok, it can load the class A . This command is also ok: clazz.newInstance But when I cast it to A : clazz.newInstance.asInstanceOf[A] I got this error: java.lang.ClassCastException: A cannot be cast to A Could you please help me? 回答1: Your code implies that you have "A" available in one

How to dynamically set a property of a class without using reflection (with dynamic) in C# 4 when property name is coming from another source

笑着哭i 提交于 2019-12-22 05:13:08
问题 I'm building/updating an EntityFramework EntityObject on runtime. I want to set the properties of the entity class, property names and values are coming from another source. So I'm doing this; public static EntityCollection<T> UpdateLocaleEntity<T>(EntityCollection<T> entityCollectionToUpdate, params ILocaleControl[] values) where T : EntityObject { foreach (var x in entityCollectionToUpdate) { Type t = typeof(T); dynamic localeEntity = x; string cultureCode = localeEntity.CultureCode; for

Form not submitting dynamically generated inputs (jQuery)

99封情书 提交于 2019-12-22 05:07:18
问题 Hello I'm trying to dynamically generate some inputs for my form, but it's not posting the new inputs generated, so far I've been searching around and the only thing I was able to find is to make the form a direct children of the body tag, and as in the design of my app thats not possible, so somebody might know what happens and how to solve it? And no, it doesn't work with .live() . HTML <form name="order" id="newOrder" action="../core/query.php" method="post"> <input type="text" value=