Exemplo n.º 1
0
        public static GhostComponentAttribute GetGhostComponentAttribute(Mono.Cecil.TypeDefinition managedType)
        {
            var attribute = managedType.GetAttribute <GhostComponentAttribute>();

            if (attribute != null)
            {
                var ghostAttribute = new GhostComponentAttribute();
                if (attribute.HasProperties)
                {
                    foreach (var a in attribute.Properties)
                    {
                        typeof(GhostComponentAttribute).GetProperty(a.Name)?.SetValue(ghostAttribute, a.Argument.Value);
                    }
                }

                return(ghostAttribute);
            }

            return(null);
        }
        void GenerateType(Context context, Mono.Cecil.TypeDefinition type)
        {
            TypeInformation typeTree;

            Mono.Cecil.TypeDefinition componentType;
            GhostComponentAttribute   ghostAttribute;
            var variantAttr = type.GetAttribute <GhostComponentVariationAttribute>();

            if (variantAttr != null)
            {
                ghostAttribute      = CecilExtensions.GetGhostComponentAttribute(type);
                context.VariantHash = CecilExtensions.ComputeVariantHash(type, variantAttr);
                var typeReference = variantAttr.ConstructorArguments.First().Value as Mono.Cecil.TypeReference;
                typeTree      = ParseVariantTypeFields(type, typeReference);
                componentType = typeReference.Resolve();
            }
            else
            {
                if (GhostAuthoringModifiers.GhostDefaultOverrides.TryGetValue(type.FullName.Replace('/', '+'), out var newComponent))
                {
                    ghostAttribute = newComponent.attribute;
                }
                else
                {
                    ghostAttribute = CecilExtensions.GetGhostComponentAttribute(type);
                }
                typeTree      = ParseTypeFields(type);
                componentType = type;
            }

            var generator = InternalGenerateType(context, typeTree, type.FullName);

            generator.GenerateMasks(context);

            var serializeGenerator = new TypeGenerator(context);

            generator.AppendTarget(serializeGenerator);
            serializeGenerator.GenerateSerializer(context, type, componentType, ghostAttribute);
        }
Exemplo n.º 3
0
        public static GhostComponentAttribute GetGhostComponentAttribute(Mono.Cecil.TypeDefinition managedType)
        {
            if (GhostAuthoringComponentEditor.GhostDefaultOverrides.TryGetValue(managedType.FullName.Replace('/', '+'), out var newComponent))
            {
                return(newComponent.attribute);
            }
            var attribute = managedType.GetAttribute <GhostComponentAttribute>();

            if (attribute != null)
            {
                var ghostAttribute = new GhostComponentAttribute();
                if (attribute.HasProperties)
                {
                    foreach (var a in attribute.Properties)
                    {
                        typeof(GhostComponentAttribute).GetProperty(a.Name)?.SetValue(ghostAttribute, a.Argument.Value);
                    }
                }

                return(ghostAttribute);
            }

            return(null);
        }