Represents the object resulting from construction as well as a tail holding any remainders.
Beispiel #1
0
        public ObjectConstructionResult CreateObject(ImportContext context, NamedJsonBuffer[] members)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }

            if (_ctors.Length > 0)
            {
                foreach (ConstructorInfo ctor in _ctors)
                {
                    ObjectConstructionResult result = TryCreateObject(context, ctor, members);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            if (_type.IsValueType)
            {
                //
                // Value types always have a default constructor available
                // but one which does not show up in reflection. If no other
                // constructors matched then just use the default one.
                //

                object     obj  = Activator.CreateInstance(_type);
                JsonReader tail = NamedJsonBuffer.ToObject(members).CreateReader();
                return(new ObjectConstructionResult(obj, tail));
            }

            throw new JsonException(string.Format("None constructor could be used to create {0} object from JSON.", _ctors[0].DeclaringType));
        }