本文整理汇总了C#中ICustomTypeDescriptor.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# ICustomTypeDescriptor.GetProperties方法的具体用法?C# ICustomTypeDescriptor.GetProperties怎么用?C# ICustomTypeDescriptor.GetProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICustomTypeDescriptor
的用法示例。
在下文中一共展示了ICustomTypeDescriptor.GetProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldRegister
/// <summary>
/// Determines whether a type uses any features requiring the
/// <see cref="DataControllerTypeDescriptor"/> to be registered. We do this
/// check as an optimization so we're not adding additional TDPs to the
/// chain when they're not necessary.
/// </summary>
/// <param name="descriptor">The descriptor for the type to check.</param>
/// <param name="keyIsEditable">Indicates whether the key for this Type is editable.</param>
/// <param name="foreignKeyMembers">The set of foreign key members for the Type.</param>
/// <returns>Returns <c>true</c> if the type uses any features requiring the
/// <see cref="DataControllerTypeDescriptionProvider"/> to be registered.</returns>
internal static bool ShouldRegister(ICustomTypeDescriptor descriptor, bool keyIsEditable, HashSet<string> foreignKeyMembers)
{
return descriptor.GetProperties()
.OfType<PropertyDescriptor>()
.Any(
propertyDescriptor =>
ShouldInferAttributes(propertyDescriptor, keyIsEditable, foreignKeyMembers)
);
}
示例2: ComponentImporter
public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor)
{
if (type == null)
throw new ArgumentNullException("type");
_type = type;
_properties = typeDescriptor == null ?
TypeDescriptor.GetProperties(type) :
typeDescriptor.GetProperties();
}
示例3: SimpleTableProvider
public SimpleTableProvider(DataModelProvider modelProvider, ICustomTypeDescriptor descriptor)
: base(modelProvider) {
if (descriptor == null) {
throw new ArgumentNullException("descriptor");
}
_descriptor = descriptor;
Name = descriptor.GetClassName();
DataContextPropertyName = String.Empty;
InitializeColumns(descriptor.GetProperties());
}
示例4: GetNamedPropertyValue
/// <summary>
/// Gets the value of an ICustomTypeDescriptor
/// implementation's named property.
/// </summary>
/// <param name="item">
/// The ICustomTypeDescriptor implementation, from
/// which to extract a named property's value.
/// </param>
/// <param name="propertyName">
/// The name of the property.
/// </param>
/// <param name="usesCaseSensitivePropertyNameMatch">
/// A value indicating whether the property name match should be
/// case-sensitive.
/// </param>
/// <param name="exceptionThrownIfNoMatch">
/// A value indicating whether an exception should be thrown if
/// no matching property can be found.
/// </param>
/// <returns>
/// The value of the property named by propertyName on item,
/// or a null reference if exceptionThrownIfNoMatch is false and
/// propertyName does not name a property on item.
/// </returns>
private static object GetNamedPropertyValue(
ICustomTypeDescriptor item,
string propertyName,
bool usesCaseSensitivePropertyNameMatch,
bool exceptionThrownIfNoMatch)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
if (string.IsNullOrEmpty("propertyName"))
{
throw new ArgumentException("propertyName is a null reference or empty string.", "propertyName");
}
StringComparison comparisonType = StringComparison.CurrentCultureIgnoreCase;
if (usesCaseSensitivePropertyNameMatch)
{
comparisonType = StringComparison.CurrentCulture;
}
PropertyDescriptor descriptor = default(PropertyDescriptor);
foreach (PropertyDescriptor pd in item.GetProperties())
{
if (string.Equals(propertyName, pd.Name, comparisonType))
{
descriptor = pd;
break;
}
}
if (descriptor == default(PropertyDescriptor))
{
if (exceptionThrownIfNoMatch)
{
throw new ArgumentException("propertyName does not name a property on item.", "propertyName");
}
else
{
return null;
}
}
else
{
return descriptor.GetValue(item);
}
}
示例5: ExportRecord
internal static void ExportRecord(ExportContext context, ICustomTypeDescriptor record, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(record != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
foreach (PropertyDescriptor property in record.GetProperties())
{
writer.WriteMember(property.Name);
context.Export(property.GetValue(record), writer);
}
writer.WriteEndObject();
}
示例6: GetTypeDescriptor
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{
if (objectType == null && instance != null)
{
objectType = instance.GetType();
}
if (_type != objectType)
{
// In inheritance scenarios, we might be called to provide a descriptor
// for a derived Type. In that case, we just return base.
return base.GetTypeDescriptor(objectType, instance);
}
if (_customTypeDescriptor == null)
{
// CLR, buddy class type descriptors
_customTypeDescriptor = base.GetTypeDescriptor(objectType, instance);
// EF, any other custom type descriptors provided through MetadataProviders.
_customTypeDescriptor = _metadataProvider.GetTypeDescriptor(objectType, _customTypeDescriptor);
// initialize FK members AFTER our type descriptors have chained
HashSet<string> foreignKeyMembers = GetForeignKeyMembers();
// if any FK member of any association is also part of the primary key, then the key cannot be marked
// Editable(false)
bool keyIsEditable = false;
foreach (PropertyDescriptor pd in _customTypeDescriptor.GetProperties())
{
if (pd.Attributes[typeof(KeyAttribute)] != null &&
foreignKeyMembers.Contains(pd.Name))
{
keyIsEditable = true;
break;
}
}
if (DataControllerTypeDescriptor.ShouldRegister(_customTypeDescriptor, keyIsEditable, foreignKeyMembers))
{
// Extend the chain with one more descriptor.
_customTypeDescriptor = new DataControllerTypeDescriptor(_customTypeDescriptor, keyIsEditable, foreignKeyMembers);
}
}
return _customTypeDescriptor;
}
示例7: GetPropertyValidators
private IEnumerable<PropertyValidator> GetPropertyValidators(ICustomTypeDescriptor typeDescriptor)
{
var propertyDescriptors =
typeDescriptor.GetProperties();
foreach (PropertyDescriptor descriptor in propertyDescriptors)
{
var attributes =
descriptor.Attributes.OfType<ValidationAttribute>();
var validator =
new PropertyValidator
{
AttributeAdaptors = this.GetAttributeAdaptors(attributes),
Descriptor = descriptor
};
yield return validator;
}
}
示例8: BuildDataObject
internal static object BuildDataObject(object dataObject, ICustomTypeDescriptor typeDescriptor, IDictionary inputParameters) {
Dictionary<string, Exception> convertOrValidateExceptions = null;
PropertyDescriptorCollection props = typeDescriptor.GetProperties();
foreach (DictionaryEntry de in inputParameters) {
string propName = (de.Key == null ? String.Empty : de.Key.ToString());
PropertyDescriptor property = props.Find(propName, /*ignoreCase*/true);
// NOTE: No longer throws when a property is not found or is read only. This makes
// Delete, Insert and Update operations more optimistic, allowing scenarios such as:
// 1) Deletes and Updates after projecting data in the Selecting event.
// 2) Deletes and Updates after selecting children of the data object type in the
// Selecting event.
if ((property != null) && (!property.IsReadOnly)) {
try {
object value = BuildObjectValue(de.Value, property.PropertyType, propName);
property.SetValue(dataObject, value);
}
catch (Exception e) {
if (convertOrValidateExceptions == null) {
convertOrValidateExceptions = new Dictionary<string, Exception>(
StringComparer.OrdinalIgnoreCase);
}
convertOrValidateExceptions[property.Name] = e;
}
}
}
// package up conversion or dlinq validation exceptions into single exception.
if (convertOrValidateExceptions != null) {
// Include the text of the first exception as part of the full exception,
// to make it less cryptic in scenarios where it gets shown.
throw new LinqDataSourceValidationException(String.Format(CultureInfo.InvariantCulture,
"AtlasWeb.LinqDataSourceView_ValidationFailed", typeDescriptor.GetClassName(), convertOrValidateExceptions.Values.First().Message),
convertOrValidateExceptions);
}
return dataObject;
}
示例9: ShouldRegister
/// <summary>
/// Determines whether a type uses any features requiring the
/// <see cref="DomainControllerTypeDescriptor"/> to be registered. We do this
/// check as an optimization so we're not adding additional TDPs to the
/// chain when they're not necessary.
/// </summary>
/// <param name="descriptor">The descriptor for the type to check.</param>
/// <param name="keyIsEditable">Indicates whether the key for this Type is editable.</param>
/// <param name="foreignKeyMembers">The set of foreign key members for the Type.</param>
/// <returns>Returns <c>true</c> if the type uses any features requiring the
/// <see cref="DomainControllerTypeDescriptionProvider"/> to be registered.</returns>
internal static bool ShouldRegister(ICustomTypeDescriptor descriptor, bool keyIsEditable, HashSet<string> foreignKeyMembers)
{
foreach (PropertyDescriptor pd in descriptor.GetProperties())
{
// If there are any attributes that should be inferred for this member, then
// we will register the descriptor
if (ShouldInferAttributes(pd, keyIsEditable, foreignKeyMembers))
{
return true;
}
}
return false;
}
示例10: ExtractPropertyValueModels
private static IEnumerable<DevicePropertyValueModel> ExtractPropertyValueModels(
ICustomTypeDescriptor deviceProperties)
{
DevicePropertyValueModel currentData;
object currentValue;
Dictionary<string, DevicePropertyMetadata> devicePropertyIndex;
int editableOrdering;
bool isDisplayedRegistered;
bool isDisplayedUnregistered;
bool isEditable;
int nonediableOrdering;
DevicePropertyMetadata propertyMetadata;
Debug.Assert(deviceProperties != null, "deviceProperties is a null reference.");
devicePropertyIndex = GetDevicePropertyConfiguration().ToDictionary(t => t.Name);
// For now, display r/o properties first.
editableOrdering = 1;
nonediableOrdering = int.MinValue;
foreach (PropertyDescriptor prop in deviceProperties.GetProperties())
{
if (devicePropertyIndex.TryGetValue(prop.Name, out propertyMetadata))
{
isDisplayedRegistered = propertyMetadata.IsDisplayedForRegisteredDevices;
isDisplayedUnregistered = propertyMetadata.IsDisplayedForUnregisteredDevices;
isEditable = propertyMetadata.IsEditable;
}
else
{
isDisplayedRegistered = isEditable = true;
isDisplayedUnregistered = false;
}
if (!isDisplayedRegistered && !isDisplayedUnregistered)
{
continue;
}
// Mark R/O properties as not-ediable.
if (prop.IsReadOnly)
{
isEditable = false;
}
currentData = new DevicePropertyValueModel()
{
Name = prop.Name,
PropertyType = propertyMetadata.PropertyType
};
if (isEditable)
{
currentData.IsEditable = true;
currentData.DisplayOrder = editableOrdering++;
}
else
{
currentData.IsEditable = false;
currentData.DisplayOrder = nonediableOrdering++;
}
currentData.IsIncludedWithUnregisteredDevices = isDisplayedUnregistered;
currentValue = prop.GetValue(deviceProperties);
if (currentValue == null)
{
currentData.Value = string.Empty;
}
else
{
currentData.Value = string.Format(CultureInfo.InvariantCulture, "{0}", currentValue);
}
yield return currentData;
}
}
示例11: ApplyPropertyValueModels
private static void ApplyPropertyValueModels(
ICustomTypeDescriptor deviceProperties,
IEnumerable<DevicePropertyValueModel> devicePropertyValueModels)
{
Dictionary<string, DevicePropertyMetadata> devicePropertyIndex;
Dictionary<string, PropertyDescriptor> propIndex;
PropertyDescriptor propDesc;
DevicePropertyMetadata propMetadata;
Debug.Assert(deviceProperties != null, "deviceProperties is a null reference.");
Debug.Assert(devicePropertyValueModels != null, "devicePropertyValueModels is a null reference.");
devicePropertyIndex = GetDevicePropertyConfiguration().ToDictionary(t => t.Name);
propIndex = new Dictionary<string, PropertyDescriptor>();
foreach (PropertyDescriptor pd in deviceProperties.GetProperties())
{
propIndex[pd.Name] = pd;
}
foreach (DevicePropertyValueModel propVal in devicePropertyValueModels)
{
if ((propVal == null) || string.IsNullOrEmpty(propVal.Name))
{
continue;
}
// Pass through properties that don't have a specified
// configuration.
if (devicePropertyIndex.TryGetValue(propVal.Name, out propMetadata) && !propMetadata.IsEditable)
{
continue;
}
if (!propIndex.TryGetValue(propVal.Name, out propDesc) || propDesc.IsReadOnly)
{
continue;
}
propDesc.SetValue(deviceProperties, propVal.Value);
}
}
示例12: ComponentExporter
public ComponentExporter(Type inputType, ICustomTypeDescriptor typeDescriptor) : this(inputType, (typeDescriptor != null) ? typeDescriptor.GetProperties() : new Maticsoft.Json.Conversion.CustomTypeDescriptor(inputType).GetProperties())
{
}
示例13: GetDisplayValue
/// <summary>
/// Gets the display value of an item based on the provided ICustomTypeDescriptor.
/// </summary>
/// <param name="ictd">Custom type descriptor.</param>
/// <param name="value">Current value of the combo.</param>
/// <returns>Value of the specified custom type descriptor.</returns>
public object GetDisplayValue(ICustomTypeDescriptor ictd, object value)
{
if (this.DataSource != null)
{
object holdValue, holdDisplay;
if (!string.IsNullOrEmpty(this.DisplayMember))
{
foreach (object o in this.Items)
{
holdValue = ictd.GetProperties().Find((string.IsNullOrEmpty(this.ValueMember) ? this.DisplayMember : this.ValueMember), true).GetValue(ictd);
holdDisplay = ictd.GetProperties().Find((string.IsNullOrEmpty(this.DisplayMember) ? this.ValueMember : this.DisplayMember), true).GetValue(ictd);
if (holdValue.Equals(value))
{
return holdDisplay;
}
}
}
}
// Return value if we didn't find a match.
return value;
}
示例14: HyperTypeDescriptor
internal HyperTypeDescriptor(ICustomTypeDescriptor parent, Type objectType)
: base(parent)
{
propertyCollection = WrapProperties(parent.GetProperties(), objectType);
}
示例15: ComponentExporter
public ComponentExporter(Type inputType, ICustomTypeDescriptor typeDescriptor) :
this(inputType, typeDescriptor != null ?
typeDescriptor.GetProperties() : (new CustomTypeDescriptor(inputType)).GetProperties()) {}