コード例 #1
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyWithConverter()
		{
			short identifier = reader.ReadInt16();
			string text = reader.ReadString();
			reader.ReadInt16();

			PropertyDeclaration pd = this.GetPropertyDeclaration(identifier);
			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = text;

			nodes.Enqueue(property);
		}
コード例 #2
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadDefAttribute()
		{
			string text = reader.ReadString();
			short identifier = reader.ReadInt16();

			PropertyDeclaration pd;
			switch (identifier)
			{
				case -2:
					pd = new PropertyDeclaration("Uid", XamlTypeDeclaration);
					break;
				case -1:
					pd = new PropertyDeclaration("Name", XamlTypeDeclaration);
					break;
				default:
					string recordName = this.stringTable[identifier];
					if (recordName != "Key") throw new NotSupportedException(recordName);
					pd = new PropertyDeclaration(recordName, XamlTypeDeclaration);

					keys.Add(new KeyMapping(text) { Position = -1 });
					break;
			}

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Key, pd);
			property.Value = text;

			nodes.Enqueue(property);
		}
コード例 #3
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyCustom()
		{
			short identifier = reader.ReadInt16();
			short serializerTypeId = reader.ReadInt16();
			bool isValueTypeId = (serializerTypeId & 0x4000) == 0x4000;
			if (isValueTypeId)
				serializerTypeId = (short)(serializerTypeId & ~0x4000);

			PropertyDeclaration pd = this.GetPropertyDeclaration(identifier);
			string value;
			switch (serializerTypeId)
			{
				case 0x2e8:
					value = new BrushConverter().ConvertToString(SolidColorBrush.DeserializeFrom(reader));
					break;
				case 0x2e9:
					value = new Int32CollectionConverter().ConvertToString(DeserializeInt32CollectionFrom(reader));
					break;
				case 0x89:

					short typeIdentifier = reader.ReadInt16();
					if (isValueTypeId)
					{
						TypeDeclaration typeDeclaration = this.GetTypeDeclaration(typeIdentifier);
						string name = reader.ReadString();
						value = FormatPropertyDeclaration(new PropertyDeclaration(name, typeDeclaration), true, false, true);
					}
					else
						value = FormatPropertyDeclaration(this.GetPropertyDeclaration(typeIdentifier), true, false, true);
					break;

				case 0x2ea:
					value = ((IFormattable)staticConvertCustomBinaryToObjectMethod.Invoke(null, new object[] { this.reader })).ToString("G", CultureInfo.InvariantCulture);
					break;
				case 0x2eb:
				case 0x2f0:
					value = Deserialize3DPoints();
					break;
				case 0x2ec:
					value = DeserializePoints();
					break;
				case 0xc3:
					// Enum
					uint num = reader.ReadUInt32();
					value = num.ToString();
					break;
				case 0x2e:
					int b = reader.ReadByte();
					value = (b == 1) ? Boolean.TrueString : Boolean.FalseString;
					break;
				default:
					return;
			}

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = value;

			nodes.Enqueue(property);
		}
コード例 #4
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyWithExtension()
		{
			short identifier = reader.ReadInt16();
			short x = reader.ReadInt16();
			short valueIdentifier = reader.ReadInt16();
			bool isValueType = (x & 0x4000) == 0x4000;
			bool isStaticType = (x & 0x2000) == 0x2000;
			x = (short)(x & 0xfff);

			PropertyDeclaration pd = this.GetPropertyDeclaration(identifier);
			short extensionIdentifier = (short)-(x & 0xfff);
			string value = String.Empty;

			switch (x) {
				case 0x25a:
					// StaticExtension
					object resource = this.GetResourceName(valueIdentifier);
					if (resource is ResourceName)
						value = this.GetStaticExtension(((ResourceName)resource).Name);
					else if (resource is PropertyDeclaration)
						value = this.GetStaticExtension(FormatPropertyDeclaration(((PropertyDeclaration)resource), true, false, false));
					break;
				case 0x25b: // StaticResource
				case 0xbd: // DynamicResource
					if (isValueType)
					{
						value = this.GetTypeExtension(valueIdentifier);
					}
					else if (isStaticType)
					{
						TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier);
						value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier).ToString()));
					}
					else
					{
						TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier);
						value = GetExtension(extensionDeclaration, (string)this.stringTable[valueIdentifier]);
					}
					break;

				case 0x27a:
					// TemplateBinding
					PropertyDeclaration pdValue = this.GetPropertyDeclaration(valueIdentifier);
					value = GetTemplateBindingExtension(pdValue);
					break;
				default:
					throw new NotSupportedException("Unknown property with extension");
			}

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = value;

			nodes.Enqueue(property);
		}
