Beispiel #1
0
        public SerializationAssemblyMetadata(IAssemblyMetadata assemblyMetadata)
        {
            Name      = assemblyMetadata.Name;
            SavedHash = assemblyMetadata.SavedHash;
            List <INamespaceMetadata> namespaces = new List <INamespaceMetadata>();

            foreach (INamespaceMetadata child in assemblyMetadata.Namespaces)
            {
                if (AlreadyMapped.TryGetValue(child.SavedHash, out IMetadata item))
                {
                    namespaces.Add(item as INamespaceMetadata);
                }
                else
                {
                    INamespaceMetadata newNamespace = new SerializationNamespaceMetadata(child);
                    namespaces.Add(newNamespace);
                    AlreadyMapped.Add(newNamespace.SavedHash, newNamespace);
                }
            }

            Namespaces = namespaces;
            foreach (INamespaceMetadata _namespace in Namespaces)
            {
                foreach (ITypeMetadata type in _namespace.Types)
                {
                    type.MapTypes();
                }
            }
        }
        public SerializationNamespaceMetadata(INamespaceMetadata namespaceMetadata)
        {
            Name      = namespaceMetadata.Name;
            SavedHash = namespaceMetadata.SavedHash;
            List <ITypeMetadata> types = new List <ITypeMetadata>();

            foreach (ITypeMetadata child in namespaceMetadata.Types)
            {
                if (AlreadyMapped.TryGetValue(child.SavedHash, out IMetadata item))
                {
                    types.Add(item as ITypeMetadata);
                }
                else
                {
                    ITypeMetadata newType = new SerializationTypeMetadata(child);
                    types.Add(newType);
                    AlreadyMapped.Add(newType.SavedHash, newType);
                }
            }

            Types = types;
        }
Beispiel #3
0
        public void MapTypes()
        {
            if (ReturnType != null)
            {
                if (AlreadyMapped.TryGetValue(
                        ReturnType.SavedHash, out IMetadata item))
                {
                    ReturnType = item as ITypeMetadata;
                }
                else
                {
                    AlreadyMapped.Add(ReturnType.SavedHash, ReturnType);
                }
            }

            if (GenericArguments != null)
            {
                ICollection <ITypeMetadata> actualGenericArguments = new List <ITypeMetadata>();
                foreach (ITypeMetadata type in GenericArguments)
                {
                    if (AlreadyMapped.TryGetValue(type.SavedHash, out IMetadata item))
                    {
                        actualGenericArguments.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        actualGenericArguments.Add(type);
                        AlreadyMapped.Add(type.SavedHash, type);
                    }
                }
                GenericArguments = actualGenericArguments;
            }
            foreach (IParameterMetadata parameter in Parameters)
            {
                parameter.MapTypes();
            }
        }
