本文整理汇总了C#中IReflect类的典型用法代码示例。如果您正苦于以下问题:C# IReflect类的具体用法?C# IReflect怎么用?C# IReflect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IReflect类属于命名空间,在下文中一共展示了IReflect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildLoggerInjectors
private static IEnumerable<Action<IComponentContext, object>> BuildLoggerInjectors(IReflect componentType)
{
// look for settable properties of type "ILogger"
var loggerProperties = componentType
.GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
.Select(p => new
{
PropertyInfo = p,
p.PropertyType,
IndexParameters = p.GetIndexParameters(),
Accessors = p.GetAccessors(false)
})
// must be a logger
.Where(x => x.PropertyType == typeof(ILogger))
// must not be an indexer
.Where(x => x.IndexParameters.Count() == 0)
// must have get/set, or only set
.Where(x => x.Accessors.Length != 1 || x.Accessors[0].ReturnType == typeof(void));
// return an IEnumerable of actions that resolve a logger and assign the property
return loggerProperties
.Select(entry => entry.PropertyInfo)
.Select(propertyInfo => (Action<IComponentContext, object>)((ctx, instance) =>
{
var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
propertyInfo.SetValue(instance, propertyValue, null);
}));
}
示例2: GetPropertyCaseInsensitive
private static PropertyInfo GetPropertyCaseInsensitive(IReflect type, string propertyName)
{
// make the property reflection lookup case insensitive
const BindingFlags bindingFlags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
return type.GetProperty(propertyName, bindingFlags);
}
示例3: AssignmentCompatible
internal bool AssignmentCompatible(IReflect lhir, bool reportError){
if (lhir == Typeob.Object || lhir == Typeob.Array || lhir is ArrayObject) return true;
IReflect target_element_ir;
if (lhir == Typeob.Array)
target_element_ir = Typeob.Object;
else if (lhir is TypedArray){
TypedArray tArr = ((TypedArray)lhir);
if (tArr.rank != 1){
this.context.HandleError(JSError.TypeMismatch, reportError);
return false;
}
target_element_ir = tArr.elementType;
}else if (lhir is Type && ((Type)lhir).IsArray){
Type t = ((Type)lhir);
if (t.GetArrayRank() != 1){
this.context.HandleError(JSError.TypeMismatch, reportError);
return false;
}
target_element_ir = t.GetElementType();
}else
return false;
for (int i = 0, n = this.elements.count; i < n; i++)
if (!Binding.AssignmentCompatible(target_element_ir, this.elements[i], this.elements[i].InferType(null), reportError))
return false;
return true;
}
示例4: HtmlToClrEventProxy
public HtmlToClrEventProxy(object sender, string eventName, EventHandler eventHandler)
{
this.eventHandler = eventHandler;
this.eventName = eventName;
System.Type type = typeof(HtmlToClrEventProxy);
this.typeIReflectImplementation = type;
}
示例5: InternalAccessibleObject
internal InternalAccessibleObject(AccessibleObject accessibleImplemention)
{
this.publicIAccessible = accessibleImplemention;
this.publicIEnumVariant = accessibleImplemention;
this.publicIOleWindow = accessibleImplemention;
this.publicIReflect = accessibleImplemention;
}
示例6: GetDefaultMembers
private static MemberInfo[] GetDefaultMembers(Type typ, IReflect objIReflect, ref string DefaultName)
{
MemberInfo[] nonGenericMembers;
if (typ == objIReflect)
{
do
{
object[] customAttributes = typ.GetCustomAttributes(typeof(DefaultMemberAttribute), false);
if ((customAttributes != null) && (customAttributes.Length != 0))
{
DefaultName = ((DefaultMemberAttribute) customAttributes[0]).MemberName;
nonGenericMembers = GetNonGenericMembers(typ.GetMember(DefaultName, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase));
if ((nonGenericMembers != null) && (nonGenericMembers.Length != 0))
{
return nonGenericMembers;
}
DefaultName = "";
return null;
}
typ = typ.BaseType;
}
while (typ != null);
DefaultName = "";
return null;
}
nonGenericMembers = GetNonGenericMembers(objIReflect.GetMember("", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase));
if ((nonGenericMembers == null) || (nonGenericMembers.Length == 0))
{
DefaultName = "";
return null;
}
DefaultName = nonGenericMembers[0].Name;
return nonGenericMembers;
}
示例7: HtmlToClrEventProxy
public HtmlToClrEventProxy(object sender, string eventName, EventHandler eventHandler) {
this.eventHandler = eventHandler;
this.eventName = eventName;
Type htmlToClrEventProxyType = typeof(HtmlToClrEventProxy);
typeIReflectImplementation = htmlToClrEventProxyType as IReflect;
}
示例8: DefaultEnvironmentProvider
/// <summary>
/// Initializes a new instance of the <see cref="DefaultEnvironmentProvider"/> class.
/// </summary>
/// <param name="supportedType">A <see cref="IReflect"/> of a object with the supported Environment Aliases on.</param>
protected DefaultEnvironmentProvider(IReflect supportedType)
{
this.SupportedAliases = supportedType
.GetFields(BindingFlags.Static | BindingFlags.Public)
.Where(f => f.IsLiteral)
.Select(a => a.GetValue(supportedType) as string)
.ToArray();
}
示例9: VsaNamedItemScope
internal VsaNamedItemScope(Object hostObject, ScriptObject parent, VsaEngine engine)
: base(parent){
this.namedItem = hostObject;
if ((this.reflectObj = hostObject as IReflect) == null)
this.reflectObj = hostObject.GetType();
this.recursive = false;
this.engine = engine;
}
示例10: CompareTypes
private static IEnumerable<string> CompareTypes(IReflect type1, IReflect type2, BindingFlags bindingFlags)
{
MethodInfo[] typeTMethodInfo = type1.GetMethods(bindingFlags);
MethodInfo[] typeXMethodInfo = type2.GetMethods(bindingFlags);
return typeTMethodInfo.Select(x => x.Name)
.Except(typeXMethodInfo.Select(x => x.Name));
}
示例11: LookupResource
public static string LookupResource(IReflect resourceManagerProvider, string resourceKey)
{
PropertyInfo property = resourceManagerProvider.GetProperty(resourceKey, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
// Fallback with the key name
if (property == null)
return resourceKey;
return (string) property.GetValue(null, null); // returns string directly from res file
}
示例12: FormatPropertiesResolver
public FormatPropertiesResolver(IReflect type, IPropertyFormatInfoProvider formatInfoProvider)
{
this.formatInfoProvider = formatInfoProvider;
PropertiesFormat =
type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(prop => prop.CanRead)
.Select(ConvertToPropertyFormat)
.Where(pform => pform != null);
}
示例13: FindUserProperty
private static PropertyInfo FindUserProperty(IReflect type)
{
//寻找类型为 "Localizer" 并且具有set方法的属性。
return type
.GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.PropertyType == typeof(Localizer)) //必须是一个本地化委托
.Where(x => !x.GetIndexParameters().Any()) //没有索引器
.FirstOrDefault(x => x.GetAccessors(false).Length != 1 || x.GetAccessors(false)[0].ReturnType == typeof(void)); //必须具有set方法。
}
示例14: GetFieldByPropertyName
private static FieldInfo GetFieldByPropertyName(IReflect viewModelType, string propertyName)
{
var charList = new List<char> { char.ToLower(propertyName[0]) };
charList.AddRange(propertyName.Substring(1));
var fieldName = new string(charList.ToArray());
var field = viewModelType.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
return field;
}
示例15: HtmlEventProxy
// private CTOR
private HtmlEventProxy(string eventName, IHTMLElement2 htmlElement, EventHandler eventHandler)
{
this.eventName = eventName;
this.htmlElement = htmlElement;
this.sender = this;
this.eventHandler = eventHandler;
Type type = typeof(HtmlEventProxy);
this.typeIReflectImplementation = type;
}