Esempio n. 1
0
	//*************************************************************************
	// Method:		getManagedDefinition
	// Description: Uses reflection to get information about a managed method
	//
	// Parameters:
	//	fInfo	- structure which contains query data
	//
	// Return Value: (InterceptedFunction) the function definition
	//*************************************************************************
	InterceptedFunction * AddCustIntWizPg2::getManagedDefinition (functionInformation * fInfo)
	{
		
		InterceptedFunction * iFunc = new InterceptedFunction();
		
		//Set the function name
		iFunc->Name = fInfo->functionName;

		//Set the library location name
		iFunc->OriginalDll = Path::GetFileName(fInfo->libraryName);

		//LOAD THE ASSEMBLY TO GET MORE INFORMATION
		Assembly * asmLibrary = Assembly::LoadFrom (fInfo->libraryName);
		
		//Get the module
		Module * asmModule = asmLibrary->GetModule (fInfo->moduleName);

		//Get the type
		Type * moduleType = asmModule->GetType (fInfo->typeName);

		//Get the method 
		if (!fInfo->isConstructor)
		{
			MethodInfo * mi = NULL;
			try
			{
				mi = moduleType->GetMethod (getBaseName(fInfo->functionName), fInfo->bindingFlags, NULL, fInfo->paramTypeArray, NULL);
			}
			catch(...)
			{
				// in case of an exception, just return NULL
				return NULL;
			}

			if (!mi)
				return NULL;

			//Get Parameter Info
			ParameterInfo * paramInfo[] = mi->GetParameters();

			//Set the modifiers
			if (mi->IsPrivate) iFunc->AddTypeModifier ("private");
			if (mi->IsPublic) iFunc->AddTypeModifier ("public");
			if (mi->IsVirtual) iFunc->AddTypeModifier ("virtual");
			if (mi->IsAbstract) iFunc->AddTypeModifier ("abstract");
			if (mi->IsStatic) iFunc->AddTypeModifier ("static");

			//Set return type
			iFunc->ReturnType = mi->ReturnType->ToString();

			//Set Parameter Info
			for (int parCount = 0; parCount < paramInfo->Count; parCount++)
			{
				ParameterInfo * pInfo = paramInfo[parCount];
				InterceptedFunctionParameter * ifParam = new InterceptedFunctionParameter ();
				ifParam->ID = pInfo->Position;
				ifParam->Name = pInfo->Name;
				ifParam->Type = pInfo->ParameterType->FullName;
				ifParam->Access = "";
				if (pInfo->IsIn)
					ifParam->Access = "IN ";
				
				if (pInfo->IsOut)
					ifParam->Access = String::Concat(ifParam->Access, "OUT");
				
				if (ifParam->Access->Length == 0)
					ifParam->Access = "NONE";

				iFunc->AddParameter (ifParam);
			}
		}
		else
		{
			ConstructorInfo * ci = moduleType->GetConstructor (fInfo->bindingFlags, NULL, fInfo->paramTypeArray, NULL);
			
			if (!ci)
				return NULL;

			//Get Parameter Info
			ParameterInfo * paramInfo[] = ci->GetParameters();
	
			//Set the modifiers
			if (ci->IsPrivate) iFunc->AddTypeModifier ("private");
			if (ci->IsPublic) iFunc->AddTypeModifier ("public");
			if (ci->IsVirtual) iFunc->AddTypeModifier ("virtual");
			if (ci->IsAbstract) iFunc->AddTypeModifier ("abstract");
			if (ci->IsStatic) iFunc->AddTypeModifier ("static");

			//Set return type
			iFunc->ReturnType = S"System.Void";

			//Set Parameter Info
			for (int parCount = 0; parCount < paramInfo->Count; parCount++)
			{
				ParameterInfo * pInfo = paramInfo[parCount];
				InterceptedFunctionParameter * ifParam = new InterceptedFunctionParameter ();
				ifParam->ID = pInfo->Position;
				ifParam->Name = pInfo->Name;
				ifParam->Type = pInfo->ParameterType->FullName;
				ifParam->Access = "";
				if (pInfo->IsIn)
					ifParam->Access = "IN ";
				
				if (pInfo->IsOut)
					ifParam->Access = String::Concat(ifParam->Access, "OUT");
				
				if (ifParam->Access->Length == 0)
					ifParam->Access = "NONE";

				iFunc->AddParameter (ifParam);
			}
		}

		return iFunc;
	}