Initialize() public static method

public static Initialize ( ConstructorInfo info, bool cache = true ) : DataWF.Common.EmitConstructor
info ConstructorInfo
cache bool
return DataWF.Common.EmitConstructor
Example #1
0
        public TypeSerializationInfo(Type type, IEnumerable <PropertyInfo> properties)
        {
            Type     = type;
            TypeName = TypeHelper.FormatBinary(Type);

            IsAttribute = TypeHelper.IsXmlAttribute(Type);
            if (IsAttribute)
            {
                Serialazer = TypeHelper.GetValueSerializer(type);
                return;
            }
            if (!Type.IsInterface)
            {
                Constructor = EmitInvoker.Initialize(type, Type.EmptyTypes);
            }

            IsList = TypeHelper.IsList(type);
            if (IsList)
            {
                IsNamedList    = TypeHelper.IsInterface(type, typeof(INamedList));
                ListItemType   = TypeHelper.GetItemType(type);
                ListDefaulType = ListItemType != typeof(object) &&
                                 !ListItemType.IsInterface &&
                                 !type.IsGenericType &&
                                 !type.IsArray &&
                                 !TypeHelper.IsInterface(type, typeof(ISortable));
                ListItemIsAttribute = TypeHelper.IsXmlAttribute(ListItemType);

                ListConstructor = EmitInvoker.Initialize(type, new[] { typeof(int) });
            }
            IsDictionary = TypeHelper.IsDictionary(type);

            Properties = new NamedList <PropertySerializationInfo>();
            Properties.Indexes.Add(PropertySaveInfoIsAttributeInvoker.Instance);

            foreach (var property in properties)
            {
                if (TypeHelper.IsNonSerialize(property))
                {
                    var exist = GetProperty(property.Name);
                    if (exist != null)
                    {
                        Properties.Remove(exist);
                    }
                    continue;
                }
                var info = new PropertySerializationInfo(property);
                {
                    var exist = GetProperty(info.Name);
                    if (exist != null)
                    {
                        Properties.Remove(exist);
                    }
                    Properties.Add(info);
                }
            }
        }
Example #2
0
 public CompaundInvoker(string property, List <MemberParseInfo> list)
 {
     this.property = property;
     foreach (var info in list)
     {
         invokers.Add(EmitInvoker.Initialize(info.Info, info.Index == null, info.Index));
     }
     lastInvoker = invokers.LastOrDefault();
 }
Example #3
0
        public TypeSerializationInfo(Type type, IEnumerable <PropertyInfo> properties)
        {
            Type     = type;
            TypeName = TypeHelper.FormatBinary(Type);

            IsAttribute = TypeHelper.IsSerializeAttribute(Type);
            if (IsAttribute)
            {
                Serialazer = TypeHelper.GetValueSerializer(type);
                return;
            }
            if (!Type.IsInterface && !Type.IsAbstract)
            {
                Constructor = EmitInvoker.Initialize(type, Type.EmptyTypes);
            }

            IsList = TypeHelper.IsList(type);
            if (IsList)
            {
                IsNamedList    = TypeHelper.IsInterface(type, typeof(INamedList));
                ListItemType   = TypeHelper.GetItemType(type);
                ListDefaulType = ListItemType != typeof(object) &&
                                 !ListItemType.IsInterface &&
                                 !type.IsGenericType &&
                                 !type.IsArray &&
                                 !TypeHelper.IsInterface(type, typeof(ISortable));
                ListItemIsAttribute = TypeHelper.IsSerializeAttribute(ListItemType);

                ListConstructor = EmitInvoker.Initialize(type, new[] { typeof(int) });
            }
            IsDictionary = TypeHelper.IsDictionary(type);

            Properties = new NamedList <PropertySerializationInfo>(6, (ListIndex <PropertySerializationInfo, string>)PropertySerializationInfo.NameInvoker.Instance.CreateIndex(false));
            Properties.Indexes.Add(PropertySerializationInfo.IsAttributeInvoker.Instance);
            int order = 0;

            foreach (var property in properties)
            {
                var exist = GetProperty(property.Name);
                if (TypeHelper.IsNonSerialize(property))
                {
                    if (exist != null)
                    {
                        Properties.Remove(exist);
                    }
                    continue;
                }
                //var method = property.GetGetMethod() ?? property.GetSetMethod();
                if (exist != null)// && method.Equals(method.GetBaseDefinition())
                {
                    Properties.Remove(exist);
                }

                Properties.Add(new PropertySerializationInfo(property, ++order));
            }
            Properties.ApplySortInternal(PropertySerializationInfo.OrderInvoker.Instance.CreateComparer <PropertySerializationInfo>());
        }
