本文整理汇总了C#中NativeMethods.GetPropertyAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods.GetPropertyAttributes方法的具体用法?C# NativeMethods.GetPropertyAttributes怎么用?C# NativeMethods.GetPropertyAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeMethods
的用法示例。
在下文中一共展示了NativeMethods.GetPropertyAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetComponentAttributes
internal static Attribute[] GetComponentAttributes(NativeMethods.IManagedPerPropertyBrowsing target, int dispid) {
int cItems = 0;
IntPtr pbstrs = IntPtr.Zero;
IntPtr pvars = IntPtr.Zero;
int hr = target.GetPropertyAttributes(dispid, ref cItems, ref pbstrs, ref pvars);
if (hr != NativeMethods.S_OK || cItems == 0) {
return new Attribute[0];
}
ArrayList attrs = new ArrayList();
string[] attrTypeNames = GetStringsFromPtr(pbstrs, cItems);
Object[] varParams = GetVariantsFromPtr(pvars, cItems);
Debug.Assert(attrTypeNames.Length == varParams.Length, "Mismatched parameter and attribute name length");
if (attrTypeNames.Length != varParams.Length) {
return new Attribute[0];
}
// get the types
Type[] types = new Type[attrTypeNames.Length];
for (int i = 0; i < attrTypeNames.Length; i++) {
string attrName = attrTypeNames[i];
// try the name first
Type t = Type.GetType(attrName);
Assembly a = null;
if (t != null) {
a = t.Assembly;
}
if (t == null) {
// check for an assembly name.
//
string assemblyName = "";
int comma = attrName.LastIndexOf(',');
if (comma != -1) {
assemblyName = attrName.Substring(comma);
attrName = attrName.Substring(0, comma);
}
string fieldName;
int lastDot = attrName.LastIndexOf('.');
if (lastDot != -1) {
fieldName = attrName.Substring(lastDot + 1);
}
else {
// somethings odd
Debug.Fail("No dot in class name?");
continue;
}
// try to get the field value
if (a == null) {
t = Type.GetType(attrName.Substring(0,lastDot) + assemblyName);
}
else {
t = a.GetType(attrName.Substring(0,lastDot) + assemblyName);
}
if (t == null){
Debug.Fail("Failed load attribute '" + attrName + assemblyName + "'. It's Type could not be found.");
continue;
}
Debug.Assert(typeof(Attribute).IsAssignableFrom(t), "Attribute type " + t.FullName + " does not derive from Attribute");
if (!typeof(Attribute).IsAssignableFrom(t)) {
continue;
}
if (t != null) {
FieldInfo fi = t.GetField(fieldName);
// only if it's static
if (fi != null && fi.IsStatic) {
Object fieldValue = fi.GetValue(null);
if (fieldValue is Attribute) {
// add it to the list
attrs.Add(fieldValue);
continue;
}
}
else {
Debug.Fail("Couldn't load field '" + fieldName + "' from type '" + attrName.Substring(0,lastDot) + "'. It does not exist or is not static");
}
}
}
Debug.Assert(typeof(Attribute).IsAssignableFrom(t), "Attribute type " + t.FullName + " does not derive from Attribute");
if (!typeof(Attribute).IsAssignableFrom(t)) {
continue;
//.........这里部分代码省略.........