Cottle.Values.ReflectionValue.Resolve C# (CSharp) Méthode

Resolve() protected méthode

protected Resolve ( ) : Value
Résultat Value
        protected override Value Resolve()
        {
            ValueConverter				converter;
            List<Value>					elements;
            Dictionary<Value, Value>	fields;
            List<MemberReader>			reader;
            Type						type;

            type = this.source.GetType ();

            // Use converter for known primitive types
            if (ReflectionValue.converters.TryGetValue (type, out converter))
                return converter (this.source);

            // Return undefined value for other primitive types
            #if CORECLR
            if (type.GetTypeInfo ().IsPrimitive)
            #else
            if (type.IsPrimitive)
            #endif
                return VoidValue.Instance;

            // Convert elements to array if source object is enumerable
            if (this.source is IEnumerable)
            {
                elements = new List<Value> ();

                foreach (object element in (IEnumerable)this.source)
                    elements.Add (new ReflectionValue (element));

                return elements;
            }

            // Otherwise, browse object fields and properties
            fields = new Dictionary<Value, Value> ();

            lock (ReflectionValue.readers)
            {
                if (!ReflectionValue.readers.TryGetValue (type, out reader))
                {
                    reader = new List<MemberReader> ();

                    foreach (FieldInfo field in type.GetFields (this.binding))
                        reader.Add (new MemberReader (field, this.binding));

                    foreach (PropertyInfo property in type.GetProperties (this.binding))
                        reader.Add (new MemberReader (property, this.binding));

                    ReflectionValue.readers[type] = reader;
                }
            }

            foreach (MemberReader extractor in reader)
                fields.Add (extractor.Name, extractor.Extract (this.source));

            return fields;
        }