本文整理汇总了C#中System.ComponentModel.PropertyDescriptorCollection.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDescriptorCollection.Cast方法的具体用法?C# PropertyDescriptorCollection.Cast怎么用?C# PropertyDescriptorCollection.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.PropertyDescriptorCollection
的用法示例。
在下文中一共展示了PropertyDescriptorCollection.Cast方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, Field.Store defaultStorage)
{
return from property in properties.Cast<PropertyDescriptor>()
where property.Name != Constants.DocumentIdFieldName
from field in CreateFields(property.Name, property.GetValue(val), defaultStorage)
select field;
}
示例2: Index
public static IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != Constants.DocumentIdFieldName
let value = property.GetValue(val)
from field in CreateFields(name, value, indexDefinition, defaultStorage)
select field);
}
示例3: Index
public static IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != "__document_id"
let value = property.GetValue(val)
where value != null
select Createfield(name, value, indexDefinition, defaultStorage));
}
示例4: Index
public IEnumerable<Field> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != "__document_id"
let value = property.GetValue(val)
where value != null
select new Field(name, ToIndexableString(value, indexDefinition.GetIndex(name)), indexDefinition.GetStorage(name), indexDefinition.GetIndex(name)));
}
示例5: Patch
PropertyDescriptorCollection Patch(PropertyDescriptorCollection original)
{
return new PropertyDescriptorCollection(original.Cast<PropertyDescriptor>().Select(x => {
var control = instance as Control;
if(control != null && (BindingOperations.IsBoundProperty(control, x) || !SerializeHelper.CanSerializeProperty(control, x)))
return new BoundPropertyDescriptor(x);
return x;
}).ToArray());
}
示例6: Filter
PropertyDescriptorCollection Filter(PropertyDescriptorCollection properties)
{
PropertyDescriptor property = properties[_parent._propertyName];
if (property != null) {
if ((properties as System.Collections.IDictionary).IsReadOnly) {
properties = new PropertyDescriptorCollection(properties.Cast<PropertyDescriptor>().ToArray());
}
properties.Remove(property);
properties.Add(new ShadowPropertyDescriptor(_parent, property));
}
return properties;
}
示例7: ValidateEntityAssociations
/// <summary>
/// This method validates the association attributes for the specified entity type
/// </summary>
/// <param name="entityType">Type of entity to validate its association attributes for</param>
/// <param name="entityProperties">collection of entity property descriptors</param>
private void ValidateEntityAssociations(Type entityType, PropertyDescriptorCollection entityProperties)
{
foreach (PropertyDescriptor pd in entityProperties)
{
// validate the association attribute (if any)
AssociationAttribute assocAttrib = pd.Attributes[typeof(AssociationAttribute)] as AssociationAttribute;
if (assocAttrib == null)
{
continue;
}
string assocName = assocAttrib.Name;
if (string.IsNullOrEmpty(assocName))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_NameCannotBeNullOrEmpty, pd.Name, entityType));
}
if (string.IsNullOrEmpty(assocAttrib.ThisKey))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_StringCannotBeNullOrEmpty, assocName, entityType, "ThisKey"));
}
if (string.IsNullOrEmpty(assocAttrib.OtherKey))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_StringCannotBeNullOrEmpty, assocName, entityType, "OtherKey"));
}
// The number of keys in 'this' and 'other' must be the same
if (assocAttrib.ThisKeyMembers.Count() != assocAttrib.OtherKeyMembers.Count())
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_Key_Count_Mismatch, assocName, entityType, assocAttrib.ThisKey, assocAttrib.OtherKey));
}
// check that all ThisKey members exist on this entity type
foreach (string thisKey in assocAttrib.ThisKeyMembers)
{
if (entityProperties[thisKey] == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_ThisKeyNotFound, assocName, entityType, thisKey));
}
}
// Verify that the association name is unique. In inheritance scenarios, self-referencing associations
// on the base type should be inheritable by the derived types.
Type otherEntityType = TypeUtility.GetElementType(pd.PropertyType);
int otherMemberCount = entityProperties.Cast<PropertyDescriptor>().Count(p => p.Name != pd.Name && p.Attributes.OfType<AssociationAttribute>().Any(a => a.Name == assocAttrib.Name));
bool isSelfReference = otherEntityType.IsAssignableFrom(entityType);
if ((!isSelfReference && otherMemberCount > 0) || (isSelfReference && otherMemberCount > 1))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_NonUniqueAssociationName, assocName, entityType));
}
// Verify that the type of FK associations return singletons.
if (assocAttrib.IsForeignKey && (otherEntityType != pd.PropertyType))
{
throw new InvalidOperationException(string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidAssociation_FKNotSingleton,
assocName, entityType));
}
// Associations are not allowed to be marked as [Required], because we don't guarantee
// that we set the association on the server. In many cases it's possible that we simply
// associate entities based on FKs.
if (pd.Attributes[typeof(RequiredAttribute)] != null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resource.Entity_RequiredAssociationNotAllowed, entityType, pd.Name));
}
// Throw if the association member has a explicit RoundtripOriginalAttribute on it
if (pd.ExplicitAttributes()[typeof(RoundtripOriginalAttribute)] != null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_RoundTripOriginal, pd.Name, entityType));
}
// if the other entity is also exposed by the service, perform additional validation
if (this._entityTypes.Contains(otherEntityType))
{
PropertyDescriptorCollection otherEntityProperties = TypeDescriptor.GetProperties(otherEntityType);
PropertyDescriptor otherMember = otherEntityProperties.Cast<PropertyDescriptor>().FirstOrDefault(p => p.Name != pd.Name && p.Attributes.OfType<AssociationAttribute>().Any(a => a.Name == assocName));
if (otherMember != null)
{
// Bi-directional association
// make sure IsForeignKey is set to true on one and only one side of the association
AssociationAttribute otherAssocAttrib = (AssociationAttribute)otherMember.Attributes[typeof(AssociationAttribute)];
if (otherAssocAttrib != null &&
!((assocAttrib.IsForeignKey != otherAssocAttrib.IsForeignKey)
&& (assocAttrib.IsForeignKey || otherAssocAttrib.IsForeignKey)))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidAssociation_IsFKInvalid, assocName, entityType));
}
Type otherMemberEntityType = TypeUtility.GetElementType(otherMember.PropertyType);
// Verify that the type of the corresponding association points back to this entity
// The type of the corresponding association can be one of the parents of the entity, but it cannot be one of its children.
if (!otherMemberEntityType.IsAssignableFrom(entityType))
//.........这里部分代码省略.........