Exemplo n.º 1
0
            public override void Init(object[] argumentObjects)
            {
                ISystemObject systemObject = argumentObjects[0] as ISystemObject;

                if (systemObject == null)
                {
                    CurrentValue = "?";
                    return;
                }

                Labelset labelset = argumentObjects[1] as Labelset;

                if (labelset == null)
                {
                    CurrentValue = "?";
                    return;
                }
                this.labelset = labelset;

                labelset.LabelTextChanged += labelsetLabelChanged;
                CurrentValue = labelset.GetText(systemObject);
            }
Exemplo n.º 2
0
        private object serializeValue(MemberInfo memberInfo, Type memberType, object item, object parentItem, int arrayDimension = 0)
        {
            if (item == null)
            {
                return(string.Empty);
            }

            ISystemObject itemAsSystemObject = item as ISystemObject;

            if ((itemAsSystemObject != null) && (memberInfo.GetCustomAttribute <PersistDetailedAttribute>() == null))
            {
                return(itemAsSystemObject.GlobalID);
            }

            if (memberType.IsArray && (item is Array))
            {
                Array           array         = item as Array;
                List <XElement> arrayElements = new List <XElement>();
                foreach (var element in array)
                {
                    arrayElements.Add(serializeCollectionElement(memberInfo, memberType.GetElementType(), element, parentItem, arrayDimension));
                }
                return(arrayElements);
            }

            bool isCollection = false;
            Type elementType  = null;

            foreach (Type interfaceType in memberType.GetInterfaces())
            {
                if (interfaceType.IsGenericType && (interfaceType.GetGenericTypeDefinition() == typeof(ICollection <>)))
                {
                    isCollection = true;
                    elementType  = interfaceType.GetGenericArguments()[0];
                    break;
                }
            }
            if (isCollection)
            {
                IEnumerable     enumerable    = item as IEnumerable;
                List <XElement> arrayElements = new List <XElement>();
                foreach (var element in enumerable)
                {
                    arrayElements.Add(serializeCollectionElement(memberInfo, elementType, element, parentItem, arrayDimension));
                }
                return(arrayElements);
            }

            if (Type.GetTypeCode(memberType) == TypeCode.Object)
            {
                Type itemType        = item.GetType();
                Type serializeAsType = memberType;

                PersistSubclassAttribute persistSubclassAttribute = memberInfo.GetCustomAttributes <PersistSubclassAttribute>().FirstOrDefault();
                if (persistSubclassAttribute != null) // should check if given type is subclass of member type
                {
                    serializeAsType = persistSubclassAttribute.SubclassType;
                }

                PolymorphFieldAttribute   polymorphFieldAttribute = memberInfo.GetCustomAttributes <PolymorphFieldAttribute>().FirstOrDefault();
                Dictionary <Type, string> typeStringDictionary    = null;
                string itemTypeString = null;
                if (polymorphFieldAttribute != null)
                {
                    MethodInfo typeStringDictionaryGetterMethodInfo = parentItem.GetType().GetMethod(polymorphFieldAttribute.TypeStringDictionaryGetterName, memberLookupBindingFlags);
                    typeStringDictionary = typeStringDictionaryGetterMethodInfo.Invoke(parentItem, new object[] { }) as Dictionary <Type, string>;
                    if (typeStringDictionary?.TryGetValue(itemType, out itemTypeString) == true)
                    {
                        serializeAsType = itemType;
                    }
                }

                IValueXmlSerializer serializer = GetSerializerForType(serializeAsType);
                if (serializer == null)
                {
                    return(item.ToString());
                }
                XElement serializedItem = serializer.SerializeItem(item, parentItem);
                if ((polymorphFieldAttribute?.TypeAttributeName != null) && (itemTypeString != null))
                {
                    serializedItem.SetAttributeValue(polymorphFieldAttribute.TypeAttributeName, itemTypeString);
                }
                return(serializedItem);
            }

            return(item.ToString());
        }
Exemplo n.º 3
0
 public Label(Labelset labelset, ISystemObject associatedObject = null)
 {
     Labelset         = labelset;
     AssociatedObject = associatedObject;
 }