/// <summary> /// 現在のモーションオブジェクトのタイプから,オブジェクトのインスタンスを作成して返します. /// </summary> public MotionObject GetEmptyObject() { if (ObjectType == null) { throw new InvalidOperationException("cannot create MotionObject of null Type"); } if (_emptyObject == null) { lock (this) { _emptyObject = (MotionObject)Activator.CreateInstance(ObjectType); return((MotionObject)_emptyObject.Clone()); } } return((MotionObject)_emptyObject.Clone()); }
/// <summary> /// 指定された方がモーションオブジェクトのタイプであるかを検証し,検証に失敗すれば例外をスローします. /// </summary> /// <param name="motionObjectType"></param> public static void IsMotionObjectTypeOrThrow(Type motionObjectType) { if (motionObjectType == null) { throw new ArgumentNullException("motionObjectType", "'motionObjectType' cannot be null"); } if (!motionObjectType.IsSubclassOf(typeof(MotionObject))) { throw new ArgumentException(string.Format("{0} is not subclass of MotionObject", motionObjectType)); } if (motionObjectType.IsAbstract) { throw new ArgumentException(string.Format("{0} is Abstract Type", motionObjectType)); } if (motionObjectType.GetConstructor(System.Type.EmptyTypes) == null) { throw new ArgumentException(string.Format("{0} does not have constructor with no parameter", motionObjectType)); } MotionObject @object = (MotionObject)Activator.CreateInstance(motionObjectType); Object clone = @object.Clone(); if (clone.GetType() != motionObjectType) { throw new ArgumentException(string.Format("{0}.Clone() returns not {0} but {1}", motionObjectType, clone.GetType())); } MemoryStream stream = new MemoryStream(); try { using (BinaryWriter writer = new BinaryWriter(stream)) { @object.WriteBinary(writer); } } catch (Exception ex) { throw new ArgumentException(string.Format("{0} failed to WriteBinary with default data", motionObjectType), ex); } stream = new MemoryStream(stream.ToArray()); try { using (BinaryReader reader = new BinaryReader(stream)) { ((MotionObject)clone).ReadBinary(reader); } } catch (Exception ex) { throw new ArgumentException(string.Format("{0} failed to WriteBinary and ReadBinary with default data", motionObjectType), ex); } }
/// <summary> /// IDを指定してオブジェクトを取得します. /// </summary> /// <param name="id"></param> /// <returns></returns> public MotionObject GetObject(uint id) { MotionObject tmp = _frame.GetObject(id); return(tmp == null ? null : (MotionObject)tmp.Clone()); }
/// <summary> /// オブジェクト情報を指定してオブジェクトを取得します /// </summary> /// <param name="info"></param> /// <returns></returns> public MotionObject GetObject(IReadableMotionObjectInfo info) { MotionObject tmp = _frame.GetObject(info); return(tmp == null ? null : (MotionObject)tmp.Clone()); }
/// <summary> /// IDを指定してオブジェクトを取得します. /// </summary> /// <param name="id"></param> /// <returns></returns> public MotionObject this[uint id] { get { MotionObject tmp = _frame.GetObject(id); return(tmp == null ? null : (MotionObject)tmp.Clone()); } }