Hello.
I was creating a Func as parameter input to another method, but how do I invoke that?
The following code describes my work:
I call Foo with:
Foo(x => x.SlidingExpiration(TimeSpan.FromSeconds(50)));
My method Foo:
public void Foo(Func<CacheExpiration, TimeSpan> cacheExpiration)
{
....
inside here I want to call RefreshCache,...
I'm curious how to check if given type is closed version of open type. For instance
public bool IsGenericList(Type source)
{
return (source.IsGenericType &&
/*here goes the manipulation on source type*/ == typeof(List<>));
}
...
I've got a Validator class which creates an instance of a Validations class, which contains all the validation methods. When a validation is performed, __call in Validator is used to dispatch a call Validator->validate_method to Validations->method.
So for instance, there is a method in Validations called length_of. When the following c...
Is there anyway I can convert a Map to a POJO that I can then use in JSP EL? Maybe with reflection or something? I don't want to have to manually create a new class for every new collection of properties.
...
Hi. I have a class that has many settable/gettable attributes. I'd like to use reflection to set these attributes, but I have 2 questions about my implementation
Here is some stripped down code from my class
class Q {
public String question_1;
public String question_2;
public String question_3;
public String answer_1;
publi...
Hey,
First of all this is not some normal action I would want to do, however this fringe case involving alot of legacy code I cannot touch, and unit tests that need to be written for newer stuff.
Anyway I have a class and I can get access to all fields and methods through reflection, except private/protected static ones. So is there an...
the code is
Field field = st.class.getField("g_"+selectedGroup);
st is my class, and g_+"selectedgroup" is in the st class as String array
how to get that string array?
I need something: String sa[]= field.getStringArray[]; but only getInt, getBoolean there is :(
how to?
...
This is my code:
The ExecutorImp extends AbstractExecutor which extract the same execute logics of its implementers(ExecutorImp is one case),when calling the execute() method of ExecutorImp, it will call the method in its supertype,but the supertype (the AbstractExcutor) should know another class binding to the implementer(in the example...
I'm trying to design a solution in MVC in which a string representation of a class is passed to the controller which should then build a grid with all the data belonging to that class in the DB. (I'm using an ORM to map classes to tables).
//A method in the Model that populates the Item Property
foreach (MethodInfo method in...
I have a VS Add-In that's using a BinaryFormatter to deserialize an object. To resolve the type of this object, it's calling Assembly.Load(objectTypeFullName) but it's triggering an exception because Assembly.Load cannot find the assembly in any of the places it's searching on. The given assembly is sibling to the add-in assembly, but it...
I have a DataTemplate that needs to set the IsSelected property on an ItemsControl's container (such as TreeViewItem, ListViewItem or ComboBoxItem). However, it doesn't know the type of the container until it's passed in to it. Since IsSelected isn't part of a common base class or interface, nor is it a common dependency property regis...
Here is the code I'm calling
PropertyInfo targetColumn;
targetColumn = targetType.GetProperty("CtrId");
Here is the Class
using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;
namespace JCDCHelper.CV
{
[DataContract, Serializable]
public class CenterAllActiveCV
{
[DataM...
I have a list of objects and I want to sort by passing object's field name and order(ascending or descending). For example: my object is,
class Person{
private String name;
private String age;
//getters and setters
..........
}
I will pass (List personList , String "name" and boolean isAscending) to...
I want to invoke all registered methods of a RoutedEvent of a FrameworkElement (e.g. a MouseLeftButtonUp or a MouseMove of a ContentControl/Canvas/...). In my case, i got a reference to that object and I know which Event should be invoked. But after trying several hours with reflection I am asking myself if this is even possible???
I th...
I want to create a class dynamically at run time by reading field names and its types from an xml file.For example my xml file looks like this:
<person>
<name type="String">abc</name>
<age type="Integer">30</age>
</person>
I also want to have getter and setters methods for each field.
Any examples or best approaches available f...
var mystring = "MyCompany.MyType.Localization.Strings.MyString"
In C#, is there a way I could fill it up such that
var abc = GetReflectedValue(mystring);
Is reflection the only way? (how?) Or any more efficient ways?
...
I have some code that binds an enumeration to a dropdown list, however, I'd like build the dropdown to take the integer value from the enum for the value and the description attribute for the text.
I tried defining the kvPairList as a int/string and casting enumValue and an (int)
I also tried converting.toInt32
Ideas?
<select name=...
I am trying to write generic code for detaching a linq class. What I have currently is:
public void Detach()
{
this.PropertyChanged = null;
this.PropertyChanging = null;
this.Categories = default(EntitySet<Categories>);
this.Jobs = default(EntitySet<Jobs>);
this.Tasks= default(EntitySet<Tasks>);
}
This is all fine...
I have a type SearchBag that holds a bunch of strings and nullable integers to use for passing on search values. I need a way to check if the search bag contains any values.
I'm currently trying to do it like this:
public bool HasValues()
{
return GetType().GetProperties().Any(p => p.GetValue(this, null) != null);
...
I'm looking for functionality in Java similar to the .NET Managed Extensibility Framework (http://mef.codeplex.com/). For those who don't know MEF, I want something like this:
Given an interface
public interface IFoo {
...
}
Dynamically load an implementation of an interface by looking in loaded jars.
IFoo foo = loadClassThatI...