private static int MeasureString(MemberAttributeInfo attributes) { if (attributes?.VariableLengthAttribute != null) { throw new InvalidOperationException("Variable size attributes are not supported for static measurement"); } if (attributes?.FixedLengthAttribute == null) { throw new InvalidOperationException("Strings without set length are not supported for static measurement"); } var strEnc = attributes.FixedLengthAttribute.StringEncoding; int charSize; switch (strEnc) { case StringEncoding.ASCII: charSize = 1; break; case StringEncoding.UTF32: charSize = 4; break; default: throw new InvalidOperationException("Variable width encodings are not supported for static measurement"); } var length = attributes.FixedLengthAttribute.Length; return(length * charSize); }
private static int MeasureString(MemberAttributeInfo attributes) { if (attributes?.VariableLengthAttribute != null) { throw new InvalidOperationException("Variable size attributes are not supported for static measurement"); } if (attributes?.FixedLengthAttribute == null) { throw new InvalidOperationException("Strings without set length are not supported for static measurement"); } return(attributes.FixedLengthAttribute.Length); }
private static int MeasureList(Type type, MemberAttributeInfo attributes) { if (attributes?.VariableLengthAttribute != null) { throw new InvalidOperationException("Variable size attributes are not supported for static measurement"); } if (attributes?.FixedLengthAttribute == null) { throw new InvalidOperationException("Strings without set length are not supported for static measurement"); } Type ElementType = type.IsArray ? type.GetElementType() : type.GetGenericArguments()[0]; return(attributes?.FixedLengthAttribute.Length ?? 0 * MeasureType(ElementType)); }