public static void AddParameter(DbCommand command, string paramName, CsType csDataType, ParameterDirection direction, object value)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "The AddParameter's Command value is null.");
            }

            try
            {
                DbParameter parameter = command.CreateParameter();
                parameter.ParameterName = paramName;
                parameter.DbType        = CSharpDbTypeConverter(csDataType);
                parameter.Value         = value ?? DBNull.Value;
                parameter.Direction     = direction;
                command.Parameters.Add(parameter);
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true);
                throw new Exception("DBHelper::AddParameter::Error occured.", ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Extension method that creates the array portion definition of a type definition in C# syntax.
        /// </summary>
        /// <param name="source">The source type to get the array information to format.</param>
        /// <returns>The formatted array syntax for the target type, or null if no array data was provided in the type definition.</returns>
        public static string CSharpFormatArraySignature(this CsType source)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsArray)
            {
                return(null);
            }

            var arraySignatureBuilder = new StringBuilder();

            foreach (var sourceArrayDimension in source.ArrayDimensions)
            {
                arraySignatureBuilder.Append(sourceArrayDimension == 1
                    ? $"{Symbols.ArrayDefinitionStart}{Symbols.ArrayDefinitionEnd}"
                    : $"{Symbols.ArrayDefinitionStart}{new string(',', sourceArrayDimension - 1)}{Symbols.ArrayDefinitionEnd}");
            }

            return(arraySignatureBuilder.ToString());
        }
예제 #3
0
        public void AddParameterToCommand(DbCommand command, string paramName, CsType csDataType, ParameterDirection direction, object value)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "The AddParameterToCommand Command is null.");
            }

            try
            {
                DbParameter param = command.CreateParameter();
                param.ParameterName = paramName;
                param.DbType        = ConvertCsharpDataTypeToDbType(csDataType);
                param.Value         = value ?? DBNull.Value;
                param.Direction     = direction;
                command.Parameters.Add(param);
            }
            catch (Exception ex)
            {
                //Bubble error to caller and encapsulate Exception object
                throw new Exception("DataHandler::AddParameterToCommand::Error occured.", ex);
            }
        }
예제 #4
0
        /// <summary>
        /// Extension method that creates a C# signature for the tuple type.
        /// </summary>
        /// <param name="source">The target declaration syntax for a tuple.</param>
        /// <param name="manager">Optional parameter that contains all the using statements from the source code, when used will replace namespaces on type definition in code.</param>
        /// <returns>The formatted tuple or null if data is missing.</returns>
        public static string CSharpFormatTupleSignature(this CsType source, NamespaceManager manager = null)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsTuple)
            {
                return(null);
            }

            if (!source.TupleTypes.Any())
            {
                return(null);
            }

            StringBuilder tupleSignature = new StringBuilder(Symbols.ParametersDefinitionStart);

            int totalParameters  = source.TupleTypes.Count;
            int currentParameter = 0;

            foreach (var sourceParameter in source.TupleTypes)
            {
                currentParameter++;

                tupleSignature.Append(!sourceParameter.HasDefaultName
                    ? $"{sourceParameter.TupleType.CSharpFormatTypeName(manager)} {sourceParameter.Name} "
                    : sourceParameter.TupleType.CSharpFormatTypeName(manager));

                if (totalParameters > currentParameter)
                {
                    tupleSignature.Append(", ");
                }
            }

            tupleSignature.Append(Symbols.ParametersDefinitionEnd);

            return(tupleSignature.ToString());
        }
예제 #5
0
 public bool TryGetExport(CsType csType, out Export export)
 {
     return(exports.TryGetValue(csType, out export));
 }
