Ejemplo n.º 1
0
        public ContractActivator(Type type)
        {
            //if(!anonimouseType)
            {
                _activator            = DynamicReflectionDelegateFactory.CreateDefaultConstructor <object>(type);
                OnDeserializingHandle = null;

                MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (MethodInfo method in methods)
                {
                    if (method.IsDefined(typeof(OnDeserializingAttribute), false))
                    {
                        OnDeserializingHandle = DynamicReflectionDelegateFactory.CreateOnDeserializingMethodCall(method, type);
                    }

                    if (method.IsDefined(typeof(OnDeserializedAttribute), false))
                    {
                        OnDeserializedHandle = DynamicReflectionDelegateFactory.CreateOnDeserializedMethodCall(method, type);
                    }
                }
            }
            //else
            //{
            //    _anonimousActivator = DynamicReflectionDelegateFactory.Instance.CreateAnonimousConstructor(type);

            //    // поля у анонимных типов не рассматриваются.
            //    // берем только свойства по умолчанию.
            //    var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            // порядок полей такой же как у конструктора.
            //AnonimousProperties = properties
            //    .Select((x, Index) => new { PropertyInfo = x, Index })
            //    .ToDictionary(x => x.PropertyInfo.Name, x => new AnonimousProperty(x.Index, x.PropertyInfo.PropertyType));
            //}
        }
Ejemplo n.º 2
0
 public AnonymousObjectMapper(Type type)
 {
     _activator  = DynamicReflectionDelegateFactory.CreateAnonimousConstructor(type);
     _properties = type.GetProperties().Select(x => new AnonProperty
     {
         Name         = x.Name,
         PropertyType = x.PropertyType,
     }).ToArray();
 }
Ejemplo n.º 3
0
        public MikroTikProperty(MemberInfo memberInfo)
        {
            if (memberInfo is PropertyInfo propertyInfo)
            {
                MemberType = propertyInfo.PropertyType;
            }
            else
            {
                var fieldInfo = (FieldInfo)memberInfo;
                MemberType = fieldInfo.FieldType;
            }

            SetValueHandler = new SetMemberValueDelegate(DynamicReflectionDelegateFactory.CreateSet <object>(memberInfo));
            //var attribute = memberInfo.GetCustomAttribute<TypeConverterAttribute>();
            //if (attribute != null)
            //{
            //    Converter = _converters.GetOrAdd(attribute.ConverterType, ConverterValueFactory);
            //}
        }