Ejemplo n.º 1
0
 private static void MakeEdgeProperties(Type entity, Type dataContract, TypeBuilder typeBuilder, Type baseType)
 {
     foreach (var prop in dataContract.GetProperties())
     {
         var serialization = Serialization(entity, prop) ??
                             prop.GetCustomAttribute <InlineSerializationAttribute>();
         if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) && prop.PropertyType.IsGenericType)
         {
             if (serialization != null)
             {
                 AddInline(prop, typeBuilder, serialization, entity, baseType);
                 InlineCollection <string> .SetSerializationType($"{typeBuilder.FullName}.{prop.Name}",
                                                                 serialization?.Type ?? SerializationType.ClearText);
             }
         }
         else
         {
             AddValueProperty(typeBuilder, prop, baseType);
         }
     }
 }
Ejemplo n.º 2
0
        public static Type MakeEdgeDataEntity(Type entity, string label)
        {
            EdgeLables.TryAdd(entity, label);
            var dataContract = entity;
            var generics     = entity.GetInterfaces().Single(c => c.GenericTypeArguments.Length == 2).GenericTypeArguments;
            var baseType     = typeof(EdgeDataEntity <,>).MakeGenericType(generics);

            if (_builder == null)
            {
                _builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Data.Contracts.Implementations"),
                                                                 AssemblyBuilderAccess.Run);
            }
            if (_moduleBuilder == null)
            {
                _moduleBuilder = _builder.DefineDynamicModule("Data.Contracts.Implementations");
            }
            var typeBuilder = _moduleBuilder.DefineType("Data.Contracts.Implementations.Edges" + entity.Name.Remove(0, 1),
                                                        TypeAttributes.Public | TypeAttributes.Class,
                                                        baseType,
                                                        new[] { dataContract }
                                                        );

            AddLabelProperty(label, typeBuilder);
            AddIdProperty(typeBuilder, baseType);
            var eagerProperties = new List <string>();

            foreach (var prop in dataContract.GetProperties())
            {
                var eager         = EagerLoading(entity, prop) ?? prop.GetCustomAttribute <EagerAttribute>();
                var serialization = Serialization(entity, prop) ?? prop.GetCustomAttribute <InlineSerializationAttribute>();
                if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) && prop.PropertyType.IsGenericType)
                {
                    if (serialization != null)
                    {
                        AddInline(prop, typeBuilder, serialization, entity, baseType);
                        InlineCollection <string> .SetSerializationType($"{typeBuilder.FullName}.{prop.Name}", serialization?.Type ?? SerializationType.ClearText);
                    }
                    //else
                    //{
                    //    AddEdge(entity, prop, typeBuilder);
                    //    if (eager != null)
                    //        eagerProperties.Add(prop.Name);
                    //}
                }
                //else if (typeof(IEdgeReference).IsAssignableFrom(prop.PropertyType))
                //{
                //    AddEdgeRef(prop, typeBuilder, entity);
                //    if (eager != null)
                //        eagerProperties.Add(prop.Name);
                //}
                else if (prop.SetMethod != null)
                {
                    AddValueProperty(typeBuilder, prop, baseType);
                }
            }
            if (eagerProperties.ContainsElements())
            {
                GraphDataEntity._eagerLodedProperties.TryAdd(typeBuilder.FullName, eagerProperties);
            }
            return(typeBuilder.CreateTypeInfo());
        }
Ejemplo n.º 3
0
        public static Type MakeDataEntity(Type entity, string label)
        {
            var dataContract = entity;

            if (_builder == null)
            {
                _builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Data.Contracts.Implementations"),
                                                                 AssemblyBuilderAccess.Run);
            }
            if (_moduleBuilder == null)
            {
                _moduleBuilder = _builder.DefineDynamicModule("Data.Contracts.Implementations");
            }
            var typeBuilder = _moduleBuilder.DefineType("Data.Contracts.Implementations." + entity.Name.Remove(0, 1),
                                                        TypeAttributes.Public | TypeAttributes.Class,
                                                        typeof(GraphDataEntity),
                                                        new[] { dataContract }
                                                        );

            AddLabelProperty(label, typeBuilder);
            AddIdProperty(typeBuilder);
            var eagerProperties = new List <string>();

            foreach (var prop in dataContract.GetProperties())
            {
                var eager         = prop.GetCustomAttribute <EagerAttribute>();
                var serialization = prop.GetCustomAttribute <InlineSerializationAttribute>();
                if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) && prop.PropertyType.IsGenericType)
                {
                    if (serialization != null)
                    {
                        AddInline(prop, typeBuilder, serialization);
                        InlineCollection <string> .SetSerializationType($"{typeBuilder.FullName}.{prop.Name}", serialization?.Type ?? SerializationType.ClearText);
                    }
                    else
                    {
                        AddEdge(prop, typeBuilder);
                        if (eager != null)
                        {
                            eagerProperties.Add(prop.Name);
                        }
                    }
                }
                else if (typeof(IEdgeReference).IsAssignableFrom(prop.PropertyType))
                {
                    AddEdgeRef(prop, typeBuilder);
                    if (eager != null)
                    {
                        eagerProperties.Add(prop.Name);
                    }
                }
                else if (prop.SetMethod != null)
                {
                    AddValueProperty(typeBuilder, prop);
                }
            }
            if (eagerProperties.ContainsElements())
            {
                GraphDataEntity._eagerLodedProperties.TryAdd(typeBuilder.FullName, eagerProperties);
            }
            return(typeBuilder.CreateTypeInfo());
        }