Exemple #1
0
        private void ReadOptimizedStaticResource()
        {
            var node = new BamlOptimizedStaticResource();

            node.Flags = (BamlOptimizedStaticResourceFlags)_accessor.ReadByte();

            short valueId = _accessor.ReadInt16();

            BamlExtensionValue value;

            switch (node.Flags)
            {
            case BamlOptimizedStaticResourceFlags.ValueType:
            {
                value = new BamlExtensionTypeValue(GetType(valueId));
            }
            break;

            case BamlOptimizedStaticResourceFlags.StaticType:
            {
                value = GetStaticExtensionValue(valueId);
            }
            break;

            default:
            {
                value = new BamlExtensionStringValue(GetString(valueId));
            }
            break;
            }

            node.Value = value;

            AddNode(node);
        }
Exemple #2
0
        private void ReadPropertyWithExtension()
        {
            var node = new BamlPropertyWithExtension();

            node.DeclaringProperty = GetProperty(_accessor.ReadInt16());

            short flags   = _accessor.ReadInt16();
            short valueId = _accessor.ReadInt16();

            node.IsValueType  = (flags & 0x4000) == 0x4000;
            node.IsStaticType = (flags & 0x2000) == 0x2000;

            var extensionType = (BamlExtensionType)(flags & 0xfff);

            BamlExtensionValue value;

            switch (extensionType)
            {
            case BamlExtensionType.StaticExtension:
            {
                value = GetStaticExtensionValue(valueId);
            }
            break;

            case BamlExtensionType.StaticResource:
            case BamlExtensionType.DynamicResource:
            {
                if (node.IsValueType)
                {
                    value = new BamlExtensionTypeValue(GetType(valueId));
                }
                else if (node.IsStaticType)
                {
                    value = GetStaticExtensionValue(valueId);
                }
                else
                {
                    value = new BamlExtensionStringValue(GetString(valueId));
                }
            }
            break;

            case BamlExtensionType.TemplateBinding:
            {
                value = new BamlExtensionPropertyValue(GetProperty(valueId));
            }
            break;

            case BamlExtensionType.Type:
            {
                value = new BamlExtensionTypeValue(GetType(valueId));
            }
            break;

            default:
            {
                value = new BamlExtensionStringValue(GetString(valueId));
            }
            break;
            }

            node.Extension = new BamlExtension(extensionType, value);

            AddNode(node);
        }