Пример #1
0
        static ITypeContainer CreateABinaryContainerGeneric(
            Type SourceObjectType, byte[] SerializedObject)
        {
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(SourceObjectType, out g))
            {
                Type[] typeArgs = { SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(SourceObjectType, g);
            }
            object o = Activator.CreateInstance(g, SerializedObject);

            return(o as ITypeContainer);
        }
        static ITypeContainer CreateATypeContainerGeneric(
            Type SourceObjectType)
        {
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(SourceObjectType, out g))
            {
                Type[] typeArgs = { SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(SourceObjectType, g);
            }
            object o = Activator.CreateInstance(g, SourceObjectType.AssemblyQualifiedName);

            return(o as ITypeContainer);
        }
Пример #3
0
        static ITypeContainer CreateATypeConverterContainerGeneric(
            Type SourceObjectType, Type SerializationType, object SerializedObject)
        {
            KeyValuePair <Type, Type> k = new KeyValuePair <Type, Type>(SerializationType, SourceObjectType);
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(k, out g))
            {
                Type[] typeArgs = { SerializationType, SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(k, g);
            }
            object o = Activator.CreateInstance(g, SerializedObject);

            return(o as ITypeContainer);
        }
Пример #4
0
        static ITypeContainer CreateABinaryContainerGeneric(
            Type SourceObjectType, object ContainedObject)
        {
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(SourceObjectType, out g))
            {
                Type[] typeArgs = { SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(SourceObjectType, g);
            }
            object o;

            if (ContainedObject == null)
            {
                o = Activator.CreateInstance(g);
            }
            else
            {
                o = Activator.CreateInstance(g, ContainedObject);
            }
            return(o as ITypeContainer);
        }