Beispiel #1
0
        public static Metadata GetOrCreate(Object child)
        {
            Metadata res = Get(child);

            if (res == null)
            {
                System.Diagnostics.Debug.WriteLine("Creating metadata for " + child.Name);
                Type metaType = BPDClassMetadataAttribute.GetMetadataType(child.GetType());
                if (metaType == null)
                {
                    throw new Exception(child.Name + " does have no metadata class defined.");
                }
                res = (Metadata)Activator.CreateInstance(metaType);
                MetadataHandler.instance.Add(child, res);
                return(res);
            }
            else
            {
                return(res);
            }
        }
Beispiel #2
0
        private static List <BPDSerializationInfo> GetListedSerializationData(Type t, int metaDepth = 0)
        {
            List <BPDSerializationInfo> sinfo = new List <BPDSerializationInfo>();

            var fields = t.GetFields().Where(prop => prop.IsDefined(typeof(BPDAttribute), false));

            foreach (var field in fields)
            {
                sinfo.Add(new BPDSerializationInfo(((BPDAttribute[])field.GetCustomAttributes(typeof(BPDAttribute), false))[0], field, metaDepth));
                System.Diagnostics.Debug.WriteLine("new field at height: " + metaDepth + " called " + sinfo[sinfo.Count - 1].Name + " in type " + t.FullName);
            }

            var props = t.GetProperties().Where(prop => prop.IsDefined(typeof(BPDAttribute), false));

            foreach (var prop in props)
            {
                sinfo.Add(new BPDSerializationInfo(((BPDAttribute[])prop.GetCustomAttributes(typeof(BPDAttribute), false))[0], prop, metaDepth));
            }

            sinfo.Sort(delegate(BPDSerializationInfo a, BPDSerializationInfo b)
            {
                return(a.attrib.position.CompareTo(b.attrib.position));
            });

            //do the same for the metadata class, then combine two lists.
            Type mdt = BPDClassMetadataAttribute.GetMetadataType(t);

            if (mdt != null)
            {
                System.Diagnostics.Debug.WriteLine("Reading meta of " + t.FullName);

                List <BPDSerializationInfo> metaInfo = GetListedSerializationData(mdt, ++metaDepth);
                metaInfo.AddRange(sinfo);
                return(metaInfo);
            }
            else
            {
                return(sinfo);
            }
        }