本文整理汇总了C#中FieldCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# FieldCollection.Add方法的具体用法?C# FieldCollection.Add怎么用?C# FieldCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldCollection
的用法示例。
在下文中一共展示了FieldCollection.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFields
/// <summary>
/// Gets the fields of the current row.
/// </summary>
/// <param name="grbit">The grbit.</param>
/// <returns>A <see cref="FieldCollection"/> object to allow retrieval of all fields of the current row.</returns>
internal FieldCollection GetFields(RetrieveColumnGrbit grbit)
{
JET_PFNREALLOC allocator =
(context, pv, cb) =>
IntPtr.Zero == pv ? Marshal.AllocHGlobal(new IntPtr(cb)) : Marshal.ReAllocHGlobal(pv, new IntPtr(cb));
lock (this.isamSession)
{
this.CheckDisposed();
this.CheckRecord();
EnumerateColumnsGrbit enumerateGrbit = ((grbit & RetrieveColumnGrbit.RetrieveCopy) != 0)
? EnumerateColumnsGrbit.EnumerateCopy
: EnumerateColumnsGrbit.None;
using (IsamTransaction trx = new IsamTransaction(this.isamSession, true))
{
// enumerate all field values in the current record or copy
// buffer
JET_ENUMCOLUMN[] jecs;
int numColumnValues;
Api.JetEnumerateColumns(
this.isamSession.Sesid,
this.tableid,
0, // numColumnids
null, // columnids
out numColumnValues,
out jecs,
allocator,
IntPtr.Zero, // allocatorContext,
int.MaxValue,
enumerateGrbit);
// create a field collection to contain our field values
FieldCollection fields = new FieldCollection();
// save the location of the source record for these field values
fields.Location = this.Location;
// fill the field collection with our field values
if (jecs != null && jecs.Length > 0)
{
foreach (JET_ENUMCOLUMN jec in jecs)
{
if (jec.rgEnumColumnValue != null && jec.rgEnumColumnValue.Length > 0)
{
JET_COLUMNBASE columnbase;
VistaApi.JetGetTableColumnInfo(
this.isamSession.Sesid,
this.tableid,
jec.columnid,
out columnbase);
Columnid columnid = new Columnid(columnbase);
bool isAscii = columnbase.cp == JET_CP.ASCII;
FieldValueCollection values = new FieldValueCollection(columnid);
foreach (JET_ENUMCOLUMNVALUE jecv in jec.rgEnumColumnValue)
{
// FUTURE-2013/11/15-martinc: Drat, this is an IntPtr, and ObjectFromBytes() really
// wants a byte[] array. Copying the data to a byte array just to simply
// re-interpret it as an object is inefficient.
// We should write Converter.ObjectFromIntPtr...
byte[] bytesData = new byte[jecv.cbData];
Marshal.Copy(jecv.pvData, bytesData, 0, bytesData.Length);
values.Add(Converter.ObjectFromBytes(columnbase.coltyp, isAscii, bytesData));
}
values.ReadOnly = true;
fields.Add(values);
}
}
}
fields.ReadOnly = true;
// Return the field collection.
return fields;
}
}
}
示例2: Serialize
/// <summary>
/// Save extension field serilized into extension field (ExtensionData)
/// </summary>
/// <param name="extensionObject"></param>
public void Serialize(IExtensionObject extensionObject)
{
FieldCollection fieldValues = new FieldCollection();
IEnumerator<KeyValuePair<string, object>> fieldNameValueEnumerator = extensionObject.GetFieldEnumerator();
while (fieldNameValueEnumerator.MoveNext())
{
KeyValuePair<string, object> fieldNameValuePair = fieldNameValueEnumerator.Current;
using (ValidationScope validationScope = new ValidationScope())
{
try
{
IFieldValue fieldValue = ConvertToFieldValueInterface(extensionObject.ExtensionDataTypeId, fieldNameValuePair.Key, fieldNameValuePair.Value);
if (fieldValue != null) fieldValues.Add(new FieldNameValuePair(fieldNameValuePair.Key, fieldValue));
}
catch (InvalidFieldValueException exp)
{
validationScope.Error(exp.Message);
}
catch (NotSupportedException exp)
{
validationScope.Error(exp.Message);
}
}
}
StringBuilder output = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings()
{
Encoding = Encoding.UTF8,
Indent = true
};
using (XmlWriter writer = XmlWriter.Create(output, settings))
{
serializer.WriteObject(writer, fieldValues);
}
extensionObject.ExtensionData = output.ToString();
}