コード例 #5
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyTypeReference()
		{
			short identifier = reader.ReadInt16();
			short typeIdentifier = reader.ReadInt16();

			PropertyDeclaration pd = this.GetPropertyDeclaration(identifier);
			string value = this.GetTypeExtension(typeIdentifier);

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = value;

			nodes.Enqueue(property);
		}
コード例 #6
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyWithStaticResourceIdentifier()
		{
			short propertyId = reader.ReadInt16();
			short index = reader.ReadInt16();

			PropertyDeclaration pd = this.GetPropertyDeclaration(propertyId);
			object staticResource = GetStaticResource(index);

			string prefix = this.LookupPrefix(XmlPIMapping.PresentationNamespace, false);
			string value = String.Format("{{{0}{1}StaticResource {2}}}", prefix, (String.IsNullOrEmpty(prefix)) ? String.Empty : ":", staticResource);

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = value;

			nodes.Enqueue(property);
		}
コード例 #7
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPresentationOptionsAttribute()
		{
			string text = reader.ReadString();
			short valueIdentifier = reader.ReadInt16();

			PropertyDeclaration pd = new PropertyDeclaration(this.stringTable[valueIdentifier].ToString());

			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
			property.Value = text;
		}
コード例 #8
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void AddKeyToElement(string key)
		{
			PropertyDeclaration pd = new PropertyDeclaration("Key", XamlTypeDeclaration);
			XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Key, pd);

			property.Value = key;

			nodes.Enqueue(property);
		}
コード例 #9
0
ファイル: XmlBamlReader.cs プロジェクト: 95ulisse/ILEdit
		void ReadPropertyComplexEnd()
		{
			XmlBamlPropertyElement propertyElement = (XmlBamlPropertyElement) elements.Peek();

			CloseElement();

			complexPropertyOpened--;
			// this property could be a markup extension
			// try to convert it
			int start = nodes.IndexOf(propertyElement) + 1;
			IEnumerator<XmlBamlNode> enumerator = nodes.GetEnumerator();
			
			// move enumerator to the start of this property value
			for (int i = 0; i < start && enumerator.MoveNext(); i++) ;

			if (IsExtension(enumerator) && start < nodes.Count - 1) {
				start--;
				nodes.RemoveAt(start);
				nodes.RemoveLast();

				StringBuilder sb = new StringBuilder();
				FormatElementExtension((XmlBamlElement) nodes[start], sb);

				XmlBamlProperty property =
					new XmlBamlProperty(elements.Peek(), PropertyType.Complex, propertyElement.PropertyDeclaration);
				property.Value = sb.ToString();
				nodes.Add(property);
			}
		}
コード例 #10
0
ファイル: XmlBamlReader.cs プロジェクト: KOLANICH/ILSpy
		void EnqueueProperty(short identifier, string text)
		{
			PropertyDeclaration pd = this.GetPropertyDeclaration(identifier);
			XmlBamlElement element = FindXmlBamlElement();
			// if we've already read a nested element for the current element, this property must be a nested element as well
			if (HaveSeenNestedElement())
			{
				XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Complex, pd);
				
				nodes.Enqueue(property);
				nodes.Enqueue(new XmlBamlText(text));
				nodes.Enqueue(new XmlBamlEndElement(property));
			}
			else
			{
				XmlBamlProperty property = new XmlBamlProperty(element, PropertyType.Value, pd);
				property.Value = text;
				
				nodes.Enqueue(property);
			}
		}
コード例 #11
0
ファイル: XmlBamlReader.cs プロジェクト: KOLANICH/ILSpy
		void ReadPropertyComplexEnd()
		{
			XmlBamlPropertyElement propertyElement = (XmlBamlPropertyElement) elements.Peek();

			CloseElement();

			complexPropertyOpened--;
			// this property could be a markup extension
			// try to convert it
			int elementIndex = nodes.IndexOf(propertyElement.Parent);
			int start = nodes.IndexOf(propertyElement) + 1;
			IEnumerator<XmlBamlNode> enumerator = nodes.GetEnumerator();
			
			// move enumerator to the start of this property value
			// note whether there are any child elements before this one
			bool anyChildElement = false;
			for (int i = 0; i < start && enumerator.MoveNext(); i++)
			{
				if (i > elementIndex && i < start - 1 && (enumerator.Current is XmlBamlEndElement))
					anyChildElement = true;
			}

			if (!anyChildElement && IsExtension(enumerator) && start < nodes.Count - 1) {
				start--;
				nodes.RemoveAt(start);
				nodes.RemoveLast();

				StringBuilder sb = new StringBuilder();
				FormatElementExtension((XmlBamlElement) nodes[start], sb);

				XmlBamlProperty property =
					new XmlBamlProperty(elements.Peek(), PropertyType.Complex, propertyElement.PropertyDeclaration);
				property.Value = sb.ToString();
				nodes.Add(property);
			}
		}