Beispiel #1
0
        /// <summary>
        /// Tries to match transformation for the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="ownerUserType">The owner user type.</param>
        /// <returns>Transformation if matched one is found; otherwise null.</returns>
        internal UserTypeTransformation FindTransformation(Symbol type, UserType ownerUserType)
        {
            // Find first transformation that matches the specified type
            string originalFieldTypeString = type.Name;
            var    transformation          = typeTransformations.FirstOrDefault(t => t.Matches(originalFieldTypeString));

            if (transformation == null)
            {
                return(null);
            }

            // Create type converter function for the transformation
            Func <string, string> typeConverter = null;

            typeConverter = (inputType) =>
            {
                var tr = typeTransformations.FirstOrDefault(t => t.Matches(inputType));

                if (tr != null)
                {
                    return(tr.TransformType(inputType, ownerUserType.ClassName, typeConverter));
                }

                UserType userType;

                if (GetUserType(type.Module, inputType, out userType))
                {
                    return(userType.NonSpecializedFullClassName);
                }

                Symbol symbol = type.Module.GetSymbol(inputType);

                if (symbol != null)
                {
                    if ((symbol.Tag == CodeTypeTag.BuiltinType) ||
                        (symbol.Tag == CodeTypeTag.Pointer && symbol.ElementType.Tag == CodeTypeTag.BuiltinType) ||
                        (symbol.Tag == CodeTypeTag.Array && symbol.ElementType.Tag == CodeTypeTag.BuiltinType))
                    {
                        return(ownerUserType.GetSymbolTypeTree(symbol, null).GetTypeString());
                    }
                }

                return("Variable");
            };

            return(new UserTypeTransformation(transformation, typeConverter, ownerUserType, type));
        }