/// <summary> /// Initializes a new instance of the <see cref="UserTypeTransformation"/> class. /// </summary> /// <param name="transformation">The XML transformation definition.</param> /// <param name="typeConverter">The type converter.</param> /// <param name="ownerUserType">The owner user type.</param> /// <param name="type">The type that should be transformed to user type.</param> public UserTypeTransformation(XmlTypeTransformation transformation, Func <string, string> typeConverter, UserType ownerUserType, Symbol type) { Transformation = transformation; this.typeConverter = typeConverter; this.ownerUserType = ownerUserType; this.type = type; typeStringCache = SimpleCache.CreateStruct(() => Transformation.TransformType(type.Name, typeConverter)); }
/// <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) { // Check if we have any transformation if (typeTransformations.Length == 0) { return(null); } // Find first transformation that matches the specified type string originalFieldTypeString = type.Name; XmlTypeTransformation 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) => { XmlTypeTransformation tr = typeTransformations.FirstOrDefault(t => t.Matches(inputType)); if (tr != null) { return(tr.TransformType(inputType, typeConverter)); } UserType userType; if (GetUserType(type.Module, inputType, out userType)) { return(ownerUserType.Factory.GetSymbolTypeInstance(ownerUserType, userType.Symbol).GetTypeString()); } 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.Factory.GetSymbolTypeInstance(ownerUserType, symbol).GetTypeString()); } } return(new VariableTypeInstance(CodeNaming).GetTypeString()); }; return(new UserTypeTransformation(transformation, typeConverter, ownerUserType, type)); }