Example #1
0
        protected override object ConvertTo(object[] handlerValues)
        {
            WhoAndWhenData result       = new WhoAndWhenData();
            Type           propertyType = this.GetHandlerSlot(0);

            if (propertyType.IsAssignableFrom(typeof(User)))
            {
                result.Who = (User)handlerValues[0];
            }
            else if (typeof(IEnumerable).IsAssignableFrom(propertyType))
            {
                var enumerableValue = handlerValues[0] as IEnumerable;
                foreach (User item in enumerableValue)
                {
                    result.Who = item;
                    break;
                }
            }

            if (handlerValues[1] != null)
            {
                result.When = (DateTime)handlerValues[1];
            }
            else
            {
                result.When = Providers.Instance.StorageSchema.DateTimeMinValue;
            }

            return(result);
        }
Example #2
0
        protected override object[] ConvertFrom(object value)
        {
            WhoAndWhenData data = value as WhoAndWhenData;

            if (data == null)
            {
                throw new NotSupportedException("Field value is null or not a WhoAndWhenData. FieldName: " + this.Name);
            }
            object[] result = new object[2];

            var nodeValue       = data.Who as Node;
            var enumerableValue = data.Who as IEnumerable;

            Type propertyType = this.GetHandlerSlot(0);

            if (typeof(Node).IsAssignableFrom(propertyType))
            {
                if (enumerableValue != null)
                {
                    foreach (Node node in enumerableValue)
                    {
                        result[0] = node;
                        break;
                    }
                }
                else
                {
                    result[0] = data.Who;
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(propertyType))
            {
                var refs = new List <Node>();
                if (enumerableValue != null)
                {
                    foreach (Node node in enumerableValue)
                    {
                        if (node != null)
                        {
                            refs.Add(node);
                            break;
                        }
                    }
                }
                else
                {
                    if (nodeValue != null)
                    {
                        refs.Add(nodeValue);
                    }
                }
                result[0] = refs;
            }
            else
            {
                throw new NotSupportedException(String.Concat(data.Who.GetType().FullName, " is not assignable to Who part of WhoAndWhen field. FieldName: ", this.Name));
            }

            result[1] = data.When;

            return(result);
        }
Example #3
0
		protected override object ConvertTo(object[] handlerValues)
		{
			WhoAndWhenData result = new WhoAndWhenData();
			Type propertyType = this.GetHandlerSlot(0);
			if (propertyType.IsAssignableFrom(typeof(User)))
			{
				result.Who = (User)handlerValues[0];
			}
			else if (typeof(IEnumerable).IsAssignableFrom(propertyType))
			{
                var enumerableValue = handlerValues[0] as IEnumerable;
                foreach (User item in enumerableValue)
                {
                    result.Who = item;
                    break;
                }
			}

			if (handlerValues[1] != null)
				result.When = (DateTime)handlerValues[1];
			else
				result.When = ActiveSchema.DateTimeMinValue;

			return result;
		}