示例#1
0
        protected override IBaseElement CreateElement(object xpdlItem)
        {
            Event        @event       = GetXpdlType <Event>(xpdlItem);
            EventElement eventElement = new EventElement();
            EventType    type         = XpdlTypeAttribute.GetCorrespondingEnum <EventType>(@event.Item.GetType());

            eventElement.Type = type;
            return(eventElement);
        }
示例#2
0
        public override void ProcessActivity(Activity activity, IBaseElement baseElement)
        {
            EventElement eventElement = GetType <EventElement>(baseElement);
            Event        @event       = new Event();
            Type         xpdlType     = XpdlTypeAttribute.GetCorrespondingType(eventElement.Type);

            if (xpdlType != null)
            {
                @event.Item = Activator.CreateInstance(xpdlType);
            }
            activity.Item = @event;
        }
示例#3
0
        public static T GetCorrespondingEnum <T>(Type objectType) where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }
            Type enumType    = typeof(T);
            var  memberInfos = enumType.GetMembers();

            foreach (var memberInfo in memberInfos)
            {
                XpdlTypeAttribute attribute = memberInfo.GetCustomAttribute(typeof(XpdlTypeAttribute)) as XpdlTypeAttribute;
                if (attribute != null && attribute.XpdlType == objectType)
                {
                    T result = (T)Enum.Parse(enumType, memberInfo.Name);
                    return(result);
                }
            }
            throw new EnumNotFoundException(enumType, objectType);
        }
示例#4
0
        public static Type GetCorrespondingType <T>(T enumType) where T : struct, IConvertible
        {
            Type result = null;

            if (!typeof(T).IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }
            var type       = typeof(T);
            var memberInfo = type.GetMember(enumType.ToString());

            if (memberInfo.Length > 0)
            {
                XpdlTypeAttribute attribute = memberInfo[0].GetCustomAttribute(typeof(XpdlTypeAttribute)) as XpdlTypeAttribute;
                if (attribute != null)
                {
                    result = attribute.XpdlType;
                }
            }
            return(result);
        }