Ejemplo n.º 1
0
		internal void AddNode(XpidlAttribute attribute)
		{
			AddNodeImpl(attribute);
		}
		private static CodeMemberMethod CreateCodeMemberAttribute(XpidlAttribute xpidlAttribute, out CodeMemberMethod codeSetterMethod)
		{
			// Create CodeTypeReference and custom attributes for XpidlAttribute.Type
			CodeAttributeDeclaration codeMarshalAsAttribute;
			var codeAttributeType = CreateCodeTypeReference(xpidlAttribute.Type, out codeMarshalAsAttribute);

			// Create getter method
			var codeGetterMethod =
				new CodeMemberMethod
				{
					Name = "Get" + xpidlAttribute.Name.ToUpperCamel()
				};
			// Create special getter for NS Strings
			switch (xpidlAttribute.Type)
			{
				case XpidlType.AString:
				case XpidlType.ACString:
				case XpidlType.AUTF8String:
				case XpidlType.DOMString:
					codeGetterMethod.ReturnType = new CodeTypeReference(typeof(void));
					var codeGetterParameter = new CodeParameterDeclarationExpression(codeAttributeType, "result");
					codeGetterParameter.CustomAttributes.AddAttribute(codeMarshalAsAttribute);
					codeGetterMethod.Parameters.Add(codeGetterParameter);
					break;
				default:
					codeGetterMethod.ReturnType = codeAttributeType;
					codeGetterMethod.ReturnTypeCustomAttributes.AddAttribute(codeMarshalAsAttribute);
					break;
			}

			// Create setter method for read-write attribute
			if (xpidlAttribute.IsReadOnly)
			{
				codeSetterMethod = null;
			}
			else
			{
				codeSetterMethod =
					new CodeMemberMethod
					{
						Name = "Set" + xpidlAttribute.Name.ToUpperCamel(),
						ReturnType = new CodeTypeReference(typeof(void))
					};
				var codeSetterParameter = new CodeParameterDeclarationExpression(codeAttributeType, "value");
				codeSetterParameter.CustomAttributes.AddAttribute(codeMarshalAsAttribute);
				codeSetterMethod.Parameters.Add(codeSetterParameter);
			}

			return codeGetterMethod;
		}