public static IGraphicDataProvider GetGraphicDataProviderForType(System.Type objType)
        {
            IGraphicDataProvider dataProvider = null;

            if (mGraphicTypes.TryGetValue(objType, out dataProvider))
            {
                return(dataProvider);
            }

            //Get data provider from the assembly of the type
            System.Type type = objType;
            while (dataProvider == null)
            {
                dataProvider = GetDataProviderFromAssembly(type);
                if (null != dataProvider)
                {
                    mGraphicTypes.Add(objType, dataProvider);
                    return(dataProvider);
                }

                type = type.BaseType;
                if (type == null)
                {
                    break;
                }
            }

            return(null);
        }
        private static IGraphicDataProvider GetDataProviderFromAssembly(System.Type type)
        {
            //Check if we already have a provider for the type.Assembly
            IGraphicDataProvider provider = null;

            if (mDataProviders.TryGetValue(type.Assembly, out provider))
            {
                return(provider);
            }

            mDataProviders.Add(type.Assembly, null); //initialize with no dataprovider from this type assembly

            //Check if this assembly implements IGraphicDataProvider interface
            var providerType = ProtoFFI.CLRDLLModule.GetImplemetationType(type.Assembly, typeof(IGraphicDataProvider), typeof(GraphicDataProviderAttribute), false);

            if (providerType == null)
            {
                return(null);
            }

            //Got the type of IGraphicDataProvider interface implementation
            //Create an instance of IGraphicDataProvider using default constructor.
            provider = (IGraphicDataProvider)Activator.CreateInstance(providerType, true);
            if (null != provider)
            {
                mDataProviders[type.Assembly] = provider;
            }

            return(provider);
        }
Beispiel #3
0
        public static List <IGraphicItem> GetGraphicItemsFromObject(object obj)
        {
            if (null == obj)
            {
                return(null);
            }

            List <IGraphicItem> items = new List <IGraphicItem>();

            System.Type objType    = obj.GetType();
            IEnumerable collection = obj as IEnumerable;

            if (null != collection)
            {
                foreach (var item in collection)
                {
                    try
                    {
                        List <IGraphicItem> graphics = GetGraphicItemsFromObject(item);
                        if (null != graphics)
                        {
                            items.AddRange(graphics);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("GetGraphicItems: " + e);
                    }
                }
                return(items);
            }

            IGraphicItem graphicItem = obj as IGraphicItem;

            if (graphicItem != null)
            {
                items.Add(graphicItem);
                return(items);
            }

            IGraphicDataProvider dataProvider = GetGraphicDataProviderForType(objType);

            if (null == dataProvider)
            {
                dataProvider = new GraphicObjectType(objType);
                mGraphicTypes.Add(objType, dataProvider);
            }

            return(dataProvider.GetGraphicItems(obj));
        }
        private List <PropertyInfo> GetGraphicProperties(System.Type type)
        {
            List <PropertyInfo> graphicProperties = new List <PropertyInfo>();

            PropertyInfo[] properties = type.GetProperties();
            foreach (var item in properties)
            {
                //Check if we have a data provider for this property type.
                IGraphicDataProvider provider = GraphicDataProvider.GetGraphicDataProviderForType(item.PropertyType);
                if (null != provider)
                {
                    graphicProperties.Add(item);
                }
            }

            return(graphicProperties);
        }