Пример #1
0
        internal static void MapProperties(BlazorComponent o)
        {
            var mappedProperties = DevUtils
                                   .GetAllProperties(o)
                                   .Where(x => x.CustomAttributes.Any(y => y.AttributeType == typeof(DevMapAttribute)));

            foreach (var property in mappedProperties)
            {
                Dev.Map(o, property.GetValue(o),
                        ((DevMapAttribute)property.GetCustomAttributes(typeof(DevMapAttribute), false)[0]).MapName);
            }
        }
Пример #2
0
        internal static void MapFields(BlazorComponent o)
        {
            var mappedFields = DevUtils
                               .GetAllFields(o)
                               .Where(x => x.CustomAttributes.Any(y => y.AttributeType == typeof(DevMapAttribute)));

            foreach (var field in mappedFields)
            {
                Dev.Map(o, field.GetValue(o),
                        ((DevMapAttribute)field.GetCustomAttributes(typeof(DevMapAttribute), false)[0]).MapName);
            }
        }
Пример #3
0
        /// <summary>
        /// Map C# referance type instance to Js object with custom name.
        /// </summary>
        /// <param name="context">Component that contains the object, mostly 'this' keyword.</param>
        /// <param name="o">Reference type object</param>
        /// <param name="name">Js variable name</param>
        public static void Map(BlazorComponent context, object o, string name, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0)
        {
            if (!(context is DevComponent))
            {
                return;
            }

            //Add DevBoot Js code
            DevUtils.DevBoot();

            AddToOrUpdateObjectList(o, name);
            UpdateMappingLayer();

            DevUtils.DevWarn($"Mapped {o.GetType().FullName} object in {filePath} at line {lineNumber}.");
        }
Пример #4
0
        private static async Task UpdateMapping()
        {
            if (!_isLooped)
            {
                _isLooped = true;
            }
            else
            {
                return;
            }

            PropertyInfo[] properties;
            FieldInfo[]    fields;

            do
            {
                try
                {
                    foreach (var o in _objects)
                    {
                        await EvalAsync($"window.{o.Key} = {{}}");

                        properties = o.Value.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                        fields     = o.Value.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                        foreach (var property in properties)
                        {
                            var value = property.GetValue(o.Value);

                            if (value == null)
                            {
                                await EvalAsync($"{o.Key}.{property.Name} = {{value: null}}");

                                //Map set method to Js
                                await MapSetMethods(o, property);

                                continue;
                            }

                            var convertedResult = DevUtils.AsConverted(value, property.PropertyType);

                            if (convertedResult.Item2 != DevUtils.TypeGroup.Others)
                            {
                                await EvalAsync($"{o.Key}.{property.Name} = {{value: {convertedResult.Item1.ToString().ToLower()}}}");
                            }

                            else
                            {
                                await EvalAsync($"{o.Key}.{property.Name} = {{value: \"{convertedResult.Item1}\"}}");
                            }

                            //Map set method to Js
                            await MapSetMethods(o, property);
                        }

                        foreach (var field in fields)
                        {
                            //Skip backing field
                            if (field.Name[0] == '<')
                            {
                                continue;
                            }

                            var value = field.GetValue(o.Value);

                            if (value == null)
                            {
                                await EvalAsync($"{o.Key}.{field.Name} = {{value: null}}");

                                //Map set method to Js
                                await MapSetMethods(o, field);

                                continue;
                            }

                            var convertedResult = DevUtils.AsConverted(value, field.FieldType);

                            if (convertedResult.Item2 != DevUtils.TypeGroup.Others)
                            {
                                await EvalAsync($"{o.Key}.{field.Name} = {{value: {convertedResult.Item1.ToString().ToLower()}}}");
                            }
                            else
                            {
                                await EvalAsync($"{o.Key}.{field.Name} = {{value: \"{convertedResult.Item1}\"}}");
                            }

                            //Map set method to Js
                            await MapSetMethods(o, field);
                        }
                    }
                }
                catch
                {
                    //Skip bug
                }

                await Task.Delay(500);
            } while (true);
        }
Пример #5
0
 internal static async void AddToStorage(DevComponent o)
 {
     DevComponentStorage.Add(o);
     await DevUtils.DevWarnAsync($"{o.GetType().FullName} is now a dev component");
 }