For a given type we hold the relevant fields with regards to printing, and functors for retrieving the content of the fields. The functors enables synthetic fields. E.g. a field that represents the call to the object's ToString().
示例#1
0
 public void TryAdd(Type type, ReflectionInfo fields)
 {
     cacheLock.EnterWriteLock();
     try
     {
         harvestCache.Add(type, fields);
     }
     finally
     {
         cacheLock.ExitWriteLock();
     }
 }
示例#2
0
 public void TryAdd(Type type, ReflectionInfo fields)
 {
     cacheLock.EnterWriteLock();
     try
     {
         if (!harvestCache.ContainsKey(type))
         {
             harvestCache.Add(type, fields);
         }
     }
     finally
     {
         cacheLock.ExitWriteLock();
     }
 }
示例#3
0
        void IntrospectComplexType(object source, Field field, Type sourceType)
        {
            Reference optionReferenceInfo;

            seenBefore.TryGetValue(source, out optionReferenceInfo);

            tokens.Add(new Token(TokenType.FieldnameWithTypeAndReference, field, null, optionReferenceInfo, sourceType));
            tokens.Add(Startscope);

            ReflectionInfo reflection = ReflectFields(sourceType);

            for (int i = 0; i < reflection.Fields.Length; i++)
            {
                Introspect(reflection.ValueProviders[i](source), reflection.Fields[i]);
            }

            tokens.Add(Endscope);
        }
示例#4
0
        ReflectionInfo ReflectFields(Type sourceType)
        {
            ReflectionInfo reflection;

            if ((reflection = harvestCache.TryGet(sourceType)) == null)
            {
                IFieldHarvester harvester;
                if (!configuration.TryGetFieldHarvester(sourceType, out harvester))
                {
                    throw new Exception(
                              string.Format(
                                  "No fieldharvester is configured for handling type '{0}'. Try using 'ConfigurationHelper.GetStandardConfiguration()' to get started.",
                                  sourceType));
                }

                List <SanitizedFieldInfo> fields = harvester.GetFields(sourceType);
                reflection = new ReflectionInfo(fields);
                harvestCache.TryAdd(sourceType, reflection);
            }

            return(reflection);
        }