Beispiel #4
0
        public MethodMetadata(IMethodMetadata methodMetadata)
        {
            Name        = methodMetadata.Name;
            SavedHash   = methodMetadata.SavedHash;
            IsExtension = methodMetadata.IsExtension;
            Modifiers   = methodMetadata.Modifiers;

            // Generic Arguments
            if (methodMetadata.GenericArguments is null)
            {
                GenericArguments = null;
            }
            else
            {
                List <ITypeMetadata> genericArguments = new List <ITypeMetadata>();
                foreach (ITypeMetadata genericArgument in methodMetadata.GenericArguments)
                {
                    if (AlreadyMapped.TryGetValue(genericArgument.SavedHash, out IMetadata mappedArgument))
                    {
                        genericArguments.Add(mappedArgument as ITypeMetadata);
                    }
                    else
                    {
                        genericArguments.Add(new TypeMetadata(genericArgument.SavedHash, genericArgument.Name));
                    }
                }

                GenericArguments = genericArguments;
            }

            // Return type
            if (methodMetadata.ReturnType is null)
            {
                ReturnType = null;
            }
            else if (AlreadyMapped.TryGetValue(methodMetadata.ReturnType.SavedHash, out IMetadata item))
            {
                ReturnType = item as ITypeMetadata;
            }
            else
            {
                ReturnType = new TypeMetadata(methodMetadata.ReturnType.SavedHash, methodMetadata.ReturnType.Name);
            }

            // Parameters
            if (methodMetadata.Parameters is null)
            {
                Parameters = Enumerable.Empty <IParameterMetadata>();
            }
            else
            {
                List <IParameterMetadata> parameters = new List <IParameterMetadata>();
                foreach (IParameterMetadata parameter in methodMetadata.Parameters)
                {
                    if (AlreadyMapped.TryGetValue(parameter.SavedHash, out IMetadata item))
                    {
                        parameters.Add(item as IParameterMetadata);
                    }
                    else
                    {
                        IParameterMetadata newParameter = new ParameterMetadata(parameter);
                        parameters.Add(newParameter);
                        AlreadyMapped.Add(newParameter.SavedHash, newParameter);
                    }
                }

                Parameters = parameters;
            }

            FillChildren(new StreamingContext());
        }
        public SerializationMethodMetadata(IMethodMetadata methodMetadata)
        {
            Name        = methodMetadata.Name;
            SavedHash   = methodMetadata.SavedHash;
            IsExtension = methodMetadata.IsExtension;
            Modifiers   = methodMetadata.Modifiers;

            // Generic Arguments
            if (methodMetadata.GenericArguments is null)
            {
                GenericArguments = null;
            }
            else
            {
                List <ITypeMetadata> genericArguments = new List <ITypeMetadata>();
                foreach (ITypeMetadata genericArgument in methodMetadata.GenericArguments)
                {
                    if (AlreadyMapped.TryGetValue(genericArgument.SavedHash, out IMetadata mappedArgument))
                    {
                        genericArguments.Add(mappedArgument as ITypeMetadata);
                    }
                    else
                    {
                        // use temporary constructor to save its hash, retrieve actual object afterr all mapping has been done
                        genericArguments.Add(new SerializationTypeMetadata(
                                                 new SerializationTypeMetadata(genericArgument.SavedHash, genericArgument.Name)));
                    }
                }

                GenericArguments = genericArguments;
            }

            // Return type
            if (AlreadyMapped.TryGetValue(methodMetadata.ReturnType.SavedHash, out IMetadata item))
            {
                ReturnType = item as ITypeMetadata;
            }
            else
            {
                // use temporary constructor to save its hash, retrieve actual object afterr all mapping has been done
                ReturnType = new SerializationTypeMetadata(
                    new SerializationTypeMetadata(methodMetadata.ReturnType.SavedHash, methodMetadata.ReturnType.Name));
            }

            // Parameters
            if (methodMetadata.Parameters is null)
            {
                Parameters = Enumerable.Empty <IParameterMetadata>();
            }
            else
            {
                List <IParameterMetadata> parameters = new List <IParameterMetadata>();
                foreach (IParameterMetadata parameter in methodMetadata.Parameters)
                {
                    if (AlreadyMapped.TryGetValue(parameter.SavedHash, out item))
                    {
                        parameters.Add(item as IParameterMetadata);
                    }
                    else
                    {
                        IParameterMetadata newParameter = new SerializationParameterMetadata(parameter);
                        parameters.Add(newParameter);
                        AlreadyMapped.Add(newParameter.SavedHash, newParameter);
                    }
                }

                Parameters = parameters;
            }

            FillChildren(new StreamingContext());
        }
        public SerializationTypeMetadata(ITypeMetadata typeMetadata)
        {
            Name          = typeMetadata.Name;
            SavedHash     = typeMetadata.SavedHash;
            NamespaceName = typeMetadata.NamespaceName;

            // Base type
            if (typeMetadata.BaseType is null)
            {
                BaseType = null;
            }
            else if (AlreadyMapped.TryGetValue(typeMetadata.BaseType.SavedHash, out IMetadata item))
            {
                BaseType = item as ITypeMetadata;
            }
            else
            {
                BaseType = new SerializationTypeMetadata(
                    new SerializationTypeMetadata(typeMetadata.BaseType.SavedHash, typeMetadata.BaseType.Name));
            }

            // Generic Arguments
            if (typeMetadata.GenericArguments is null)
            {
                GenericArguments = null;
            }
            else
            {
                List <ITypeMetadata> genericArguments = new List <ITypeMetadata>();
                foreach (ITypeMetadata genericArgument in typeMetadata.GenericArguments)
                {
                    if (AlreadyMapped.TryGetValue(genericArgument.SavedHash, out IMetadata item))
                    {
                        genericArguments.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        genericArguments.Add(new SerializationTypeMetadata(
                                                 new SerializationTypeMetadata(genericArgument.SavedHash, genericArgument.Name)));
                    }
                }

                GenericArguments = genericArguments;
            }

            // Modifiers
            Modifiers = typeMetadata.Modifiers;

            // Type kind
            TypeKind = typeMetadata.TypeKind;

            // Attributes
            if (typeMetadata.Attributes is null)
            {
                Attributes = Enumerable.Empty <IAttributeMetadata>();
            }
            else
            {
                List <IAttributeMetadata> attributes = new List <IAttributeMetadata>();
                foreach (IAttributeMetadata attribute in typeMetadata.Attributes)
                {
                    if (AlreadyMapped.TryGetValue(attribute.SavedHash, out IMetadata item))
                    {
                        attributes.Add(item as IAttributeMetadata);
                    }
                    else
                    {
                        IAttributeMetadata newAttribute = new SerializationAttributeMetadata(attribute);
                        attributes.Add(newAttribute);
                        AlreadyMapped.Add(newAttribute.SavedHash, newAttribute);
                    }
                }

                Attributes = attributes;
            }

            // Interfaces
            if (typeMetadata.ImplementedInterfaces is null)
            {
                ImplementedInterfaces = Enumerable.Empty <ITypeMetadata>();
            }
            else
            {
                List <ITypeMetadata> interfaces = new List <ITypeMetadata>();
                foreach (ITypeMetadata implementedInterface in typeMetadata.ImplementedInterfaces)
                {
                    if (AlreadyMapped.TryGetValue(implementedInterface.SavedHash, out IMetadata item))
                    {
                        interfaces.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        interfaces.Add(new SerializationTypeMetadata(
                                           new SerializationTypeMetadata(implementedInterface.SavedHash, implementedInterface.Name)));
                    }
                }

                ImplementedInterfaces = interfaces;
            }

            // Nested Types
            if (typeMetadata.NestedTypes is null)
            {
                NestedTypes = null;
            }
            else
            {
                List <ITypeMetadata> nestedTypes = new List <ITypeMetadata>();
                foreach (ITypeMetadata nestedType in typeMetadata.NestedTypes)
                {
                    if (AlreadyMapped.TryGetValue(nestedType.SavedHash, out IMetadata item))
                    {
                        nestedTypes.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        nestedTypes.Add(new SerializationTypeMetadata(
                                            new SerializationTypeMetadata(nestedType.SavedHash, nestedType.Name)));
                    }
                }

                NestedTypes = nestedTypes;
            }

            // Properties
            if (typeMetadata.Properties is null)
            {
                Properties = Enumerable.Empty <IPropertyMetadata>();
            }
            else
            {
                List <IPropertyMetadata> properties = new List <IPropertyMetadata>();
                foreach (IPropertyMetadata property in typeMetadata.Properties)
                {
                    if (AlreadyMapped.TryGetValue(property.SavedHash, out IMetadata item))
                    {
                        properties.Add(item as IPropertyMetadata);
                    }
                    else
                    {
                        IPropertyMetadata newProperty = new SerializationPropertyMetadata(property);
                        properties.Add(newProperty);
                        AlreadyMapped.Add(newProperty.SavedHash, newProperty);
                    }
                }

                Properties = properties;
            }

            //Declaring type
            if (typeMetadata.DeclaringType is null)
            {
                DeclaringType = null;
            }
            else if (AlreadyMapped.TryGetValue(typeMetadata.DeclaringType.SavedHash, out IMetadata item))
            {
                DeclaringType = item as ITypeMetadata;
            }
            else
            {
                DeclaringType = new SerializationTypeMetadata(
                    new SerializationTypeMetadata(typeMetadata.DeclaringType.SavedHash, typeMetadata.DeclaringType.Name));
            }

            // Methods
            if (typeMetadata.Methods is null)
            {
                Methods = Enumerable.Empty <IMethodMetadata>();
            }
            else
            {
                List <IMethodMetadata> methods = new List <IMethodMetadata>();
                foreach (IMethodMetadata method in typeMetadata.Methods)
                {
                    if (AlreadyMapped.TryGetValue(method.SavedHash, out IMetadata item))
                    {
                        methods.Add(item as IMethodMetadata);
                    }
                    else
                    {
                        IMethodMetadata newMethod = new SerializationMethodMetadata(method);
                        methods.Add(newMethod);
                        AlreadyMapped.Add(newMethod.SavedHash, newMethod);
                    }
                }

                Methods = methods;
            }

            // Constructors
            if (typeMetadata.Methods is null)
            {
                Constructors = Enumerable.Empty <IMethodMetadata>();
            }
            else
            {
                List <IMethodMetadata> constructors = new List <IMethodMetadata>();
                foreach (IMethodMetadata constructor in typeMetadata.Methods)
                {
                    if (AlreadyMapped.TryGetValue(constructor.SavedHash, out IMetadata item))
                    {
                        constructors.Add(item as IMethodMetadata);
                    }
                    else
                    {
                        IMethodMetadata newMethod = new SerializationMethodMetadata(constructor);
                        constructors.Add(newMethod);
                        AlreadyMapped.Add(newMethod.SavedHash, newMethod);
                    }
                }

                Constructors = constructors;
            }

            FillChildren(new StreamingContext());
        }
