Skip to content

Instantly share code, notes, and snippets.

@jcansdale
Created July 22, 2016 11:07
Show Gist options
  • Save jcansdale/7fa50ede36d712b54b77c746e3f54bdf to your computer and use it in GitHub Desktop.
Save jcansdale/7fa50ede36d712b54b77c746e3f54bdf to your computer and use it in GitHub Desktop.
Some utility methods for poking around .NET Core.
namespace Utilities
{
using System;
using System.Collections;
using System.Collections.Generic;
public static class NetCoreUtilities
{
public static string[] GetTrustedPlatformAssemblies()
{
var paths = (string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES");
return paths.Split(';');
}
public static Dictionary<string, string> GetDataDictionary()
{
Dictionary<string, string> stringStore = new Dictionary<string, string>();
var localStore = (ICollection)CurrentDomain.get("LocalStore");
foreach (KeyValuePair<string, object[]> kv in localStore)
{
var str = (string)kv.Value[0];
stringStore[kv.Key] = str;
}
return stringStore;
}
public static object SetupInformation
{
get
{
return CurrentDomain.get("SetupInformation");
}
}
public static object CurrentDomain
{
get
{
return Type.GetType("System.AppDomain").get("CurrentDomain");
}
}
}
}
namespace Utilities
{
using System;
using System.Reflection;
static class GetValueUtilities
{
public static object get(this object ob, string name)
{
var typeInfo = ob.GetType().GetTypeInfo();
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var prop = typeInfo.GetProperty(name, flags);
if (prop != null)
{
return prop.GetValue(ob);
}
var field = typeInfo.GetField(name, flags);
if (field != null)
{
return field.GetValue(ob);
}
return null;
}
public static object get(this Type type, string name)
{
var typeInfo = type.GetTypeInfo();
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
var prop = typeInfo.GetProperty(name, flags);
if (prop != null)
{
return prop.GetValue(null);
}
var field = typeInfo.GetField(name, flags);
if (field != null)
{
return field.GetValue(null);
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment