Ejemplo n.º 1
0
        public static ObjectSpecs NewSingleSpec(ISpec spec, Type objType)
        {
            string getError(object obj)
            {
                return($"Type mismatched, got: {obj.GetType()}, expected: {objType}.");
            }

            var specs = new Specs();

            specs.AddSpec(spec);

            object?deserializeValue = null;
            object?serializeValue   = null;

            return(new ObjectSpecs(
                       specs,

                       (_, _) => null,
                       (_, v) =>
            {
                if (v != null && !objType.IsInstanceOfType(v))
                {
                    throw new InvalidOperationException(getError(v));
                }

                deserializeValue = v;
            },
                       (_, _) => deserializeValue,

                       (_, obj) =>
            {
                if (obj != null && !objType.IsInstanceOfType(obj))
                {
                    throw new InvalidOperationException(getError(obj));
                }

                serializeValue = obj;
            },
                       _ => serializeValue,
                       (_, _) => { }));
        }
Ejemplo n.º 2
0
 public MemberSpecs(Type objType)
 {
     mObjType         = objType;
     mSpec2MemberInfo = new Dictionary <ISpec, MemberInfo>();
     mSpecs           = new Specs();
 }