Ejemplo n.º 1
0
        private static TypeKind CalcKind(FudgeContext context, TypeDataCache typeCache, Type type, FudgeFieldNameConvention fieldNameConvention, out TypeData subType, out TypeData subType2, out FudgeFieldType fieldType)
        {
            // REVIEW 2010-02-14 t0rx -- There seems to be some duplication here with the FudgeSurrogateSelector, should look at joining up
            subType   = null;
            subType2  = null;
            fieldType = context.TypeDictionary.GetByCSharpType(type);
            if (fieldType != null)
            {
                // Just a simple field
                return(TypeKind.FudgePrimitive);
            }

            // Check for arrays
            if (type.IsArray)
            {
                subType = typeCache.GetTypeData(type.GetElementType(), fieldNameConvention);
                return(TypeKind.Inline);
            }

            // Check for dictionaries
            Type keyType, valueType;

            if (DictionarySurrogate.IsDictionary(type, out keyType, out valueType))
            {
                subType  = typeCache.GetTypeData(keyType, fieldNameConvention);
                subType2 = typeCache.GetTypeData(valueType, fieldNameConvention);
                return(TypeKind.Inline);
            }

            // Check for lists
            Type elementType;

            if (ListSurrogate.IsList(type, out elementType))
            {
                subType = typeCache.GetTypeData(elementType, fieldNameConvention);
                return(TypeKind.Inline);
            }

            return(TypeKind.Reference);
        }