Carl,
The intern method actually wraps the object in another object (a
DotNetObject), and that outer object is what is used by the scripting
engine in an object type it understands (a dotNetObject). This is for
a C++ application with a typeless scripting language, we are adding
..net access to the scripting language. So the user can call inspection
functions on the dotNetObject, and via reflection we expose the
methods/properties/events/etc of the wrapped .net object.
We already have the concept of interfaces in the scripting language,
where you can get interfaces that are exposed by our app's objects and
operate on those interfaces. I'm trying to extend that concept to the
..net exposure. I'm thinking that I'll need to tweak the DotNetObject
so that I optionally specify the Type to expose it as, rather than
just take the Type from the object. So then we would have:
myString = dotNetObject "System.String" "AAA"
showMethods myString -- shows all methods of String
newString = myString.Copy()
iclonable = getInterface myString "IClonable"
showMethods iclonable -- shows just that methods of IClonable
interface
clonedString = iclonable.Clone()
Our current "interfaces" are actually objects, which colors my
thinking here.
Larry
Larry said:
Is there a C++ method comparable to the vb.net TryCast function? I
had hopes for Convert::ChangeType, but that didn't work.
dynamic_cast is identical to the VB TryCast function - they both compile to
the same IL.
For a scripting engine, the user is specifying to retrieve an
interface on an object by name. Code is roughly:
array<Type^> ^l_pInterfaces = l_pType->GetInterfaces();
for(int m=0; m < l_pInterfaces->Length; m++)
{
Type^ l_pInterface = l_pInterfaces[m];
System::String ^ l_pInterfaceName = l_pInterface->Name;
if (l_pPropString->Equals(l_pInterfaceName)
break;
l_pInterface = nullptr;
}
if (l_pInterface)
return intern(Convert::ChangeType(l_pObject,l_pInterface));
What exactly are you trying to return here? How do you plan to return an
object reference of unspecified type? AFIAK, the best you can do is just
plain 'object'. .NET is not like COM where there's a universal base
interface (IUnknown). All you have is a univeral object reference
(System::Object).
If you have an instance of System::Type and you want to know if a given
System::Object is reference convertible to that type, you can use
Type::IsInstanceOfType to determine if ths object is an instance of that
type.
HTH
-cd