dynamic

Log4J change File path dynamically

早过忘川 提交于 2020-01-10 08:57:08
问题 I want to change the path and file name of my log4j logfile dynamically. I have read a lot of pages and nearly every tell me that I should use system properties like here: how to change the log4j log file dynamically? So my log4j.properties file looks like this: log4j.logger.JDBC_LOGGER=INFO,jdbcTests log4j.additivity.JDBC_LOGGER = false log4j.appender.jdbcTests=org.apache.log4j.FileAppender log4j.appender.jdbcTests.File=${my.log} log4j.appender.jdbcTests.layout=org.apache.log4j.PatternLayout

System.Linq.Dynamic - Can I use IN clause in WHERE statement

情到浓时终转凉″ 提交于 2020-01-10 08:54:04
问题 I have dynamic linq WHERE statement: dataContext.Table.Where("id = 0 Or id = 1 Or id = 2 Or ..."); I want change to: dataContext.Table.Where("id IN (0, 1, 2, ...)"); But it doesn´t work. How can I do this for better performance? 回答1: From How to use “contains” or “like” in a dynamic linq query? //edit: this is probably broken, see below ids = new int[] {1,2,3,4}; dataContext.Table.Where("id.Contains(@0)", ids); Aside: It is good practice to use placeholders in dynamic linq expressions.

System.Linq.Dynamic - Can I use IN clause in WHERE statement

南楼画角 提交于 2020-01-10 08:53:07
问题 I have dynamic linq WHERE statement: dataContext.Table.Where("id = 0 Or id = 1 Or id = 2 Or ..."); I want change to: dataContext.Table.Where("id IN (0, 1, 2, ...)"); But it doesn´t work. How can I do this for better performance? 回答1: From How to use “contains” or “like” in a dynamic linq query? //edit: this is probably broken, see below ids = new int[] {1,2,3,4}; dataContext.Table.Where("id.Contains(@0)", ids); Aside: It is good practice to use placeholders in dynamic linq expressions.

Dynamic Object Intellisense

混江龙づ霸主 提交于 2020-01-10 05:49:28
问题 If dynamic resolves to object at compile time, and all .NET types extend object, why does dynamic not act like an object with regards to IntelliSense? Whenever I use dynamic I get a message saying "dynamic expression. this will be resolved at runtime". Surely it should also display object members? 回答1: Intellisense do not work in dynamic type. It is resolved at Runtime. Dynamic type work for static types as well as anonymous types. If intellisense would have worked, it would have defied the

When passing dynamic to method, the result is dynamic expression, even if it is not

爱⌒轻易说出口 提交于 2020-01-10 05:40:06
问题 In C# 5 when I tried to pass a dynamic as a method parameter the result for some reason became dynamic. class Program { static void Main(string[] args) { dynamic value = "John"; Find<int>(value).ToList(); } public static IEnumerable<T> Find<T>(object value) { //SOME LOGIC yield return default(T); //REAL RESULT } } Find<T>(value) has to return IEnumerable<T> . Why compiler thinks it is dynamic? I know that Find<int>(val as object).ToList(); solves this, but I want to understand WHY it happens.

How to preserve whitespace in dynamically added javascript DOM element without using CSS?

ぐ巨炮叔叔 提交于 2020-01-10 05:10:45
问题 When adding in text with small whitespace appended to it for alignment purposes the whitespace is trimmed off (the whitespace is added in c# so by the time it gets to front end Javascript it cannot be edited - it would be nice to just use some CSS to do this but it is not an option ). Here is what I tried so far: <div id="testDiv"></div> <script type="text/javascript"> var zlp = document.getElementById("testDiv"); zlp.innerHTML = "hello hello"; var zzz = document.createTextNode("hello hello")

Creating objects dynamically in loop

若如初见. 提交于 2020-01-10 02:47:07
问题 I have an array of strings that I am looping through. I would like to loop through the array and on each iteration, create a new object with a name that matches the string value. For example; string[] array = new string[] { "one", "two", "three" }; class myClass(){ public myClass(){ } } foreach (string name in array) { myClass *value of name here* = new myClass(); } Would result in three objects being instantiated, with the names "one", "two" and "three". Is this possible or is there are

how to define dynamic nested loop python function

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 02:43:08
问题 a = [1] b = [2,3] c = [4,5,6] d = [a,b,c] for x0 in d[0]: for x1 in d[1]: for x2 in d[2]: print(x0,x1,x2) Result: 1 2 4 1 2 5 1 2 6 1 3 4 1 3 5 1 3 6 Perfect, now my question is how to define this to function, considering ofcourse there could be more lists with values. The idea is to get function, which would dynamicaly produce same result. Is there a way to explain to python: "do 8 nested loops for example"? 回答1: You can use itertools to calculate the products for you and can use the *

Create an instance of a React class from a string

折月煮酒 提交于 2020-01-10 02:28:30
问题 I have a string which contains a name of the Class (this is coming from a json file). This string tells my Template Class which layout / template to use for the data (also in json). The issue is my layout is not displaying. Home.jsx: //a template or layout. var Home = React.createClass({ render () { return ( <div>Home layout</div> ) } }); Template.jsx: var Template = React.createClass({ render: function() { var Tag = this.props.template; //this is the name of the class eg. 'Home' return (

How to work with objects of unknown type returned from DataContext.ExecuteQuery

纵然是瞬间 提交于 2020-01-10 02:06:11
问题 So, with the advent of the dynamic keyword in C# 4.0 I am hoping I can find a better solution to the problem of dealing with types returned by DataContext.ExecuteQuery when arbitrary columns are selected. In the past I have either created a new type to hold the result of such a query or used the method described in this SO post. So, now that I am able to work on a new project running under .NET 4.0, I looked into using a dynamic type to accomplish the same thing in a less painful manner. So,