Example #4
0
        public static object CreateObject(Type type)
        {
            if (type == typeof(string))
            {
                return("");
            }
            var invoker = EmitInvoker.Initialize(type, Type.EmptyTypes, true);

            return(invoker?.Create());
        }
Example #5
0
 public PropertySerializationInfo(PropertyInfo property)
 {
     Property    = property;
     IsText      = TypeHelper.IsXmlText(property);
     IsAttribute = TypeHelper.IsXmlAttribute(property) && !IsText;
     Invoker     = EmitInvoker.Initialize(property, true);
     Default     = TypeHelper.GetDefault(property);
     if (IsAttribute || IsText)
     {
         Serialazer = TypeHelper.GetValueSerializer(property);
     }
     Name = property.Name;
 }
Example #6
0
        public static string GetFullName(IGroup item, string separator, string member)
        {
            var    invoker = EmitInvoker.Initialize(item.GetType(), member);
            string rez     = "";
            IGroup g       = item;

            while (g != null)
            {
                object val = invoker.GetValue(g);
                if (val != null)
                {
                    rez = val + separator + rez;
                }
                g = g.Group;
            }
            return(rez.Substring(0, rez.Length - separator.Length));
        }
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            if (property.Ignored)
            {
                return(property);
            }

            if (property.NullValueHandling != null)
            {
                if (TypeHelper.IsInterface(property.DeclaringType, typeof(ISynchronized)))
                {
                    var propertyName = property.PropertyName;
                    if (!TypeHelper.IsEnumerable(property.PropertyType))
                    {
                        property.ShouldSerialize =
                            instance =>
                        {
                            var e = (ISynchronized)instance;
                            return(e.Changes.ContainsKey(propertyName));
                        };
                    }
                    else if (TypeHelper.IsInterface(TypeHelper.GetItemType(property.PropertyType), typeof(ISynchronized)))
                    {
                        var propertyInvoker = EmitInvoker.Initialize(property.DeclaringType, propertyName);
                        property.ShouldSerialize =
                            instance =>
                        {
                            var collection = (IEnumerable)propertyInvoker.GetValue(instance);
                            return(collection != null && collection.TypeOf <ISynchronized>().Any(p => p.SyncStatus != SynchronizedStatus.Actual));
                        };
                    }
                }
            }
            else if (member.GetCustomAttribute <JsonIgnoreSerializationAttribute>() != null)
            {
                property.ShouldSerialize = instance => false;
            }

            return(property);
        }
Example #8
0
        public PropertySerializationInfo(PropertyInfo property, int order = -1)
        {
            Property = property;
            Name     = property.Name;
            DataType = Property.PropertyType;
            var keys = PropertySerializationInfoKeys.None;

            if (TypeHelper.IsSerializeText(property))
            {
                keys |= PropertySerializationInfoKeys.Text;
            }
            else if (TypeHelper.IsSerializeAttribute(property))
            {
                keys |= PropertySerializationInfoKeys.Attribute;
            }
            if (TypeHelper.IsSerializeWriteable(property))
            {
                keys |= PropertySerializationInfoKeys.Writeable;
            }
            if (TypeHelper.IsRequired(property))
            {
                keys |= PropertySerializationInfoKeys.Required;
            }
            if (TypeHelper.IsJsonSynchronized(property))
            {
                keys |= PropertySerializationInfoKeys.ChangeSensitive;
            }
            if (TypeHelper.IsReadOnly(property))
            {
                keys |= PropertySerializationInfoKeys.ReadOnly;
            }
            Keys    = keys;
            Order   = TypeHelper.GetOrder(property, order);
            Invoker = EmitInvoker.Initialize(property, true);

            Default = TypeHelper.GetDefault(property);
            if (IsAttribute || IsText)
            {
                Serialazer = TypeHelper.GetValueSerializer(property);
            }
        }
Example #9
0
 public InvokerComparer(PropertyInfo info, object index, ListSortDirection direction = ListSortDirection.Ascending)
     : this(index == null ? EmitInvoker.Initialize(info, true) : EmitInvoker.Initialize(info, index), direction)
 {
 }
Example #10
0
 public InvokerComparer(Type type, string property, ListSortDirection direction = ListSortDirection.Ascending)
     : this(EmitInvoker.Initialize(type, property), direction)
 {
 }
Example #11
0
 public InvokeBinder(D data, string dataProperty, V view, string viewProeprty)
     : this(data, EmitInvoker.Initialize(data.GetType(), dataProperty),
            view, EmitInvoker.Initialize(view.GetType(), viewProeprty))
 {
 }