Ejemplo n.º 1
0
        public static void RegisterType(string name, DataType type)
        {
            var hash = StringHasher.GetHash(name);

            if (!m_userTypes.ContainsKey(hash))
            {
                m_userTypes.Add(hash, type);
            }
        }
Ejemplo n.º 2
0
 private void AddAdditionalTypesAsKnown(params Tuple <Type, TsPrimitive>[] typesToBeAdded)
 {
     foreach (var type in typesToBeAdded)
     {
         var typeByMetadata = _compilation.GetTypeByMetadataName(type.Item1.FullName);
         if (typeByMetadata != null)
         {
             TypeLookup.Add(typeByMetadata, type.Item2);
         }
     }
 }
Ejemplo n.º 3
0
        public static ModelType GetForType(Type objectType)
        {
            if (TypeLookup.TryGetValue(objectType, out var modelType))
            {
                return(modelType);
            }

            var possible = from type in ModelTypes
                           let score = type.GetRelation(objectType)
                                       where score.HasValue
                                       orderby score ascending
                                       select type;

            modelType = possible.FirstOrDefault();

            TypeLookup.Add(objectType, modelType);

            return(modelType);
        }
Ejemplo n.º 4
0
        private static bool RegisterTypeToLookup(TypeLookup lookup, string name, int hash, DataType type)
        {
            if (name != null)
            {
                if (hash != -1)
                {
                    // add manual lookup
                    StringHasher.AddToLookup(hash, name);
                }
                else
                {
                    hash = StringHasher.GetHash(name);

                    // try adding this to the lookup
                    if (!StringHasher.CanResolveHash(hash))
                    {
                        Debug.WriteLine($"- Adding '{name}' to lookup");
                        StringHasher.AddToLookup(name);
                    }
                }

                if (!lookup.ContainsKey(hash))
                {
                    lookup.Add(hash, type);
                }

                var id       = name;
                var parentId = "";

                var splitIdx = name.LastIndexOf('.');

                if (splitIdx != -1)
                {
                    parentId = name.Substring(0, splitIdx);
                    id       = name.Substring(splitIdx + 1);

                    StringHasher.AddToLookup(parentId);
                    StringHasher.AddToLookup(id);
                }

                // auto-register accompanying "text_*" string
                if ((type == DataType.StringId) || (type == DataType.PathId))
                {
                    id = $"text_{id}";

                    if (!String.IsNullOrEmpty(parentId))
                    {
                        id = $"{parentId}.{id}";
                    }

                    RegisterTypeToLookup(lookup, id, -1, DataType.String);
                }
            }
            else
            {
                // empty attribute!?
                if (hash == -1)
                {
                    return(false);
                }

                //--var canResolve = StringHasher.CanResolveHash(hash);
                //--
                //--name = (canResolve)
                //--    ? StringHasher.ResolveHash(hash)
                //--    : $"_{hash:X8}";
                //--
                //--if (canResolve)
                //--{
                //--    if (IsTypeKnown(hash))
                //--    {
                //--        var knownType = GetType(hash);
                //--
                //--        //WriteUniqueHint($"<!-- Remove: --><Attribute Hash=\"{attrHash:X8}\" Type=\"{attrType.ToString()}\" /><!-- SameAs --><Attribute Name=\"{name}\" Type=\"{knownType.ToString()}\" />");
                //--    }
                //--    else
                //--    {
                //--        //WriteUniqueHint($"<!-- Rename: --><Attribute Hash=\"{attrHash:X8}\" Type=\"{attrType.ToString()}\" /><!-- EqualTo --><Attribute Name=\"{name}\" Type=\"{attrType.ToString()}\" />");
                //--    }
                //--}

                if (!lookup.ContainsKey(hash))
                {
                    lookup.Add(hash, type);
                }
            }

            return(true);
        }