dynamic

Dynamic Column Name in LinQ

蹲街弑〆低调 提交于 2019-12-19 03:06:24
问题 I am having a class Item. class Item{ public int Id { get; set; } public DateTime CreatedDate { get; set; } public string Name { get; set; } public string Description { get; set;} } I want to filter list of items based on dynamic column name. Suppose I want list of Names then Column Name is "Name" and result will be list of names If column name is Description, I need list of descriptions. How to do this with LinQ? 回答1: Easy, just select the property you need from the list: var items = new

How do I dynamically create functions that are accessible in a parent scope?

怎甘沉沦 提交于 2019-12-19 02:27:20
问题 Here is an example: function ChildF() { #Creating new function dynamically $DynFEx = @" function DynF() { "Hello DynF" } "@ Invoke-Expression $DynFEx #Calling in ChildF scope Works DynF } ChildF #Calling in parent scope doesn't. It doesn't exist here DynF I was wondering whether you could define DynF in such a way that it is "visible" outside of ChildF. 回答1: The other solutions are better answers to the specific question. That said, it's good to learn the most general way to create global

AngularJS dynamic ng-option to link two drop downs

岁酱吖の 提交于 2019-12-18 18:21:38
问题 Can anyone help me with a ng-option issue, I am trying to have ng-option created dynamically. What I am doing is pretty complex but I tried to explain it in following link I have two drop downs the first one has values like county, municipality and district based on whats selected in first drop down box the second drop down box will have either county or municipality or districts populated. but the trick is that the json for county or district or municipality have different structure so the

ExpandoObject, anonymous types and Razor

两盒软妹~` 提交于 2019-12-18 17:35:33
问题 I want to use an ExpandoObject as the viewmodel for a Razor view of type ViewPage<dynamic> . I get an error when I do this ExpandoObject o = new ExpandoObject(); o.stuff = new { Foo = "bar" }; return View(o); what can I do to make this work? 回答1: You can do it with the extension method mentioned in this question: Dynamic Anonymous type in Razor causes RuntimeBinderException So your controller code would look like: dynamic o = new ExpandoObject(); o.Stuff = new { Foo = "Bar" }.ToExpando();

Static vs. Dynamic Library Performance

本秂侑毒 提交于 2019-12-18 16:34:18
问题 It's a general notion that performance of static libraries is greater than that of dynamic. My question is: does it also depend on once the dll is already loaded in memory? I mean, once the initialization and all has happened, does the function calling and execution take longer in case of dynamic libraries than static libraries? 回答1: Disclaimer : I am a Linux-fu grasshopper, so there might be some inaccuracies here and there (or just everywhere). But the general idea should be relatively

Does the C# 4.0 “dynamic” keyword make Generics redundant?

我们两清 提交于 2019-12-18 15:46:17
问题 I'm very excited about the dynamic features in C# (C#4 dynamic keyword - why not?), especially because in certain Library parts of my code I use a lot of reflection. My question is twofold: 1. does "dynamic" replace Generics, as in the case below? Generics method: public static void Do_Something_If_Object_Not_Null<SomeType>(SomeType ObjToTest) { //test object is not null, regardless of its Type if (!EqualityComparer<SomeType>.Default.Equals(ObjToTest, default(SomeType))) { //do something } }

Dynamic JPA 2.0 query using Criteria API

依然范特西╮ 提交于 2019-12-18 15:34:19
问题 I am a bit stucked constructing a dynamic query using the CriteriaBuilder of JPA 2.0. I have quite a common use case I guess: User supplies a arbitrary amount of search parameters X to be and / or concatenated: like : select e from Foo where (name = X1 or name = X2 .. or name = Xn ) The Method or of CriteriaBuilder is not dynamic: Predicate or(Predicate... restrictions) Ideas? Samples? 回答1: In your case, I would rather use Expression#in(Collection) to avoid having to loop and to build a

Difference between dynamic and System.Object

六月ゝ 毕业季﹏ 提交于 2019-12-18 14:48:30
问题 What is the difference between a variable declared as dynamic and a variable declared as System.Object? Running the following function would seem to indicate that both variables get cast to the correct type dynamically: void ObjectTest() { System.Object MyTestVar = "test"; dynamic MyTestVar2 = "Testing 123"; Console.WriteLine("{0}", MyTestVar.GetType()); Console.WriteLine("{0}", MyTestVar2.GetType()); MyTestVar = 123; MyTestVar2 = 321; Console.WriteLine("{0}", MyTestVar.GetType()); Console

C# accessing property values dynamically by property name

帅比萌擦擦* 提交于 2019-12-18 14:45:16
问题 The problem I am trying to solve is how to write a method which takes in a property name as a string, and returns the value assigned to said property. My model class is declared similar to: public class Foo { public int FooId public int param1 public double param2 } and from within my method I wish to do something similar to this var property = GetProperty("param1) var property2 = GetProperty("param2") I am currently trying to do this by using Expressions such as public dynamic GetProperty

How to catch exception thrown from library in GCC C++?

北战南征 提交于 2019-12-18 13:37:59
问题 When i use dlopen to dynamically load a library it seems i can not catch exceptions thrown by that library. As i understand it it's because dlopen is a C function. Is there another way to dynamically load a library that makes it possible to catch exceptions thrown by the lib in GCC? In Windows you can use LoadLibrary but for Linux i have only found dlopen but when using dlopen i can not catch exceptions. Edit : I have tried void* handle = dlopen("myLib.so", RTLD_NOW | RTLD_GLOBAL); and I