lundi 22 juin 2015

list files compiled with the Page Build action

I'm trying to create a method of changing themes in my program using WPF. I have that part working, so the next step is to try to automate as much as I can. Currently, I have the following in my project. Each file contains a ResourceDictionary that I'm using to set the theme for my WPF application.

enter image description here

When the program is running, I'm making a menu that will contain the theme's as a set of menu items. Currently I'm using the following code to populate that list.

private void LoadSkinsList()
{
    List<string> assembies = new List<string>();
    assembies.Add(@"Skins/Default/Resources.xaml");
    assembies.Add(@"Skins/Black/Resources.xaml");
    assembies.Add(@"Skins/Green/Resources.xaml");

    foreach (string name in assembies)
    {
        MenuItem menuItem = new MenuItem();
        menuItem.Header = name;
        menuItem.Command = SelectTheme;
        menuItem.CommandParameter = menuItem;

        ThemeMenuItems.Add(menuItem);
    }
}

What I would like to do is find the Folders Black,Default and Green via using code, I'm happy to find the paths to all the files in the the folders, then shred the info.

I'm not just not sure how to find the folders or files in the first place.

The Resources.xaml files are all compiled into the project using the Build Action Page.

Any ideas how I can replace the block of code.

assembies.Add(@"Skins/Default/Resources.xaml");
assembies.Add(@"Skins/Black/Resources.xaml");
assembies.Add(@"Skins/Green/Resources.xaml");

with something that will find the resources via code?





C# - Get all types that been used in class A

how can I get all the types that been used in specific type?

Example for class "MyClass":

[MyAttribute(new OtherType(TestEnum.EnumValue1))]
public class MyClass:MyOtherClass
{
    public Type MyType { get; set; }
    public string MyString { get; set; }

    private DateTime MyDateTime;
    [OtherAttribute()]
    public int MyMethod(double doubleNumber, float floatNumber)
    {
        justMyClass myClass = new justMyClass();
        return (int)doubleNumber / (int)floatNumber;
    }
}

I want to get the types: MyAttribute, OtherType, TestEnum, MyClass, MyOtherClass, Type, string, DateTime, OtherAttribute, int, double, float and justMyClass.

Is there any way to do it?





How can I recursively return the reflected names of a property and all its parents

So I have the following helper method that is returning the name of a property given an expression. Its being used in an MVC application to set the ID of a hidden field in a view based on the property it needs to bind to .

public static string GetIDFromPropertyName<T>(Expression<Func<T>> exp)
{
   return (((MemberExpression)(exp.Body)).Member).Name;
}

However what I want is to be able to pass in an expression such as:

GetIDFromPropertyName(() => model.AComplexProperty.AnotherComplexProperty.ASimpleProperty)

And have returned back to me:

AComplexProperty_AnotherComplexProperty_ASimpleProperty

How can I do this?





Separate project by dependency of another project

I have project A and project B. Project A been use project B dll.

I want to get all the dependencies of project A out from project B and separate them into 2 different projects, project C and project D.

I want project A to use only project D.

The dependency been declared by class's(in properties, interfaces, methods body and interface, interfaces, methods parameters, base class, attribute etc.).

Is there some way or tool to do it?





Android - multiple Gson libs in different SDKs

We are using couple of SDKs with our app and some of them have Google Gson library but in different package e.g. thirdpartylib.gson.Gson, thirdpartylibsecond.gson.Gson, .... We use com.google.gson.* package as well but the thing is: Is there any way how to use one of the Gson from other SDKs instead of ours? The main reason is to reduce number of method IDs.

We are thinking about using reflection something like:

1) Create our stub class for Gson and use it everywhere in our app -> GsonStub.

2) Check if any other Gson is available: Class cl = Class.forName('<specific-gson>')

3) and then use method delegation in our GsonStub: cl.getDeclaredMethod()

But problem is that another our 3rd party library takes com.google.gson.Gson as parameter. Moreover, each call of Gson method in this implementation could cost us extra resources because of reflection.

Has anyone got experience with this 'issue'? It seems ineffective to have linked number of same Gson libs each with around 900 method IDs.





Get all types that been use in specific assembly by reflection

I need to get all the types that a specific assembly depend on.

For example if I have project A that have reference to project B. I want to get all the class's that been used in A and define in A or B including enums, interfaces, attributes, base class of a class, entities type that been use inside of methods at project A etc.

Is there some way to get all entities type?





Enable or Disable Mobile Data in Lollipop

      try {
             ConnectivityManager connectivityManager = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
               Method iMthd = ConnectivityManager.class.getDeclaredMethod(
                        "setMobileDataEnabled", boolean.class);
                if (iMthd != null) {
                    iMthd.setAccessible(false);
                    iMthd.invoke(connectivityManager, enable);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

Upto kitkat above mechanism is working properly but in lollipop it is not worked out is there any other way to achieve this.