Advertisement
Advertisement
| 10.16.2008 at 11:48PM PDT, ID: 23823075 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: |
//Main program - loads in *.dll files.
using System;
using System.Reflection;
using Base;
namespace PluginDll
{
public class LoadMovingObjects : IBaseMod
{
//do stuff
public bool InterfaceFilter(Type typeObj, Object criteriaObj)
{
if (typeObj.ToString() == criteriaObj.ToString())
return true;
else
return false;
}
public void LoadDLLs(string directory, string chkInterface)
{
TypeFilter myFilter = new TypeFilter(InterfaceFilter);
List<IBaseMod> modules = new List<IBaseMod>();
foreach (string file in Directory.GetFiles(directory, "*.dll"))
{
Assembly componentAssembly = Assembly.LoadFrom(file);
if (componentAssembly != null)
{
try
{
foreach (Type componentType in componentAssembly.GetTypes())
{
Type[] InterfaceList = componentType.FindInterfaces(myFilter, chkInterface);
{
if (InterfaceList.Length > 0)
{
Console.WriteLine("\n{0} implements the interface {1}.", componentType.Name, chkInterface);
foreach (KeyValuePair<int, string> kvp in objDict)
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
if (kvp.Value == componentType.Name)
{
int i = kvp.Key;
Console.WriteLine("Found match: object {0} with class {1} ", objArray[i, 0], componentType.Name);
//The following are the commands I have tried.
//Object tempObj = Activator.CreateInstance(componentType); //object is created.
//IBaseMod movingObj = (IBaseMod)tempObj; //however, receive "Unable to cast object message" here
//Exception: Unable to cast object of type 'PluginDll.MovingObect1' to type 'Base.IBaseMod'.
//These commands result in the same exception message:
//Type PluginType = componentAssembly.GetType(componentAssembly.GetName().Name + "." + componentType.Name, true, true);
//IBaseMod movingObj = (IBaseMod)Activator.CreateInstance(PluginType);
//Object tempObj = componentAssembly.CreateInstance("PluginDll.MovingObect1"); //object is created
//IBaseMod movingObj = (IBaseMod)tempObj; //however, receive "Unable to cast object message" here
//These are the only commands that will successfully create the instance and type cast the instance.
//As you can see, I have to type in the actual name.
//PluginDll.MovingObect1 tempObj = new PluginDll.MovingObect1();
//Base.IBaseMod movingObj = (Base.IBaseMod)tempObj;
//MovingObect1 tempObj = new MovingObect1();
//BaseMod movingObj = (IBaseMod)tempObj;
--------------------------------
//The Interface class
using System;
namespace Base
{
public interface IBaseMod
{
Vector3 PositionFromDate(DateTime date);
Vector3 PositionDelta(double timeDelta);
}
}
---------------------------------
//The dll file that needs to be loaded
using System;
using Base;
namespace PluginDll
{
public class MovingObect1 : IBaseMod
{
public MovingObect1()
{
Console.WriteLine("In MovingObect1 constructor");
}
Vector3 IBaseMod.PositionFromDate(DateTime date)
{
//Do stuff
return positionVector;
}
Vector3 IBaseMod.PositionDelta(double timeDelta)
{
//Do stuff
return positionVector;
}
}
public class MovingObect2 : IBaseMod
{
public MovingObect2()
{
Console.WriteLine("In MovingObect2 constructor");
}
Vector3 IBaseMod.PositionFromDate(DateTime date)
{
//Do stuff
return positionVector;
}
Vector3 IBaseMod.UpdatePosition(double timeDelta)
{
//Do stuff
return positionVector;
}
}
|
| Answered By: | weleda |
| Expert Since: | 10/07/2008 |
| Accepted Solutions: | 1 |