/// <summary> /// Create Tag array. /// </summary> /// <param name="name">The textual name of the tag to access. The name is anything allowed by the protocol. /// E.g. myDataStruct.rotationTimer.ACC, myDINTArray[42] etc.</param> /// <param name="length">elements count: 1- single, n-array.</param> /// <typeparam name="TCustomType">Type to create</typeparam> /// <returns></returns> public Tag <TCustomType> CreateTagArray <TCustomType>(string name, int length) { var type = typeof(TCustomType); if (!type.IsArray) { throw new ArgumentException("Is not array!"); } var obj = (Array)Activator.CreateInstance(type, length); TagValueManager.FixStringNullToEmpty(obj); return(CreateTagType <TCustomType>(name, TagSize.GetSizeFromObject(obj.GetValue(0)), length)); }
internal static TType CreateObject <TType>(int length) { var obj = default(TType); var typeTType = typeof(TType); if (typeTType == typeof(string)) { obj = (TType)((object)""); } else if (typeTType.IsArray) { obj = (TType)Activator.CreateInstance(typeTType, length); } else { obj = (TType)Activator.CreateInstance(typeTType); } TagValueManager.FixStringNullToEmpty(obj); return(obj); }