Пример #1
0
        public static DxfClassMap Create <T>()
            where T : CadObject
        {
            Type        type     = typeof(T);
            DxfClassMap classMap = new DxfClassMap();

            var att = type.GetCustomAttribute <DxfSubClassAttribute>();

            if (att == null)
            {
                throw new ArgumentException($"{type.FullName} is not a dxf subclass");
            }

            classMap.Name = type.GetCustomAttribute <DxfSubClassAttribute>().ClassName;

            addClassProperties(classMap, type);

            DxfSubClassAttribute baseAtt = type.BaseType.GetCustomAttribute <DxfSubClassAttribute>();

            if (baseAtt != null && baseAtt.IsEmpty)
            {
                //Properties in the table seem to be embeded to the hinerit type
                addClassProperties(classMap, type.BaseType);
            }

            return(classMap);
        }
Пример #2
0
        /// <summary>
        /// Creates a dxf map for an <see cref="Entity"/> or a <see cref="TableEntry"/>
        /// </summary>
        /// <remarks>
        /// This method does not work with the entities <see cref="AttributeEntity"/> and <see cref="AttributeDefinition"/>
        /// </remarks>
        public static DxfMap Create <T>()
            where T : CadObject
        {
            DxfMap map = new DxfMap();

            Type             type = typeof(T);
            DxfNameAttribute dxf  = type.GetCustomAttribute <DxfNameAttribute>();

            map.Name = dxf.Name;

            for (type = typeof(T); type != null; type = type.BaseType)
            {
                DxfSubClassAttribute subclass = type.GetCustomAttribute <DxfSubClassAttribute>();

                if (type.Equals(typeof(CadObject)))
                {
                    addClassProperties(map, type);

                    break;
                }
                else if (subclass != null && subclass.IsEmpty)
                {
                    DxfClassMap classMap = map.SubClasses.Last().Value;

                    addClassProperties(classMap, type);
                }
                else if (type.GetCustomAttribute <DxfSubClassAttribute>() != null)
                {
                    DxfClassMap classMap = new DxfClassMap();
                    classMap.Name = type.GetCustomAttribute <DxfSubClassAttribute>().ClassName;

                    addClassProperties(classMap, type);

                    map.SubClasses.Add(classMap.Name, classMap);
                }
            }

            return(map);
        }