本文整理汇总了C#中FieldDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# FieldDescriptor类的具体用法?C# FieldDescriptor怎么用?C# FieldDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDescriptor类属于命名空间,在下文中一共展示了FieldDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSerializable
private static bool IsSerializable(FieldDescriptor fd, object obj)
{
switch (fd.FdType)
{
case FieldTypes.Scalar:
if (fd.IsDefaultValueFromContext(obj))
return false;
break;
case FieldTypes.CompositeElement:
case FieldTypes.CollectionElement:
case FieldTypes.MapElement:
Object tempObj = fd.GetObject(obj);
if (tempObj == null)
return false;
break;
case FieldTypes.CollectionScalar:
case FieldTypes.MapScalar:
Object scalarCollectionObject = fd.GetObject(obj);
if (scalarCollectionObject == null)
return false;
ICollection scalarCollection = XmlTools.GetCollection(scalarCollectionObject);
if (scalarCollection == null || scalarCollection.Count <= 0)
return false;
break;
}
return true;
}
示例2: equals
public bool equals(FieldDescriptor fd)
{
return fieldName.Equals(fd.fieldName)
&& className.Equals(fd.className)
&& valueDesc == fd.valueDesc
&& type == fd.type;
}
示例3: ExtensionGenerator
internal ExtensionGenerator(FieldDescriptor descriptor)
: base(descriptor, 0)
{
if (Descriptor.ExtensionScope != null)
{
scope = GetClassName(Descriptor.ExtensionScope);
}
else
{
scope = DescriptorUtil.GetFullUmbrellaClassName(Descriptor.File);
}
switch (Descriptor.MappedType)
{
case MappedType.Message:
type = GetClassName(Descriptor.MessageType);
break;
case MappedType.Enum:
type = GetClassName(Descriptor.EnumType);
break;
default:
type = DescriptorUtil.GetMappedTypeName(Descriptor.MappedType);
break;
}
extends = GetClassName(Descriptor.ContainingType);
name = Descriptor.CSharpOptions.PropertyName;
}
示例4: Get
public override void Get(FieldDescriptor ds_, IDataReader dr_)
{
switch( ds_.Pos )
{
case 0: Name = dr_.AsString(); break;
case 1: dr_.AsMessage(_data??(Data = new Struct()), ds_); break;
}
}
示例5: LoadFields
public override void LoadFields(FieldDescriptor[] fields)
{
base.LoadFields(fields); // removes RequiredMessageHeader
if (Fields.Length != 3 ||
Fields[0].Type.Name != "DT_INT" ||
Fields[1].Type.Name != "DT_FIXEDARRAY" || Fields[1].SubType.Name != "NetAttributeKeyValue" ||
Fields[2].Type != null)
throw new Exception("Unexpected fields in AttributesSetValuesMessage.");
}
示例6: LoadFields
public override void LoadFields(FieldDescriptor[] fields)
{
base.LoadFields(fields); // removes RequiredMessageHeader
if (Fields.Length != 2 ||
Fields[0].Type.Name != "DT_INT" || Fields[0].HasMinMax != false && Fields[0].EncodedBits != 32 ||
Fields[1].Type != null)
throw new Exception("Unexpected fields in GenericBlobMessage");
}
示例7: LoadFields
public override void LoadFields(FieldDescriptor[] fields)
{
base.LoadFields(fields); // removes RequiredMessageHeader
if (this.Fields.Length != 4 ||
this.Fields[0].Type._Name != "RequiredMessageHeader" ||
this.Fields[1].Type._Name != "DT_INT" ||
this.Fields[2].Type._Name != "NetAttributeKeyValue" ||
this.Fields[3].Type != null)
throw new Exception("Unexpected fields in AttributeSetValueMessage");
}
示例8: SerializeComposite
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <param name="textWriter"></param>
/// <param name="translationContext"></param>
/// <param name="fd"></param>
private void SerializeComposite(object obj, TextWriter textWriter, TranslationContext translationContext,
FieldDescriptor fd)
{
Object compositeObject = fd.GetObject(obj);
FieldDescriptor compositeAsScalarFd = GetClassDescriptor(compositeObject).ScalarValueFieldDescripotor;
if (compositeAsScalarFd != null)
{
WriteBibtexAttribute(compositeObject, fd, textWriter, translationContext);
}
}
示例9: CheckedMungeValue
/// <summary>
/// Munges a single value and checks that the length ends up the same as it was before.
/// </summary>
private static object CheckedMungeValue(FieldDescriptor fieldDescriptor, object value)
{
int currentSize = CodedOutputStream.ComputeFieldSize(fieldDescriptor.FieldType, fieldDescriptor.FieldNumber, value);
object mungedValue = MungeValue(fieldDescriptor, value);
int mungedSize = CodedOutputStream.ComputeFieldSize(fieldDescriptor.FieldType, fieldDescriptor.FieldNumber, mungedValue);
// Exceptions log more easily than assertions
if (currentSize != mungedSize) {
throw new Exception("Munged value had wrong size. Field type: " + fieldDescriptor.FieldType
+ "; old value: " + value + "; new value: " + mungedValue);
}
return mungedValue;
}
示例10: GetAdditionalParameters
protected virtual FieldDescriptor GetAdditionalParameters(Item standardValues, Dictionary<string, string> additionalParameters)
{
Assert.ArgumentNotNull(standardValues, "standardValues");
Assert.ArgumentNotNull(additionalParameters, "additionalParameters");
var value = new UrlString();
foreach (var key in additionalParameters.Keys)
{
value[key] = HttpUtility.UrlDecode(additionalParameters[key]);
}
var descriptor = new FieldDescriptor(standardValues, "Additional Parameters") { Value = value.ToString() };
return descriptor;
}
示例11: Serialize
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <param name="rootObjectFieldDescriptor"></param>
/// <param name="textWriter"></param>
/// <param name="translationContext"></param>
private void Serialize(object obj, FieldDescriptor rootObjectFieldDescriptor, TextWriter textWriter,
TranslationContext translationContext)
{
SerializationPreHook(obj, translationContext);
WriteObjectStart(rootObjectFieldDescriptor, textWriter);
IEnumerable<FieldDescriptor> allFieldDescriptors = GetClassDescriptor(obj).AllFieldDescriptors;
SerializeFields(obj, textWriter, translationContext, allFieldDescriptors.ToList());
WriteClose(textWriter);
SerializationPostHook(obj, translationContext);
}
示例12: AddToMapOrMarkUnresolved
private void AddToMapOrMarkUnresolved(object root, FieldDescriptor currentFieldDescriptor, object subRoot,
string simplId)
{
IDictionary collection =
(IDictionary) currentFieldDescriptor.AutomaticLazyGetCollectionOrMap(root);
if (subRoot != null)
{
var mappable = subRoot as IMappable<object>;
if (mappable != null)
{
var key = mappable.Key();
collection.Add(key, mappable);
}
}
else
translationContext.RefObjectNeedsIdResolve(collection, null, simplId);
}
示例13: SingleFieldAccessor
internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
{
if (!property.CanWrite)
{
throw new ArgumentException("Not all required properties/methods available");
}
setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod());
var clrType = property.PropertyType;
// TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
object defaultValue =
descriptor.FieldType == FieldType.Message ? null
: clrType == typeof(string) ? ""
: clrType == typeof(ByteString) ? ByteString.Empty
: Activator.CreateInstance(clrType);
clearDelegate = message => SetValue(message, defaultValue);
}
示例14: SerializeScalar
private static void SerializeScalar(object obj, FieldDescriptor fd, TextWriter textWriter, TranslationContext translationContext)
{
// check wether we need quotation marks to surround the value.
bool needQuotationMarks = true;
ScalarType st = fd.ScalarType;
if (st != null)
{
needQuotationMarks = st.NeedsJsonQuotationWrap();
}
textWriter.Write('"');
textWriter.Write(fd.TagName);
textWriter.Write('"');
textWriter.Write(':');
if (needQuotationMarks)
textWriter.Write('"');
fd.AppendValue(textWriter, obj, translationContext, Format.Json);
if (needQuotationMarks)
textWriter.Write('"');
}
示例15: Serialize
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <param name="rootObjectFieldDescriptor"></param>
/// <param name="binaryWriter"></param>
/// <param name="translationContext"></param>
private void Serialize(object obj, FieldDescriptor rootObjectFieldDescriptor, BinaryWriter binaryWriter,
TranslationContext translationContext)
{
if (AlreadySerialized(obj, translationContext))
{
WriteSimplRef(obj, rootObjectFieldDescriptor, binaryWriter);
return;
}
translationContext.MapObject(obj);
SerializationPreHook(obj, translationContext);
ClassDescriptor rootObjectClassDescriptor = GetClassDescriptor(obj);
MemoryStream bufferMemoryStream = new MemoryStream();
BinaryWriter outputBuffer = new BinaryWriter(bufferMemoryStream);
IEnumerable<FieldDescriptor> allFieldDescriptors = GetClassDescriptor(obj).AllFieldDescriptors;
SerializeFields(obj, outputBuffer, translationContext, allFieldDescriptors.ToList());
WriteHeader(binaryWriter, bufferMemoryStream, rootObjectFieldDescriptor.TlvId);
SerializationPostHook(obj, translationContext);
}