Exemplo n.º 1
0
        private string CreateDbSetType(EntityDefinition entityDef, DbSetInfo dbSetInfo, DotNet2TS dotNet2TS)
        {
            StringBuilder      sb          = new StringBuilder(512);
            string             dbSetType   = GetDbSetTypeName(dbSetInfo.dbSetName);
            List <Association> childAssoc  = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList();
            List <Association> parentAssoc = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList();
            FieldsList         fieldInfos  = dbSetInfo.fieldInfos;

            Field[] pkFields = dbSetInfo.GetPKFields();
            string  pkVals   = "";

            foreach (Field pkField in pkFields)
            {
                if (!string.IsNullOrEmpty(pkVals))
                {
                    pkVals += ", ";
                }

                pkVals += pkField.fieldName.ToCamelCase() + ": " + GetFieldDataType(pkField);
            }
            Dictionary <string, Func <TemplateParser.Context, string> > dic = new Dictionary <string, Func <TemplateParser.Context, string> >
            {
                { "DBSET_NAME", (context) => dbSetInfo.dbSetName },
                { "DBSET_TYPE", (context) => dbSetType },
                { "ENTITY_NAME", (context) => entityDef.entityName },
                { "ASPECT_NAME", (context) => entityDef.aspectName },
                { "INTERFACE_NAME", (context) => entityDef.interfaceName },
                { "VALS_NAME", (context) => entityDef.valsName },
                {
                    "DBSET_INFO",
                    (context) =>
                    {
                        //we are making copy of the object, in order that we don't change original object
                        //while it can be accessed by other threads
                        //we change our own copy, making it threadsafe
                        DbSetInfo copy = dbSetInfo.ShallowCopy();
                        copy.SetFieldInfos(new FieldsList()); //serialze with empty field infos
                        return(_serializer.Serialize(copy));
                    }
                },
                { "FIELD_INFOS", (context) => _serializer.Serialize(dbSetInfo.fieldInfos) },
                { "CHILD_ASSOC", (context) => _serializer.Serialize(childAssoc) },
                { "PARENT_ASSOC", (context) => _serializer.Serialize(parentAssoc) },
                { "QUERIES", (context) => CreateDbSetQueries(dbSetInfo, dotNet2TS) },
                { "CALC_FIELDS", (context) => CreateCalcFields(dbSetInfo) },
                { "PK_VALS", (context) => pkVals }
            };

            return(_dbSetTemplate.ToString(dic));
        }