Esempio n. 1
0
 public SerializationPropertyMetadata(IPropertyMetadata propertyMetadata)
 {
     Name      = propertyMetadata.Name;
     SavedHash = propertyMetadata.SavedHash;
     if (AlreadyMapped.TryGetValue(propertyMetadata.MyType.SavedHash, out IMetadata item))
     {
         MyType = item as ITypeMetadata;
     }
     else
     {
         // use temporary constructor to save its hash, retrieve actual object afterr all mapping has been done
         MyType = new SerializationTypeMetadata(
             new SerializationTypeMetadata(
                 propertyMetadata.MyType.SavedHash, propertyMetadata.MyType.Name));
     }
 }
        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;
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        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());
        }