本文整理汇总了C#中ReadOnlyCollection.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyCollection.GroupBy方法的具体用法?C# ReadOnlyCollection.GroupBy怎么用?C# ReadOnlyCollection.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyCollection
的用法示例。
在下文中一共展示了ReadOnlyCollection.GroupBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeNode
protected TypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
: this(parent)
{
if (memberInfo == null)
return;
Name = memberInfo.Name;
var propertyInfo = memberInfo as PropertyInfo;
var fieldInfo = memberInfo as FieldInfo;
if (propertyInfo != null)
{
Type = propertyInfo.PropertyType;
ValueGetter = MagicMethods.MagicFunc(parentType, propertyInfo.GetGetMethod());
var setMethod = propertyInfo.GetSetMethod();
if(setMethod != null)
ValueSetter = MagicMethods.MagicAction(parentType, setMethod);
}
else if (fieldInfo != null)
{
Type = fieldInfo.FieldType;
ValueGetter = fieldInfo.GetValue;
ValueSetter = fieldInfo.SetValue;
}
else throw new NotSupportedException(String.Format("{0} not supported", memberInfo.GetType().Name));
NullableUnderlyingType = Nullable.GetUnderlyingType(Type);
var attributes = memberInfo.GetCustomAttributes(true);
IgnoreAttribute = attributes.OfType<IgnoreAttribute>().SingleOrDefault();
/* Don't go any further if we're ignoring this. */
if (IsIgnored)
return;
var fieldOrderAttribute = attributes.OfType<FieldOrderAttribute>().SingleOrDefault();
if (fieldOrderAttribute != null)
_order = fieldOrderAttribute.Order;
var serializeAsAttribute = attributes.OfType<SerializeAsAttribute>().SingleOrDefault();
if (serializeAsAttribute != null)
{
_serializedType = serializeAsAttribute.SerializedType;
Endianness = serializeAsAttribute.Endianness;
if (!String.IsNullOrEmpty(serializeAsAttribute.Encoding))
Encoding = Encoding.GetEncoding(serializeAsAttribute.Encoding);
}
FieldLengthAttribute = attributes.OfType<FieldLengthAttribute>().SingleOrDefault();
if (FieldLengthAttribute != null)
{
FieldLengthBinding = new Binding(FieldLengthAttribute, GetBindingLevel(FieldLengthAttribute.Binding));
}
FieldCountAttribute = attributes.OfType<FieldCountAttribute>().SingleOrDefault();
if (FieldCountAttribute != null)
{
FieldCountBinding = new Binding(FieldCountAttribute, FindAncestorLevel(FieldCountAttribute.Binding));
}
FieldOffsetAttribute = attributes.OfType<FieldOffsetAttribute>().SingleOrDefault();
if (FieldOffsetAttribute != null)
{
FieldOffsetBinding = new Binding(FieldOffsetAttribute, GetBindingLevel(FieldOffsetAttribute.Binding));
}
var serializeWhenAttributes = attributes.OfType<SerializeWhenAttribute>().ToArray();
SerializeWhenAttributes = new ReadOnlyCollection<SerializeWhenAttribute>(serializeWhenAttributes);
if (SerializeWhenAttributes.Count > 0)
{
SerializeWhenBindings = new ReadOnlyCollection<ConditionalBinding>(
serializeWhenAttributes.Select(
attribute => new ConditionalBinding(attribute, GetBindingLevel(attribute.Binding))).ToList());
}
var subtypeAttributes = attributes.OfType<SubtypeAttribute>().ToArray();
SubtypeAttributes = new ReadOnlyCollection<SubtypeAttribute>(subtypeAttributes);
if (SubtypeAttributes.Count > 0)
{
var bindingGroups =
SubtypeAttributes.GroupBy(subtypeAttribute => subtypeAttribute.Binding);
if (bindingGroups.Count() > 1)
throw new BindingException("Subtypes must all use the same binding configuration.");
var firstBinding = SubtypeAttributes[0];
SubtypeBinding = new Binding(firstBinding, GetBindingLevel(firstBinding.Binding));
var valueGroups = SubtypeAttributes.GroupBy(attribute => attribute.Value);
if (valueGroups.Count() < SubtypeAttributes.Count)
throw new InvalidOperationException("Subtype values must be unique.");
//.........这里部分代码省略.........