Пример #1
0
        private static Func <IGeometryEntity, bool, DSGeometry> GetGeomConstructor(IGeometryEntity host)
        {
            Type type = host.GetType();

            Type[] interfaces = type.GetInterfaces();
            for (int i = interfaces.Length - 1; i >= 0; --i)
            {
                Func <IGeometryEntity, bool, DSGeometry> constructor;
                if (mGeometryContructors.TryGetValue(interfaces[i], out constructor))
                {
                    return(constructor);
                }
            }

            return(null);
        }
Пример #2
0
        internal static DSGeometry ToGeometry(IGeometryEntity host, bool persist = false, DSGeometry context = null)
        {
            if (host == null)
            {
                return(null);
            }

            if (host.Owner != null)
            {
                return(host.Owner as DSGeometry);
            }

            Func <IGeometryEntity, bool, DSGeometry> constructor = GetGeomConstructor(host);

            if (null == constructor)
            {
                throw new InvalidOperationException(string.Format("Can't locate DSGeometry constructor for type: {0}.", host.GetType()));
            }

            DSGeometry geom = constructor(host, persist);

            if (null != context)
            {
                geom.Context = context;
            }

            return(geom);
        }