예제 #1
0
        public IJT808_0x0200_Custom_Factory SetMap2 <TJT808_0x0200_CustomBody2>() where TJT808_0x0200_CustomBody2 : JT808_0x0200_CustomBodyBase2
        {
            Type type         = typeof(TJT808_0x0200_CustomBody2);
            var  instance     = Activator.CreateInstance(type);
            var  attachInfoId = (ushort)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase2.AttachInfoId)).GetValue(instance);

            if (Map2.ContainsKey(attachInfoId))
            {
                throw new ArgumentException($"{type.FullName} {attachInfoId} An element with the same key already exists.");
            }
            else
            {
                Map2.Add(attachInfoId, instance);
            }
            return(this);
        }
예제 #2
0
        public void Register(Assembly externalAssembly)
        {
            var types = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase)).ToList();

            foreach (var type in types)
            {
                var instance = Activator.CreateInstance(type);
                var attachid = (byte)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase.AttachInfoId)).GetValue(instance);
                if (Map.ContainsKey(attachid))
                {
                    throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists.");
                }
                else
                {
                    Map.Add(attachid, instance);
                }
            }

            var types2 = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase2)).ToList();

            foreach (var type in types2)
            {
                var instance = Activator.CreateInstance(type);
                var attachid = (ushort)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase2.AttachInfoId)).GetValue(instance);
                if (Map2.ContainsKey(attachid))
                {
                    throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists.");
                }
                else
                {
                    Map2.Add(attachid, instance);
                }
            }

            var types3 = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase3)).ToList();

            foreach (var type in types3)
            {
                var instance = Activator.CreateInstance(type);
                var attachid = (ushort)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase3.AttachInfoId)).GetValue(instance);
                if (Map3.ContainsKey(attachid))
                {
                    throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists.");
                }
                else
                {
                    Map3.Add(attachid, instance);
                }
            }

            var types4 = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase4)).ToList();

            foreach (var type in types4)
            {
                var instance = Activator.CreateInstance(type);
                var attachid = (byte)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase4.AttachInfoId)).GetValue(instance);
                if (Map4.ContainsKey(attachid))
                {
                    throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists.");
                }
                else
                {
                    Map4.Add(attachid, instance);
                }
            }
        }