Merging changes
This commit is contained in:
1 parent
c4216d2272
commit
797816be7e
437 files changed
+54228
-28
No files matched your search
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
//using BCG.Utilities.BlueConfiguration;
|
||||
using BCG.Utilities;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
public class CorePrimtiveManager
|
||||
{
|
||||
private IDictionary myTypeLookupTable = new Hashtable ();
|
||||
private static CorePrimtiveManager mySelf;
|
||||
private ArrayList myAssemblyNames = new ArrayList ();
|
||||
|
||||
private CorePrimtiveManager()
|
||||
{
|
||||
myLoadAllTypes ();
|
||||
}
|
||||
|
||||
private void myLoadAllTypes ()
|
||||
{
|
||||
//we only load one type here
|
||||
loadAssembly ("X:\\bcg\\blue2\\Debug\\CppToCSharpDataStreamBridge.dll");
|
||||
}
|
||||
|
||||
private static Assembly myAssemblyResolver(object sender, ResolveEventArgs args)
|
||||
{
|
||||
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
if (args.Name.Equals(a.FullName))
|
||||
return a;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads all the types associated with the assembly
|
||||
/// </summary>
|
||||
/// <param name="assemblyName"></param>
|
||||
public void loadAssembly (string assemblyName)
|
||||
{
|
||||
if (myAssemblyNames.Contains (assemblyName))
|
||||
return;
|
||||
myAssemblyNames.Add (assemblyName);
|
||||
Assembly loadedAssembly = GetType ().Assembly.FullName.Equals (assemblyName) ?
|
||||
GetType ().Assembly :
|
||||
Assembly.LoadFrom (assemblyName);
|
||||
|
||||
foreach (Type type in loadedAssembly.GetTypes())
|
||||
if (!type.IsInterface
|
||||
&& !type.IsAbstract
|
||||
&& type.IsPublic)
|
||||
{
|
||||
bool isVisible = true;
|
||||
string userRep = type.Name;
|
||||
|
||||
if (isVisible)
|
||||
{
|
||||
// BlueEventLog.logAssert(myTypeLookupTable [userRep] == null);
|
||||
myTypeLookupTable[userRep] = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static CorePrimtiveManager instance
|
||||
{
|
||||
get {return mySelf = mySelf == null ? new CorePrimtiveManager () : mySelf;}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Type name corresponding to the primitive name
|
||||
/// </summary>
|
||||
/// <param name="friendlyName"></param>
|
||||
/// <returns></returns>
|
||||
public string find (string friendlyName)
|
||||
{
|
||||
if (myTypeLookupTable[friendlyName] == null)
|
||||
throw new ApplicationException (friendlyName + " is not the friendly name of any of the loaded types");
|
||||
return (myTypeLookupTable[friendlyName] as Type).Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs and returns an object of type corresponding to the friendly name
|
||||
/// </summary>
|
||||
/// <param name="friendlyName">friendly primitive name </param>
|
||||
/// <param name="args">args can be null or an empty ICollection if the paramterless constructor
|
||||
/// is the desired one</param>
|
||||
/// <returns></returns>
|
||||
public Object build (string friendlyName, ICollection args)
|
||||
{
|
||||
object[] constructorArgs = null;
|
||||
if (args != null && args.Count > 0)
|
||||
{
|
||||
constructorArgs = new object [args.Count];
|
||||
args.CopyTo (constructorArgs, 0);
|
||||
}
|
||||
if (myTypeLookupTable[friendlyName] == null)
|
||||
throw new ApplicationException (friendlyName + " is not the friendly name of any of the loaded types");
|
||||
return
|
||||
constructorArgs == null ?
|
||||
Activator.CreateInstance (myTypeLookupTable[friendlyName] as Type):
|
||||
Activator.CreateInstance (myTypeLookupTable[friendlyName] as Type, constructorArgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of all the primitives
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string[] getPrimitiveNames ()
|
||||
{
|
||||
string[] retVal = new string [myTypeLookupTable.Count];
|
||||
myTypeLookupTable.Keys.CopyTo (retVal, 0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the types of all the streams
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Type[] getStreamTypes ()
|
||||
{
|
||||
Type[] retVal = new Type [myTypeLookupTable.Count];
|
||||
myTypeLookupTable.Values.CopyTo (retVal, 0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public ICollection getConstructorSigns (string primitiveName)
|
||||
{
|
||||
ArrayList retVal = new ArrayList ();
|
||||
// BlueEventLog.logAssert (myTypeLookupTable[primitiveName] != null);
|
||||
Type t = myTypeLookupTable[primitiveName] as Type;
|
||||
foreach (ConstructorInfo ci in t.GetConstructors())
|
||||
{
|
||||
string sign = "";
|
||||
sign = t.Name + " (";
|
||||
foreach (ParameterInfo pi in ci.GetParameters ())
|
||||
sign += pi.ParameterType.Name +
|
||||
" " +
|
||||
pi.Name + ", ";
|
||||
sign = sign.Length == (t.Name + " (").Length ? sign + ")": sign.Remove (sign.Length - 2, 2) + ")";
|
||||
retVal.Add (sign);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public string getAssemblyName (string primitiveName)
|
||||
{
|
||||
// BlueEventLog.logAssert (myTypeLookupTable[primitiveName] != null);
|
||||
return (myTypeLookupTable[primitiveName] as Type).Assembly.GetName().Name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user