Exemple #1
0
        public static dynamic GenerateDynamicItem(JToken actualItem)
        {
            var propDict = actualItem.Cast <JProperty>().Where(p => p.Name.StartsWith("RegistrationStub.")).ToDictionary(p => p.Name.Replace("RegistrationStub.", String.Empty), p => p.Value);

            IEnumerable <PropertySpec> types = propDict.Select(p => new PropertySpec(GetType(p.Value), p.Key));

            Type targetType = DynamicTypeFactory.GenerateDynamicType(TargetType, true, types.ToArray <PropertySpec>());

            dynamic dynamicItem = DynamicTypeFactory.GenerateCustomItem(targetType);

            return(PopulateDynamicItem(targetType, actualItem, dynamicItem));
        }
Exemple #2
0
        public static dynamic GenerateDynamicItem(DynamicTableEntity actualItem)
        {
            // Parse EdmTypes
            IEnumerable <PropertySpec> types = actualItem.Properties
                                               .Where(p => TargetType.GetProperty(p.Key) == null)
                                               .Select(p => new PropertySpec(Type.GetType("System." + p.Value.PropertyType.ToString()), p.Key));

            Type targetType = DynamicTypeFactory.GenerateDynamicType(TargetType, false, types.ToArray <PropertySpec>());

            dynamic dynamicItem = DynamicTypeFactory.GenerateCustomItem(targetType);

            return(PopulateDynamicItem(targetType, actualItem, dynamicItem));
        }