mercredi 1 avril 2015

Get registered directives and their DDOs

Knowing the name of the directive I was able to get its DDO with something like this



$injector.get('ngModelDirectiveProvider').$get()


However, it seems that Angular doesn't expose the list of its directives in any way. I'm particularly aimed at built-in Angular directives, this substantially limits the ways Angular's providers could be monkey-patched.


I'm looking for the option to get all registered directives without modifying or parsing Angular source code, if there is any.






Any API for TSYS(TOTAL SYSTEM SERVICES)

It's a credit card company and is using a system called "Tsys" from "TOTAL SYSTEM SERVICES, INC". In order to get the information from the "Tsys", it's using Reflecltion for IBM 9 to connect to the "Tsys" server to get information. And for the sake of efficientcy, it's using VBA macro to simulate user's input in reflection to get information. However it's still very slow and easy to be interrupted by other application. For any people who is familiar with "tsys", is there any API(Java or C#) that allow people to communicate with the Tsys server directly without using third party software like reflection for IBM?






GetIndexParameters() empty on Dictionary property

I'm using reflection to get some info about a class I'm exporting to excel. It loops through the properties to get their values.


I want it to also be able to handle indexed types like Lists and Dictionarys. However, the GetIndexParameters() method on the property is returning none. Am I using this wrong?


Here you can see that prop.Property (which is a PropertyInfo) is showing the value as a Dictionary<int, decimal>, but the indexParams has 0 length.


Loop logic (slightly modified for SO, partially pseudocode)



foreach (var prop in ExportingPropertiesInOrder)
{
//detect if it needs to have indexing applied.
var indexParams = prop.Property.GetIndexParameters();
var isIndexed = indexParams.Any();
if (!isIndexed)
{
//get value for property for export
}else{
//loop through indeces, get each value
}





Can Java Reflection be used to print class contents? [duplicate]


I am looking to find a solution which will allow me to import a package into an existing Java Workspace and print out the contents of each class in that workspace into a .txt file. I will then use a BufferedReader to read the contents of the .txt file into another program.


In trying to find a solution for this problem I have came across the technique of Java Reflection and wondering if it is possible to solve my problem using this technique? Please advise!






Get OrderBy method using reflection

I want to implement generic pager and filter View Model for my project and I'm stuck on getting OrderBy method using reflection. Here is what I've tried, but keep getting null for methodInfo. It seems I'm passing the wrong Type[] arguments to the GetMethod() Method, but I can't get it right.



protected virtual Expression<Func<T, IComparable>> GetOrderByExpression()
{
var type = typeof(T);
var property = type.GetProperty("DataSetName");
var parameter = Expression.Parameter(type, "x");
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = Expression.Lambda(propertyAccess, parameter);
var methodInfo = typeof(Enumerable).GetMethod("OrderBy", new Type[] { orderByExp.Body.Type });
var predicateBody = Expression.Call(propertyAccess, methodInfo, orderByExp);
var expression = Expression.Lambda<Func<T, IComparable>>(predicateBody, parameter);

return expression;
}





PHP: reflexion, "non well formed numeric value encountered" setting array index

I haven't been able to find anything specific to this issue. In my class I need to take an associative array and put it's values in class variables. Any sub-arrays need to be converted to objects. The conversion to objects is happening in the following code:



foreach ($value as $key2 => $value2) {
$object = new $object_str($value2);
$this->$key[$object->getId()] = $object;
}


$value comes from an outer foreach loop.

$object_str contains the name of the object that has to be created,

like this: MartKuper\OnePageCRM\Contacts\ContactsUrl


The input array could look like this:



[
'url' => [
'type' => 'website',
'value' => 'google.com'
]
]


It should create a ContactsUrl object and add it to the $url class variable (which also is an array) based on the class' internal random id (uniqid()). Because I don't know how many 'url' entries the input array will have, this all needs to happen dynamically. Hence the



$this->$key[$object->getId()]


The error occurs on the index of the $key (url) array. It seems that it doesn't like to take a string as an index. I've tried putting hardcoded strings in



$this->$key['test]


that doesn't work either. When I put an integer in



$this->$key[1]


it does work. Converting the string to an integer is not an option. It will break a parser class that is used by many other classes.






Unit testing in C# of private-static method accepting other private-static method as a delegate parameter

What I have: I have a non-static class containing, among others, two private-static methods: one of them can be passed to another one as a delegate parameter:



public class MyClass
{
...

private static string MyMethodToTest(int a, int b, Func<int, int, int> myDelegate)
{
return "result is " + (myDelegate(a, b));
}

private static int MyDelegateMethod(int a, int b)
{
return (a + b);
}
}


What I have to do: I have to test (with unit testing) the private-static method MyMethodToTest with passing to it as the delegate parameter the private-static method MyDelegateMethod.


What I can do: I know how to test a private-static method, but I do not know how to pass to this method another private-static method of the same class as a delegate parameter.


So, if we assume that the MyMethodToTest method has no the third parameter at all, the test method will look like:



using System;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;


...



[TestMethod]
public void MyTest()
{
PrivateType privateType = new PrivateType(typeof(MyClass));

Type[] parameterTypes =
{
typeof(int),
typeof(int)
};

object[] parameterValues =
{
33,
22
};

string result = (string)privateType.InvokeStatic("MyMethodToTest", parameterTypes, parameterValues);

Assert.IsTrue(result == "result is 55");
}


My question: How to test a private-static method passing to it as a delegate parameter another private-static method of the same class?