예제 #6
0
        /// <summary>
        /// LUA结构支持
        /// </summary>
        /// <returns></returns>
        public override void GetLuaStruct(StringBuilder code)
        {
            base.GetLuaStruct(code);
            int idx;

            if (!string.IsNullOrWhiteSpace(PropertyName))
            {
                code.AppendLine($@"['PropertyName'] = '{PropertyName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['PropertyName'] = nil,");
            }

            code.AppendLine($@"['IsCaption'] ={(IsCaption.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Alias))
            {
                code.AppendLine($@"['Alias'] = '{Alias.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Alias'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Group))
            {
                code.AppendLine($@"['Group'] = '{Group.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Group'] = nil,");
            }

            code.AppendLine($@"['CreateIndex'] ={(CreateIndex.ToString().ToLower())},");

            code.AppendLine($@"['IsPrimaryKey'] ={(IsPrimaryKey.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendKey'] ={(IsExtendKey.ToString().ToLower())},");

            code.AppendLine($@"['IsIdentity'] ={(IsIdentity.ToString().ToLower())},");

            code.AppendLine($@"['IsGlobalKey'] ={(IsGlobalKey.ToString().ToLower())},");

            code.AppendLine($@"['UniqueIndex'] ={UniqueIndex},");

            code.AppendLine($@"['IsRequired'] ={(IsRequired.ToString().ToLower())},");

            code.AppendLine($@"['IsUserReadOnly'] ={(IsUserReadOnly.ToString().ToLower())},");

            code.AppendLine($@"['IsMemo'] ={(IsMemo.ToString().ToLower())},");


            code.AppendLine($@"['DenyClient'] ={(DenyClient.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Prefix))
            {
                code.AppendLine($@"['Prefix'] = '{Prefix.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Prefix'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Suffix))
            {
                code.AppendLine($@"['Suffix'] = '{Suffix.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Suffix'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(InputType))
            {
                code.AppendLine($@"['InputType'] = '{InputType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['InputType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ComboBoxUrl))
            {
                code.AppendLine($@"['ComboBoxUrl'] = '{ComboBoxUrl.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComboBoxUrl'] = nil,");
            }

            code.AppendLine($@"['IsMoney'] ={(IsMoney.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(GridAlign))
            {
                code.AppendLine($@"['GridAlign'] = '{GridAlign.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['GridAlign'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(DataFormater))
            {
                code.AppendLine($@"['DataFormater'] = '{DataFormater.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['DataFormater'] = nil,");
            }

            code.AppendLine($@"['DenyClient'] ={(DenyClient.ToString().ToLower())},");

            code.AppendLine($@"['GridDetails'] ={(GridDetails.ToString().ToLower())},");

            code.AppendLine($@"['NoneGrid'] ={(NoneGrid.ToString().ToLower())},");

            code.AppendLine($@"['NoneDetails'] ={(NoneDetails.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(GridDetailsCode))
            {
                code.AppendLine($@"['GridDetailsCode'] = '{GridDetailsCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['GridDetailsCode'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CppType))
            {
                code.AppendLine($@"['CppType'] = '{CppType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppType'] = nil,");
            }

            if (CppTypeObject != null)
            {
                code.AppendLine($@"['CppTypeObject'] ='{CppTypeObject}',");
            }

            if (!string.IsNullOrWhiteSpace(CppName))
            {
                code.AppendLine($@"['CppName'] = '{CppName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppName'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CppLastType))
            {
                code.AppendLine($@"['CppLastType'] = '{CppLastType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppLastType'] = nil,");
            }

            code.AppendLine($@"['IsIntDecimal'] ={(IsIntDecimal.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(CsType))
            {
                code.AppendLine($@"['CsType'] = '{CsType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CsType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CustomType))
            {
                code.AppendLine($@"['CustomType'] = '{CustomType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CustomType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(LastCsType))
            {
                code.AppendLine($@"['LastCsType'] = '{LastCsType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LastCsType'] = nil,");
            }

            if (EnumConfig != null)
            {
                code.AppendLine($@"['EnumConfig'] = {EnumConfig.GetLuaStruct()},");
            }

            code.AppendLine($@"['IsCompute'] ={(IsCompute.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ComputeGetCode))
            {
                code.AppendLine($@"['ComputeGetCode'] = '{ComputeGetCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComputeGetCode'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ComputeSetCode))
            {
                code.AppendLine($@"['ComputeSetCode'] = '{ComputeSetCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComputeSetCode'] = nil,");
            }

            code.AppendLine($@"['IsMiddleField'] ={(IsMiddleField.ToString().ToLower())},");

            code.AppendLine($@"['InnerField'] ={(InnerField.ToString().ToLower())},");

            code.AppendLine($@"['IsSystemField'] ={(IsSystemField.ToString().ToLower())},");

            code.AppendLine($@"['IsInterfaceField'] ={(IsInterfaceField.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Initialization))
            {
                code.AppendLine($@"['Initialization'] = '{Initialization.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Initialization'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(EmptyValue))
            {
                code.AppendLine($@"['EmptyValue'] = '{EmptyValue.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['EmptyValue'] = nil,");
            }

            code.AppendLine($@"['DenyScope'] ='{DenyScope}',");

            code.AppendLine($@"['Nullable'] ={(Nullable.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Max))
            {
                code.AppendLine($@"['Max'] = '{Max.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Max'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Min))
            {
                code.AppendLine($@"['Min'] = '{Min.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Min'] = nil,");
            }

            code.AppendLine($@"['UniqueString'] ={(UniqueString.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ColumnName))
            {
                code.AppendLine($@"['ColumnName'] = '{ColumnName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ColumnName'] = nil,");
            }

            code.AppendLine($@"['DbNullable'] ={(DbNullable.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(DbType))
            {
                code.AppendLine($@"['DbType'] = '{DbType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['DbType'] = nil,");
            }

            code.AppendLine($@"['Precision'] ={Datalen},");

            if (!string.IsNullOrWhiteSpace(ArrayLen))
            {
                code.AppendLine($@"['ArrayLen'] = '{ArrayLen.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ArrayLen'] = nil,");
            }

            code.AppendLine($@"['Scale'] ={Scale},");

            code.AppendLine($@"['DbIndex'] ={DbIndex},");

            code.AppendLine($@"['Unicode'] ={(Unicode.ToString().ToLower())},");

            code.AppendLine($@"['FixedLength'] ={(FixedLength.ToString().ToLower())},");

            code.AppendLine($@"['IsBlob'] ={(IsBlob.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(StorageProperty))
            {
                code.AppendLine($@"['StorageProperty'] = '{StorageProperty.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['StorageProperty'] = nil,");
            }

            code.AppendLine($@"['DbInnerField'] ={(DbInnerField.ToString().ToLower())},");

            code.AppendLine($@"['NoStorage'] ={(NoStorage.ToString().ToLower())},");

            code.AppendLine($@"['KeepStorageScreen'] ='{KeepStorageScreen}',");

            code.AppendLine($@"['CustomWrite'] ={(CustomWrite.ToString().ToLower())},");

            code.AppendLine($@"['IsLinkField'] ={(IsLinkField.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(LinkTable))
            {
                code.AppendLine($@"['LinkTable'] = '{LinkTable.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LinkTable'] = nil,");
            }

            code.AppendLine($@"['IsLinkKey'] ={(IsLinkKey.ToString().ToLower())},");

            code.AppendLine($@"['IsLinkCaption'] ={(IsLinkCaption.ToString().ToLower())},");

            code.AppendLine($@"['IsUserId'] ={(IsUserId.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(LinkField))
            {
                code.AppendLine($@"['LinkField'] = '{LinkField.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LinkField'] = nil,");
            }

            code.AppendLine($@"['IsCustomCompute'] ={(IsCustomCompute.ToString().ToLower())},");

            code.AppendLine($@"['CanGet'] ={(CanGet.ToString().ToLower())},");

            code.AppendLine($@"['CanSet'] ={(CanSet.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(AccessType))
            {
                code.AppendLine($@"['AccessType'] = '{AccessType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['AccessType'] = nil,");
            }

            code.AppendLine($@"['ReadOnly'] ={(ReadOnly.ToString().ToLower())},");

            code.AppendLine($@"['CanInput'] ={(CanUserInput.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ExtendRole))
            {
                code.AppendLine($@"['ExtendRole'] = '{ExtendRole.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendRole'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ValueSeparate))
            {
                code.AppendLine($@"['ValueSeparate'] = '{ValueSeparate.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ValueSeparate'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ArraySeparate))
            {
                code.AppendLine($@"['ArraySeparate'] = '{ArraySeparate.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ArraySeparate'] = nil,");
            }

            code.AppendLine($@"['ExtendArray'] ={(ExtendArray.ToString().ToLower())},");

            code.AppendLine($@"['IsKeyValueArray'] ={(IsKeyValueArray.ToString().ToLower())},");

            code.AppendLine($@"['IsRelation'] ={(IsRelation.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ExtendPropertyName))
            {
                code.AppendLine($@"['ExtendPropertyName'] = '{ExtendPropertyName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendPropertyName'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ExtendClassName))
            {
                code.AppendLine($@"['ExtendClassName'] = '{ExtendClassName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendClassName'] = nil,");
            }

            code.AppendLine($@"['ExtendClassIsPredestinate'] ={(ExtendClassIsPredestinate.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationField'] ={(IsRelationField.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationValue'] ={(IsRelationValue.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationArray'] ={(IsRelationArray.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendArray'] ={(IsExtendArray.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendValue'] ={(IsExtendValue.ToString().ToLower())},");
        }
예제 #7
0
 public static TsType From(CsType csType,
                           bool forceNullable = false)
 {
     return(From(csType.OriginalType, forceNullable));
 }
        /// <summary>
        /// Extension method that generates the default value syntax for a parameter in the C# language.
        /// </summary>
        /// <param name="source">The target default value to format.</param>
        /// <param name="type">The target type of the value to be formatted.</param>
        /// <returns>The fully formatted syntax for the default value or null if data was missing.</returns>
        public static string CSharpFormatParameterDefaultValue(this CsParameterDefaultValue source, CsType type)
        {
            if (source == null)
            {
                return(null);
            }
            if (type == null)
            {
                return(null);
            }

            string result = null;

            switch (source.ValueType)
            {
            case ParameterDefaultValueType.Value:

                result = type.CSharpFormatValueSyntax(source.Value);
                break;

            case ParameterDefaultValueType.DefaultKeyWord:

                result = Keywords.Default;
                break;

            case ParameterDefaultValueType.NullKeyword:

                result = Keywords.Null;
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
예제 #9
0
        /// <summary>
        /// Extension method that returns a value declaration in the C# language format.
        /// </summary>
        /// <param name="source">The target type to create the value definition for.</param>
        /// <param name="value">The value to be formatted.</param>
        /// <returns>The definition of the value formatted for C#</returns>
        public static string CSharpFormatValueSyntax(this CsType source, string value)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsLoaded)
            {
                return(null);
            }

            if (source.Name == "Type" & source.Namespace == "System")
            {
                return($"typeof({value})");
            }

            if (source.IsEnum)
            {
                try
                {
                    var enumData = source.GetEnumModel();


                    return(enumData?.CSharpFormatEnumValue(value));
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            if (!source.IsWellKnownType)
            {
                return(value);
            }

            string result = null;

            switch (source.WellKnownType)
            {
            case CsKnownLanguageType.Void:

                result = Keywords.Void;

                break;

            case CsKnownLanguageType.Boolean:

                result = value.ToLower();
                break;

            case CsKnownLanguageType.Character:
                result = $"'{value}'";
                break;

            case CsKnownLanguageType.String:
                result = $"\"{value}\"";
                break;

            default:
                result = value;
                break;
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Formats a type name to match the C# syntax for a type deceleration in C#.
        /// </summary>
        /// <param name="source">The type model to use to generate the type signature for c#</param>
        /// <param name="manager">Optional parameter that contains all the using statements from the source code, when used will replace namespaces on type definition in code.</param>
        /// <returns>The formatted type definition for C#</returns>
        public static string CSharpFormatTypeName(this CsType source, NamespaceManager manager = null)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsLoaded)
            {
                return(null);
            }

            var namespaceManager = manager ?? new NamespaceManager(null);

            string returnValue = null;

            string typeName = null;

            if (source.IsWellKnownType)
            {
                switch (source.WellKnownType)
                {
                case CsKnownLanguageType.NotWellKnown:
                    typeName = null;
                    break;

                case CsKnownLanguageType.Object:
                    typeName = WellKnownTypes.Object;
                    break;

                case CsKnownLanguageType.Void:
                    typeName = Keywords.Void;
                    break;

                case CsKnownLanguageType.Boolean:
                    typeName = WellKnownTypes.Boolean;
                    break;

                case CsKnownLanguageType.Character:
                    typeName = WellKnownTypes.Character;
                    break;

                case CsKnownLanguageType.Signed8BitInteger:
                    typeName = WellKnownTypes.SByte;
                    break;

                case CsKnownLanguageType.UnSigned8BitInteger:
                    typeName = WellKnownTypes.Byte;
                    break;

                case CsKnownLanguageType.Signed16BitInteger:
                    typeName = WellKnownTypes.Short;
                    break;

                case CsKnownLanguageType.Unsigned16BitInteger:
                    typeName = WellKnownTypes.Ushort;
                    break;

                case CsKnownLanguageType.Signed32BitInteger:
                    typeName = WellKnownTypes.Int;
                    break;

                case CsKnownLanguageType.Unsigned32BitInteger:
                    typeName = WellKnownTypes.Uint;
                    break;

                case CsKnownLanguageType.Signed64BitInteger:
                    typeName = WellKnownTypes.Long;
                    break;

                case CsKnownLanguageType.Unsigned64BitInteger:
                    typeName = WellKnownTypes.Ulong;
                    break;

                case CsKnownLanguageType.Decimal:
                    typeName = WellKnownTypes.Decimal;
                    break;

                case CsKnownLanguageType.Single:
                    typeName = WellKnownTypes.Float;
                    break;

                case CsKnownLanguageType.Double:
                    typeName = WellKnownTypes.Double;
                    break;

                case CsKnownLanguageType.Pointer:
                    typeName = WellKnownTypes.Pointer;
                    break;

                case CsKnownLanguageType.PlatformPointer:
                    typeName = WellKnownTypes.PlatformPointer;
                    break;

                case CsKnownLanguageType.DateTime:
                    typeName = WellKnownTypes.Datetime;
                    break;

                case CsKnownLanguageType.String:
                    typeName = WellKnownTypes.String;
                    break;

                default:
                    typeName = null;
                    break;
                }
            }
            else
            {
                var targetNamespace = namespaceManager.AppendingNamespace(source.Namespace);

                typeName = targetNamespace == null ? source.Name : $"{targetNamespace}.{source.Name}";
            }

            returnValue = typeName;

            if (source.IsGeneric)
            {
                returnValue = $"{typeName}{source.GenericParameters.CSharpFormatGenericParametersSignature(namespaceManager)}";
            }
            if (source.IsArray)
            {
                returnValue = $"{typeName}{source.CSharpFormatArraySignature()}";
            }
            if (source.IsTuple)
            {
                returnValue = source.CSharpFormatTupleSignature(namespaceManager);
            }
            return(returnValue);
        }