using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Server;
public static class AOFactory <T>
{
public static T CreateObject(IServerContext SC, object ArcObject)
{
string progId = string.Empty;
try
{
Type t = ArcObject.GetType();
Guid guid = t.GUID;
progId = Win32API.ProgIDFromCLSID(ref guid);
}
catch { }
if (!string.IsNullOrEmpty(progId))
return (T)SC.CreateObject(progId);
else
return default(T);
}
}
public static class Win32API
{
[DllImport("ole32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern string ProgIDFromCLSID([In()]ref Guid clsid);
}
Sample:
ESRI.ArcGIS.Geometry.IPoint aoPoint = AOFactory<Geometry.IPoint>.CreateObject(sc, new ESRI.ArcGIS.Geometry.PointClass());
Qui puoi scaricare il codice
Nessun commento:
Posta un commento