本文整理汇总了C#中System.ComponentModel.PropertyDescriptorCollection.Find方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDescriptorCollection.Find方法的具体用法?C# PropertyDescriptorCollection.Find怎么用?C# PropertyDescriptorCollection.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.PropertyDescriptorCollection
的用法示例。
在下文中一共展示了PropertyDescriptorCollection.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddGraphicProperties
public static void AddGraphicProperties(List<PropertyDescriptor> allProperties,
PropertyDescriptorCollection props)
{
PropertyDescriptor prop = null;
prop = props.Find("ForeColor",true);
allProperties.Add(prop);
prop = props.Find("DashStyle",true);
allProperties.Add(prop);
prop = props.Find("Thickness",true);
allProperties.Add(prop);
}
示例2: AddTextBasedProperties
public static void AddTextBasedProperties(List<PropertyDescriptor> allProperties,
PropertyDescriptorCollection props)
{
PropertyDescriptor prop = props.Find("Font",true);
allProperties.Add(prop);
prop = props.Find("FormatString",true);
allProperties.Add(prop);
prop = props.Find("StringTrimming",true);
allProperties.Add(prop);
prop = props.Find("ContentAlignment",true);
allProperties.Add(prop);
prop = props.Find("TextAlignment",true);
allProperties.Add(prop);
prop = props.Find("CanGrow",true);
allProperties.Add(prop);
prop = props.Find("CanShrink",true);
allProperties.Add(prop);
prop = props.Find("DataType",true);
allProperties.Add(prop);
}
示例3: FilterProperties
/*
* Does the property filtering...
*/
private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc)
{
ArrayList toRemove = new ArrayList();
PropertyDescriptor pd = pdc.Find("fileAction", true);
if (pd != null)
{
object val = pd.GetValue(this);
if (val != null)
{
if ((PGPFileAction)val == PGPFileAction.Decrypt)
foreach (string s in invalidDecrypt)
toRemove.Add(s);
else if ((PGPFileAction)val == PGPFileAction.Encrypt)
foreach (string s in invalidEncrypt)
toRemove.Add(s);
}
}
PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
foreach (PropertyDescriptor p in pdc)
if (!toRemove.Contains(p.Name))
adjustedProps.Add(p);
return adjustedProps;
}
示例4: AddDefaultProperties
public static void AddDefaultProperties (List<PropertyDescriptor> allProperties,
PropertyDescriptorCollection props )
{
PropertyDescriptor prop = props.Find("Location",true);
allProperties.Add(prop);
prop = props.Find("Size",true);
allProperties.Add(prop);
prop = props.Find("BackColor",true);
allProperties.Add(prop);
// need this for Contextmenu's
prop = props.Find("ContextMenu",true);
allProperties.Add(prop);
}
示例5: ExtractIndexDataFromDocument
private IEnumerable<AbstractField> ExtractIndexDataFromDocument(PropertyDescriptorCollection properties, object doc, out string newDocId)
{
if (properties == null)
{
properties = TypeDescriptor.GetProperties(doc);
}
newDocId = properties.Find("__document_id", false).GetValue(doc) as string;
return AnonymousObjectToLuceneDocumentConverter.Index(doc, properties, indexDefinition, Field.Store.NO);
}
示例6: GetPropertyDescriptor
/// <summary>
/// Retrieves a property descriptor from its name.
/// </summary>
/// <param name="propertyName">the name of a property</param>
/// <param name="collection">the property collection to search</param>
/// <returns>the corresponding property descriptor</returns>
/// <exception cref="InvalidPropertyException"> if the property does not exist</exception>
private PropertyDescriptor GetPropertyDescriptor(string propertyName, PropertyDescriptorCollection collection)
{
var property = collection.Find(propertyName, true);
if (property == null)
{
throw new InvalidPropertyException(string.Format("Invalid property {0} on type {1}", propertyName, _wrappedInstance.GetType()),
_wrappedInstance.GetType(), propertyName);
}
return property;
}
示例7: GetProperties
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptor pd;
var pdc = new PropertyDescriptorCollection(base.GetProperties(attributes).Cast<PropertyDescriptor>().ToArray());
if ((pd = pdc.Find("Source", false)) != null)
{
pdc.Add(TypeDescriptor.CreateProperty(typeof(Binding), pd, new Attribute[] { new DefaultValueAttribute("null") }));
pdc.Remove(pd);
}
return pdc;
}
示例8: Find_Name_Null
public void Find_Name_Null ()
{
PropertyDescriptorCollection descriptors;
descriptors = new PropertyDescriptorCollection (
new PropertyDescriptor[] { new MockPropertyDescriptor ("A", 1),
new MockPropertyDescriptor ("b", 2)});
try {
descriptors.Find (null, false);
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsNotNull (ex.ParamName, "#A5");
}
try {
descriptors.Find (null, true);
Assert.Fail ("#B1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.IsNotNull (ex.ParamName, "#B5");
}
descriptors = PropertyDescriptorCollection.Empty;
try {
descriptors.Find (null, false);
Assert.Fail ("#C1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
Assert.IsNull (ex.InnerException, "#C3");
Assert.IsNotNull (ex.Message, "#C4");
Assert.IsNotNull (ex.ParamName, "#C5");
}
try {
descriptors.Find (null, true);
Assert.Fail ("#D1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
Assert.IsNull (ex.InnerException, "#D3");
Assert.IsNotNull (ex.Message, "#D4");
Assert.IsNotNull (ex.ParamName, "#D5");
}
}
示例9: ConvertPropertys
private PropertyDescriptorCollection ConvertPropertys(PropertyDescriptorCollection pdc)
{
PropertyDescriptor pd = pdc.Find("ItemsSource", false);
if (pd != null)
{
PropertyDescriptor pdNew = TypeDescriptor.CreateProperty(typeof(ItemsControl), pd, new Attribute[]
{
new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible),
new DefaultValueAttribute("")
});
pdc.Add(pdNew);
pdc.Remove(pd);
}
return pdc;
}
示例10: FilterProperties
/*
* Does the property filtering...
*/
private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc)
{
ArrayList toRemove = new ArrayList();
/* Hide invalid File Actions */
PropertyDescriptor pd = pdc.Find("fileAction", true);
if (pd != null)
{
object val = pd.GetValue(this);
if (val != null)
{
if((ZipFileAction)val == ZipFileAction.Decompress)
foreach (string s in invalidDeCompress)
toRemove.Add(s);
}
}
/* Hide Compression types */
PropertyDescriptor cTypePD = pdc.Find("compressionType", true);
if (cTypePD != null)
{
object val = cTypePD.GetValue(this);
if (val != null)
{
if ((CompressionType)val == CompressionType.Zip)
foreach (string s in invalidZip)
toRemove.Add(s);
else if ((CompressionType)val == CompressionType.Tar)
foreach (string s in invalidTar)
toRemove.Add(s);
}
}
PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
foreach (PropertyDescriptor p in pdc)
if (!toRemove.Contains(p.Name))
adjustedProps.Add(p);
return adjustedProps;
}
示例11: ExtractIndexDataFromDocument
private IndexingResult ExtractIndexDataFromDocument(AnonymousObjectToLuceneDocumentConverter anonymousObjectToLuceneDocumentConverter, PropertyDescriptorCollection properties, object doc)
{
if (properties == null)
{
properties = TypeDescriptor.GetProperties(doc);
}
var abstractFields = anonymousObjectToLuceneDocumentConverter.Index(doc, properties, indexDefinition, Field.Store.NO).ToList();
return new IndexingResult()
{
Fields = abstractFields,
NewDocId = properties.Find(Constants.DocumentIdFieldName, false).GetValue(doc) as string,
ShouldSkip = properties.Count > 1 // we always have at least __document_id
&& abstractFields.Count == 0
};
}
示例12: ParseTo
/// <summary>
/// Updates object from command-line arguments where
/// <paramref name="properties" /> describes the target object.
/// </summary>
public static string[] ParseTo(IEnumerable<string> args, object target, PropertyDescriptorCollection properties)
{
if (target == null) throw new ArgumentNullException("target");
if (args == null) throw new ArgumentNullException("args");
var tails = new List<string>();
var e = args.GetEnumerator();
while (e.MoveNext())
{
var arg = e.Current;
if (arg.Length == 0) // empty arg?
{
tails.Add(arg);
continue;
}
// Get argument name, Unix or DOS style.
string name;
if (arg[0] == '/') // DOS style
{
name = arg.Substring(1);
}
else if (arg.Length > 1 && arg[0] == '-' && arg[1] == '-') // Unix style
{
if (arg.Length == 2) // comment
break;
name = arg.Substring(2);
}
else
{
tails.Add(arg); // anonymous argument
continue;
}
// Is the argument name and value paired in one?
// Allows `arg=value` or `arg:value` style.
var paired = name.IndexOfAny(_argSeparators) > 0;
var pair = name.Split(_argSeparators, (n, v) => new { Name = n, Value = v });
if (paired)
name = pair.Name; // Break the name out of the pair
// Get setting property from name.
var propertyName = name.Replace("-", " ")
.ToTitleCaseInvariant()
.Replace(" ", string.Empty);
if (properties == null)
properties = TypeDescriptor.GetProperties(target);
var property = properties.Find(propertyName, true);
if (property == null)
throw new FormatException(string.Format("Unknown command-line argument: " + name));
// Process argument based on property type.
var type = property.PropertyType;
object value;
if (type == typeof(bool)) // Boolean?
{
value = true; // flag-style
}
else
{
// If value was paired with name then break out the value
// from the pair other read it from the next argument.
if (paired)
{
value = pair.Value;
}
else
{
if (!e.MoveNext())
throw new FormatException("Missing value for command-line argument: " + name);
value = e.Current;
}
// If property is of another type than string and it
// support conversion then do that now.
if (type != typeof(string))
{
var converter = property.Converter ?? TypeDescriptor.GetConverter(type);
if (!converter.CanConvertFrom(typeof(string)))
throw new FormatException("Unsupported command-line argument:" + name);
//.........这里部分代码省略.........
示例13: ServerObjectParsingObject
public ServerObjectParsingObject(Type type, Hashtable attributes, string tagid, ParsingObject parent)
: base (tagid, parent)
{
//create the object
if (type.GetInterface ("System.ComponentModel.IComponent") != null)
//note: this automatically adds to parent's container, as some controls
//need to be sited e.g. if they use site dictionaries
//TODO: should this action be passed up the tree so controls can intercept?
obj = ((AspNetEdit.Editor.ComponentModel.DesignerHost) base.DesignerHost).CreateComponent (type, attributes["ID"] as string, false);
else
obj = Activator.CreateInstance (type);
//and populate it from the attributes
pdc = TypeDescriptor.GetProperties (obj);
foreach (DictionaryEntry de in attributes) {
if (0 == string.Compare((string)de.Key, "runat"))
continue;
if (0 == string.Compare((string)de.Key, "ID"))
continue;
//use the dash subproperty syntax
string[] str = ((string)de.Key).Split ('-');
PropertyDescriptor pd = pdc.Find (str[0], true);
//if property not found, try events
if (str.Length == 1 && pd == null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix (str[0].ToLower(), "on")) {
IEventBindingService iebs = (IEventBindingService) DesignerHost.GetService (typeof (IEventBindingService));
if (iebs == null)
throw new Exception ("Could not obtain IEventBindingService from host");
EventDescriptorCollection edc = TypeDescriptor.GetEvents (obj);
EventDescriptor e = edc.Find (str[0].Remove(0,2), true);
if (e != null)
pd = iebs.GetEventProperty(e);
else
throw new Exception ("Could not find event " + str[0].Remove(0,2));
}
object loopObj = obj;
for (int i = 0; i < str.Length; i++ )
{
if (pd == null)
throw new Exception ("Could not find property " + (string)de.Key);
if (i == str.Length - 1) {
pd.SetValue (obj, pd.Converter.ConvertFromString ((string) de.Value));
break;
}
loopObj = pd.GetValue (loopObj);
pd = TypeDescriptor.GetProperties (loopObj).Find (str[0], true);
}
}
parseAtt = TypeDescriptor.GetAttributes (obj)[typeof(ParseChildrenAttribute )] as ParseChildrenAttribute;
//FIXME: fix this in MCS classlib
if (parseAtt.DefaultProperty.Length == 0)
parseAtt = null;
//work out how we're trying to parse the children
if (parseAtt != null) {
if (parseAtt.DefaultProperty != null) {
PropertyDescriptor pd = pdc[parseAtt.DefaultProperty];
if (pd == null)
throw new Exception ("Default property does not exist");
if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
mode = ParseChildrenMode.DefaultCollectionProperty;
else
mode = ParseChildrenMode.DefaultProperty;
}
else if (parseAtt.ChildrenAsProperties)
mode = ParseChildrenMode.Properties;
else
mode = ParseChildrenMode.Controls;
}
else {
//FIXME: these are actually persistence hints, but ParseChildrenAttribute doesn't always exist.
//FIXME: logic would be dodgy with bad input
parseAtt = ParseChildrenAttribute.Default;
mode = ParseChildrenMode.Controls;
foreach (PropertyDescriptor pd in pdc) {
PersistenceModeAttribute modeAttrib = pd.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute;
if (modeAttrib == null) return;
switch (modeAttrib.Mode) {
case PersistenceMode.Attribute:
continue;
case PersistenceMode.EncodedInnerDefaultProperty:
parseAtt.DefaultProperty = pd.Name;
mode = ParseChildrenMode.DefaultEncodedProperty;
break;
case PersistenceMode.InnerDefaultProperty:
parseAtt.DefaultProperty = pd.Name;
if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
mode = ParseChildrenMode.DefaultCollectionProperty;
else
mode = ParseChildrenMode.DefaultProperty;
break;
case PersistenceMode.InnerProperty:
//.........这里部分代码省略.........
示例14: ModifyDynamicProperties
/// <summary>
/// This is a callback function for DynamicTypeDescriptionProvider.
/// You can modify the collection in this method.
/// Things you can do in this method:
/// Hide a property
/// Show a property
/// Add/Remove attributes of a property
/// Create a new property on the fly
///
/// More info: http://www.codeproject.com/KB/grid/PropertyGridDynamicProp.aspx
/// </summary>
/// <param name="pdc"></param>
public void ModifyDynamicProperties(PropertyDescriptorCollection pdc)
{
PropertyDescriptor pd = pdc.Find("SourcePath", false);
pdc.Remove(pd);
switch (DecodingMode)
{
case JobDecodingMode.SingleDecoding:
pdc.Add(TypeDescriptor.CreateProperty(
this.GetType(),
pd,
new EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(UITypeEditor))
));
break;
case JobDecodingMode.BatchDecoding:
pdc.Add(TypeDescriptor.CreateProperty(
this.GetType(),
pd,
new EditorAttribute(typeof(FolderEditor), typeof(UITypeEditor))
));
break;
}
pd = pdc.Find("FilterText", false);
pdc.Remove(pd);
pdc.Add(TypeDescriptor.CreateProperty(this.GetType(), pd, new ReadOnlyAttribute(!IsFilterActive)));
pd = pdc.Find("FormatterSettings", false);
pdc.Remove(pd);
pdc.Add(TypeDescriptor.CreateProperty(this.GetType(), pd, new ReadOnlyAttribute(!IsFormatterActive)));
}
示例15: GetPropertyDescriptorValue
private static object GetPropertyDescriptorValue(object value, string name, PropertyDescriptorCollection props)
{
PropertyDescriptor propertyDescriptor = props.Find(name, ignoreCase: true);
Debug.Assert(propertyDescriptor != null, "Property descriptor shouldn't be null");
return propertyDescriptor.GetValue(value);
}