Beispiel #7
0
        public void MapTypes()
        {
            IMetadata item;

            if (BaseType != null && AlreadyMapped.TryGetValue(
                    BaseType.SavedHash, out item))
            {
                BaseType = item as ITypeMetadata;
            }
            if (DeclaringType != null &&
                AlreadyMapped.TryGetValue(DeclaringType.SavedHash, out item))
            {
                DeclaringType = item as ITypeMetadata;
            }
            if (GenericArguments != null)
            {
                ICollection <ITypeMetadata> actualGenericArguments = new List <ITypeMetadata>();
                foreach (ITypeMetadata type in GenericArguments)
                {
                    if (AlreadyMapped.TryGetValue(type.SavedHash, out item))
                    {
                        actualGenericArguments.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        actualGenericArguments.Add(type);
                        AlreadyMapped.Add(type.SavedHash, type);
                    }
                }
                GenericArguments = actualGenericArguments;
            }
            if (ImplementedInterfaces != null)
            {
                ICollection <ITypeMetadata> actualImplementedInterfaces = new List <ITypeMetadata>();
                foreach (ITypeMetadata type in ImplementedInterfaces)
                {
                    if (AlreadyMapped.TryGetValue(type.SavedHash, out item))
                    {
                        actualImplementedInterfaces.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        actualImplementedInterfaces.Add(type);
                        AlreadyMapped.Add(type.SavedHash, type);
                    }
                }
                ImplementedInterfaces = actualImplementedInterfaces;
            }

            if (NestedTypes != null)
            {
                ICollection <ITypeMetadata> actualNestedTypes = new List <ITypeMetadata>();
                foreach (ITypeMetadata type in NestedTypes)
                {
                    if (AlreadyMapped.TryGetValue(type.SavedHash, out item))
                    {
                        actualNestedTypes.Add(item as ITypeMetadata);
                    }
                    else
                    {
                        actualNestedTypes.Add(type);
                        AlreadyMapped.Add(type.SavedHash, type);
                    }
                }
                NestedTypes = actualNestedTypes;
            }

            foreach (IMethodMetadata method in Methods)
            {
                method.MapTypes();
            }
            foreach (IMethodMetadata method in Constructors)
            {
                method.MapTypes();
            }
            foreach (IPropertyMetadata property in Properties)
            {
                property.MapTypes();
            }
        }