Esempio n. 1
0
        public bool TryGetByKey(DurableTypeKey key, out Type type)
        {
            lock (_byKey)
            {
                type = _byKey.TryGetValue(key, out var durableType) ? durableType.DeclaredType : null;

                return(type != null);
            }
        }
Esempio n. 2
0
        //
        // Details
        //

        static bool TryGetKey(Type declaredType, out DurableTypeKey key)
        {
            var value =
                declaredType.GetCustomAttribute <DurablePrefixAttribute>()?.Prefix
                ?? declaredType.Assembly.GetCustomAttribute <DurablePrefixAttribute>()?.Prefix
                ?? "";

            key = DurablePrefix.TryFrom(value, out var prefix)
        ? DurableTypeKey.From(prefix, TypeName.From(declaredType))
        : null;

            return(key != null);
        }
        public override Type BindToType(string assemblyName, string typeName)
        {
            if (typeName.StartsWith(_prefix))
            {
                var key = typeName.Substring(_prefix.Length);

                if (DurableTypeKey.TryFrom(key, out var parsedKey) && _durableTypes.TryGetByKey(parsedKey, out var type))
                {
                    return(type);
                }
            }

            return(TypeResolver.Resolve(typeName, assemblyName));
        }
Esempio n. 4
0
 public DurableType(DurableTypeKey key, Type declaredType)
 {
     Key          = key;
     DeclaredType = declaredType;
 }
Esempio n. 5
0
 static DurableType CreateType(DurablePrefix prefix, Type declaredType) =>
 new DurableType(
     DurableTypeKey.From(prefix, TypeName.From(declaredType)),
     declaredType);
Esempio n. 6
0
        public bool TryGetKey(Type type, out DurableTypeKey key)
        {
            key = TryGetOrAdd(type, out var durableType) ? durableType.Key : null;

            return(key != null);
        }