Example #1
0
        public XAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, object firstArg, MethodInfo read, MethodInfo write)
            : base(fieldRW, attribute)
        {
            if (read.IsStatic)
            {
                this.read = MethodHelper.CreateDelegate <Func <IValueReader, T> >(read, SignatureLevels.Cast);
            }
            else
            {
                var _read = MethodHelper.CreateDelegate <Func <object, IValueReader, T> >(read, SignatureLevels.Cast);

                this.read = valueReader => _read(firstArg, valueReader);
            }

            if (write.IsStatic)
            {
                this.write = MethodHelper.CreateDelegate <Action <IValueWriter, T> >(write, SignatureLevels.Cast);
            }
            else
            {
                var _write = MethodHelper.CreateDelegate <Action <object, IValueWriter, T> >(write, SignatureLevels.Cast);

                this.write = (valueWriter, value) => _write(firstArg, valueWriter, value);
            }
        }
        public XDelegateAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags, object firstArg, MethodInfo read, MethodInfo write)
            : base(fieldRW, attribute, flags)
        {
            if (read.IsStatic)
            {
                this.read = MethodHelper.CreateDelegate <Func <IValueReader, T> >(read, false);
            }
            else
            {
                var _read = MethodHelper.CreateDelegate <Func <object, IValueReader, T> >(read, false);

                this.read = valueReader => _read(firstArg, valueReader);
            }

            if (write.IsStatic)
            {
                this.write = MethodHelper.CreateDelegate <Action <IValueWriter, T> >(write, false);
            }
            else
            {
                var _write = MethodHelper.CreateDelegate <Action <object, IValueWriter, T> >(write, false);

                this.write = (valueWriter, value) => _write(firstArg, valueWriter, value);
            }
        }
        protected XAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute)
        {
            this.fieldRW   = fieldRW;
            this.attribute = attribute;

            canRead  = (attribute.Access & RWFieldAccess.ReadOnly) != 0 && fieldRW.CanRead;
            canWrite = (attribute.Access & RWFieldAccess.WriteOnly) != 0 && fieldRW.CanWrite;

            name = attribute.Name ?? fieldRW.Name;
        }
Example #4
0
        public XAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute)
        {
            this.fieldRW   = fieldRW;
            this.attribute = attribute;

            canRead  = !(attribute.Access != RWFieldAccess.RW && attribute.Access != RWFieldAccess.ReadOnly && !fieldRW.CanRead);
            canWrite = !(attribute.Access != RWFieldAccess.RW && attribute.Access != RWFieldAccess.WriteOnly && !fieldRW.CanWrite);

            name = attribute.Name ?? fieldRW.Name;
        }
        protected XAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags)
        {
            this.fieldRW   = fieldRW;
            this.attribute = attribute;

            canRead  = (attribute.Access & RWFieldAccess.ReadOnly) != 0 && fieldRW.CanRead;
            canWrite = (attribute.Access & RWFieldAccess.WriteOnly) != 0 && fieldRW.CanWrite;

            skipDefaultValue   = attribute.SkipDefaultValue != RWBoolean.None ? attribute.SkipDefaultValue == RWBoolean.Yes : (flags & XBindingFlags.RWSkipDefaultValue) != 0;
            cannotGetException = attribute.CannotGetException != RWBoolean.None ? attribute.CannotGetException == RWBoolean.Yes : (flags & XBindingFlags.RWCannotGetException) != 0;
            cannotSetException = attribute.CannotSetException != RWBoolean.None ? attribute.CannotSetException == RWBoolean.Yes : (flags & XBindingFlags.RWCannotSetException) != 0;

            name = attribute.Name ?? fieldRW.Name;
        }
Example #6
0
 internal XFieldValueRW(object obj, IXFieldRW fieldRW)
 {
     this.obj     = obj;
     this.fieldRW = fieldRW;
 }
 public XInterfaceAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags, IValueInterface <T> valueInterface)
     : base(fieldRW, attribute, flags)
 {
     this.valueInterface = valueInterface;
 }
 public XInterfaceAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, IValueInterface <T> valueInterface) : base(fieldRW, attribute)
 {
     this.valueInterface = valueInterface;
 }
        public static XAttributedFieldRW Create(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags)
        {
            attribute.GetBestMatchInterfaceMethod(fieldRW.BeforeType, out var firstArg, out var read, out var write);

            if (read != null && write != null)
            {
                var valueType = write.GetParameters()[1].ParameterType;

                if (valueType != read.ReturnType)
                {
                    throw new NotSupportedException("The type of the value of the Read method is inconsistent with the value of the Write method.");
                }

                var type = firstArg.GetType();

                foreach (var item in type.GetInterfaces())
                {
                    if (item.IsGenericType && item.GetGenericTypeDefinition() == typeof(IValueInterface <>))
                    {
                        var arguments = item.GetGenericArguments();

                        if (arguments.Length == 1 && arguments[0] == valueType)
                        {
                            var rwType = typeof(XInterfaceAttributedFieldRW <>).MakeGenericType(valueType);

                            var map = type.GetInterfaceMap(item);

                            if ((map.TargetMethods.Contains(read) || map.InterfaceMethods.Contains(read)) &&
                                (map.TargetMethods.Contains(write) || map.InterfaceMethods.Contains(write)))
                            {
                                return((XAttributedFieldRW)Activator.CreateInstance(
                                           rwType,
                                           new object[] {
                                    fieldRW,
                                    attribute,
                                    flags,
                                    firstArg
                                }));
                            }
                        }
                    }
                }

                if (valueType.IsByRef || valueType.IsPointer)
                {
                    valueType = typeof(IntPtr);
                }

                return((XAttributedFieldRW)Activator.CreateInstance(
                           typeof(XDelegateAttributedFieldRW <>).MakeGenericType(valueType),
                           new object[] {
                    fieldRW,
                    attribute,
                    flags,
                    firstArg,
                    read,
                    write
                }));
            }

            return(new XAttributedFieldRW(fieldRW, attribute, flags));
        }
Example #10
0
        internal XFieldValueRW SetFieldRW(IXFieldRW fieldRW)
        {
            this.fieldRW = fieldRW;

            return(this);
        }
Example #11
0
 internal XFieldValueRW(XObjectRW objectRW, IXFieldRW fieldRW)
 {
     this.objectRW = objectRW;
     this.fieldRW  = fieldRW;
 }