public static IEnumerable <CAttribute> GetCOBieAttributes(this DPoWAttributableObject obj, DateTime?createdOn, string createdBy) { IEnumerable <Xbim.DPoW.Attribute> sAttributes = obj.Attributes; var sAttrs = sAttributes as DAttribute[] ?? sAttributes.ToArray(); if (sAttributes == null || !sAttrs.Any()) { yield break; } foreach (var sAttr in sAttrs) { //create attribute in target var tAttr = new CAttribute { Name = sAttr.Name, Description = sAttr.Definition, PropertySetName = "DPoW Attributes", CreatedOn = createdOn, CreatedBy = new ContactKey { Email = createdBy }, Categories = new List <Category>(new [] { new Category { Code = "Submitted" } }) }; switch (sAttr.ValueType) { case ValueTypeEnum.NotDefined: tAttr.Value = new StringAttributeValue { Value = sAttr.Value }; break; case ValueTypeEnum.Boolean: bool bVal; if (bool.TryParse(sAttr.Value, out bVal)) { tAttr.Value = new BooleanAttributeValue { Value = bVal } } ; break; case ValueTypeEnum.DateTime: DateTime dtVal; if (DateTime.TryParse(sAttr.Value, out dtVal)) { tAttr.Value = new DateTimeAttributeValue { Value = dtVal } } ; break; case ValueTypeEnum.Decimal: float fVal; if (float.TryParse(sAttr.Value, out fVal)) { tAttr.Value = new DecimalAttributeValue { Value = fVal } } ; break; case ValueTypeEnum.Integer: int iVal; if (int.TryParse(sAttr.Value, out iVal)) { tAttr.Value = new IntegerAttributeValue { Value = iVal } } ; break; case ValueTypeEnum.String: tAttr.Value = new StringAttributeValue { Value = sAttr.Value }; break; default: throw new ArgumentOutOfRangeException(); } //default action is to create string if (tAttr.Value == null) { tAttr.Value = new StringAttributeValue { Value = sAttr.Value } } ; yield return(tAttr); } } }
public static IEnumerable <AttributeType> GetCOBieAttributes(this DPoWAttributableObject obj) { IEnumerable <Xbim.DPoW.Attribute> sAttributes = obj.Attributes; var sAttrs = sAttributes as Attribute[] ?? sAttributes.ToArray(); if (sAttributes == null || !sAttrs.Any()) { yield break; } foreach (var sAttr in sAttrs) { //create attribute in target var tAttr = new AttributeType { AttributeName = sAttr.Name, AttributeDescription = sAttr.Definition, AttributeValue = new AttributeValueType() }; switch (sAttr.ValueType) { case ValueTypeEnum.NotDefined: tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; break; case ValueTypeEnum.Boolean: bool bVal; if (bool.TryParse(sAttr.Value, out bVal)) { tAttr.AttributeValue.Item = new BooleanValueType { BooleanValue = bVal, BooleanValueSpecified = true }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeBooleanValue; } break; case ValueTypeEnum.DateTime: DateTime dtVal; if (DateTime.TryParse(sAttr.Value, out dtVal)) { tAttr.AttributeValue.Item = dtVal; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeDateTimeValue; } break; case ValueTypeEnum.Decimal: float fVal; if (float.TryParse(sAttr.Value, out fVal)) { tAttr.AttributeValue.Item = new AttributeDecimalValueType { DecimalValue = fVal, DecimalValueSpecified = true }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeDecimalValue; } break; case ValueTypeEnum.Integer: int iVal; if (int.TryParse(sAttr.Value, out iVal)) { tAttr.AttributeValue.Item = new AttributeIntegerValueType { IntegerValue = iVal }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeIntegerValue; } break; case ValueTypeEnum.String: tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; break; default: throw new ArgumentOutOfRangeException(); } //default action is to create string if (tAttr.AttributeValue.Item == null) { tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; } yield return(tAttr); } }