public void DefaultCtor()
        {
            var da = new DynamicAttribute();

            Assert.AreEqual(da.TransformFlags, new [] { true });
            Assert.IsTrue(da.TransformFlags.IsReadOnly);
        }
示例#2
0
        public void DefaultCtorSingleTrueFlag()
        {
            IList <bool> flags = new DynamicAttribute().TransformFlags;

            Assert.Equal(1, flags.Count);
            Assert.True(flags[0]);
        }
示例#3
0
        private static object Deserialize(XElement element, Type type)
        {
            if (DynamicAttribute.IsObjectDynamic(type))
            {
                return(DeserializeObject(element.Elements(), type));
            }

            var item       = Activator.CreateInstance(type);
            var properties = type.GetProperties()
                             .ToDictionary(x => x.Name.ToLower(), x => x);

            foreach (var attribute in element.Attributes())
            {
                if (properties.TryGetValue(attribute.Name.ToString().ToLower(), out var property))
                {
                    var propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
                    var value        = Convert.ChangeType(attribute.Value, propertyType);
                    property.SetValue(item, value);
                }
            }

            if (item is SQEX.Ebony.Object obj)
            {
                var childType = GetSafeType($"{obj.Type}");
                if (childType != null)
                {
                    obj.Item = DeserializeObject(element.Elements(), childType);
                }
            }
            else
            {
                foreach (var e in element.Elements())
                {
                    if (properties.TryGetValue(e.Name.ToString().ToLower(), out var property))
                    {
                        bool isCollection = e.HasAttributes == false && e.HasElements;
                        if (isCollection)
                        {
                            var collectionType = property.PropertyType.GenericTypeArguments[0];
                            var collection     = DeserializeCollection(e, collectionType);
                            property.SetValue(item, collection);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }

            return(item);
        }
示例#4
0
        static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)
        {
            if (attributeProvider == null)
            {
                return(false);
            }
            object[] attributes = attributeProvider.GetCustomAttributes(typeof(DynamicAttribute), false);
            if (attributes.Length == 0)
            {
                return(false);
            }
            DynamicAttribute attr = attributes[0] as DynamicAttribute;

            if (attr != null)
            {
                var transformFlags = attr.TransformFlags;
                if (transformFlags != null && typeIndex < transformFlags.Count)
                {
                    return(transformFlags[typeIndex]);
                }
                return(true);
            }
            return(false);
        }
        public void TransformCtor()
        {
            var da = new DynamicAttribute(new [] { false, true, false });

            Assert.AreEqual(da.TransformFlags, new [] { false, true, false });
        }
示例#6
0
 /** Todo
  */
 public void CopyAttributesTo(DynamicAttribute dynamicAttribute)
 {
     DynamicAttributeOscillate_CopyAttributesTo(nativePointer, dynamicAttribute.NativePointer);
 }
示例#7
0
 /** Todo
  */
 public void CopyAttributesTo(DynamicAttribute dynamicAttribute)
 {
     DynamicAttributeCurved_CopyAttributesTo(nativePointer, dynamicAttribute.NativePointer);
 }