/// <summary> /// Encodes the search as an SRestriction. /// </summary> /// <returns>The encoder containing the restriction. The caller is responsible for disposing.</returns> public static RestrictionEncoder ToRestriction(this SearchQuery search) { RestrictionEncoder encoder = new RestrictionEncoder(); search.Encode(encoder); return(encoder); }
unsafe public static IntPtr MarshalFromObject(RestrictionEncoder encoder, PropTag prop, object value) { IntPtr ptr; Data data = new Data(); switch (prop.type) { case PropType.BOOLEAN: data.b = (bool)value; ptr = encoder.AllocateWithExtra <Header>(8, data.b); break; case PropType.STRING8: IntPtr lpszA = encoder.Allocate(Encoding.ASCII.GetBytes((string)value), 1); ptr = encoder.AllocateWithExtra <Header>(8, lpszA); break; case PropType.UNICODE: IntPtr lpszW = encoder.Allocate(Encoding.Unicode.GetBytes((string)value), 2); ptr = encoder.AllocateWithExtra <Header>(8, lpszW); break; case PropType.BINARY: data.bin.cb = (uint)((SBinaryWrapper)value).Data.Length; data.bin.ptr = (byte *)encoder.Allocate(((SBinaryWrapper)value).Data); ptr = encoder.AllocateWithExtra <Header>(8, data.bin); break; default: throw new NotImplementedException(); } // Initialise the header PropValue *obj = (PropValue *)ptr; obj->header.ulPropTag = prop; return(ptr); }
/// <summary> /// Constructor. Allocates the memory for the object. /// </summary> /// <param name="root">The root allocation, or null if this is the root. All allocations will be added to the root.</param> /// <param name="count">The number of SRestriction objects to allocate</param> public Allocation(RestrictionEncoder encoder, int count) { this.count = count; // Allocate the buffer ptr = encoder.AllocateArray <SRestriction>(count); }