/// <summary> /// Validate if that member m should be logged, i.e. it must have a ToLog annotation /// and be a field or a parameterless method. /// Also it may return an instance of GetterField or GetterMethod. /// </summary> protected virtual bool ShouldLog(MemberInfo m, out IGetter getter) { getter = null; /** * Check if it is annotated with ToLog */ if (!Attribute.IsDefined(m, typeof(ToLogAttribute))) { return(false); } /** * Check if it is a Field */ if (m.MemberType == MemberTypes.Field) { getter = new GetterField((FieldInfo)m); return(true); } /** * Check if it is a parameterless method */ if (m.MemberType == MemberTypes.Method && (m as MethodInfo).GetParameters().Length == 0) { getter = new GetterMethod((MethodInfo)m); return(true); } return(false); }
protected virtual bool ShoudlLog(MemberInfo m, out IGetter getter) { getter = null; /// /// Check if ToLog annotation exists /// if (!Attribute.IsDefined(m, typeof(ToLogAttribute))) { return(false); } /// /// Check if is a field or parameterless method /// if (m.MemberType == MemberTypes.Field) { getter = new GetterField((FieldInfo)m); return(true); } if (m.MemberType == MemberTypes.Method) { MethodInfo mi = (MethodInfo)m; if (mi.GetParameters().Length == 0) { getter = new GetterMethod((MethodInfo)m); return(true); } } return(false); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public override void DefineMemberBody() { var typedGetterDefinition = (GetterBodyDefinition as Action <IHappilMethodBody <T>, HappilArgument <TIndex1> >); var typedSetterDefinition = (SetterBodyDefinition as Action <IVoidHappilMethodBody, HappilArgument <TIndex1>, HappilArgument <T> >); using (TypeTemplate.CreateScope( typeof(TypeTemplate.TIndex1), OwnerProperty.Declaration.GetIndexParameters()[0].ParameterType)) { if (typedGetterDefinition != null) { using ((GetterMethod as IHappilMember).CreateTypeTemplateScope()) { using (GetterMethod.CreateBodyScope()) { typedGetterDefinition(GetterMethod.GetMethodBody <T>(), new HappilArgument <TIndex1>(GetterMethod, 1)); } } } if (typedSetterDefinition != null) { using ((SetterMethod as IHappilMember).CreateTypeTemplateScope()) { using (SetterMethod.CreateBodyScope()) { typedSetterDefinition(SetterMethod, new HappilArgument <TIndex1>(SetterMethod, 1), new HappilArgument <T>(SetterMethod, 2)); } } } } }
public AvaloniaAttachedInstanceProperty(XamlAstNamePropertyReference prop, TransformerConfiguration config, IXamlType declaringType, IXamlType type, IXamlType avaloniaPropertyType, IXamlType avaloniaObject, IXamlField field) : base(prop, prop.Name, declaringType, null) { _config = config; _declaringType = declaringType; _avaloniaPropertyType = avaloniaPropertyType; // XamlIl doesn't support generic methods yet if (_avaloniaPropertyType.GenericArguments?.Count > 0) { _avaloniaPropertyType = _avaloniaPropertyType.BaseType; } _avaloniaObject = avaloniaObject; _field = field; PropertyType = type; Setters.Add(new SetterMethod(this)); Getter = new GetterMethod(this); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public override void DefineMemberBody() { var typedGetterDefinition = (GetterBodyDefinition as Action <IHappilMethodBody <T> >); var typedSetterDefinition = (SetterBodyDefinition as Action <IVoidHappilMethodBody, HappilArgument <T> >); if (typedGetterDefinition != null) { using ((GetterMethod as IHappilMember).CreateTypeTemplateScope()) { using (GetterMethod.CreateBodyScope()) { typedGetterDefinition(GetterMethod.GetMethodBody <T>()); } } } if (typedSetterDefinition != null) { using ((SetterMethod as IHappilMember).CreateTypeTemplateScope()) { using (SetterMethod.CreateBodyScope()) { typedSetterDefinition(SetterMethod, new HappilArgument <T>(SetterMethod, 1)); } } } }
internal static string NativeGet(GetterMethod <string> getter, [CallerMemberName] string propertyName = "") { string value; var err = getter(out value); if (err.IsSuccess()) { return(value); } //err.WarnIfFailed($"Native getter for {propertyName} failed"); return(string.Empty); }
internal static T NativeGet <T>(GetterMethod <T> getter, [CallerMemberName] string propertyName = "") { T value; var err = getter(out value); if (err.IsSuccess()) { return(value); } //err.WarnIfFailed($"Native getter for {propertyName} failed"); return(default(T)); }
protected override bool ShoudlLog(MemberInfo m, out IGetter getter) { getter = null; /// /// Check if ToLog annotation exists /// ToLogAttribute attr = (ToLogAttribute)m.GetCustomAttribute(typeof(ToLogAttribute)); if (attr == null) { return(false); } /// /// Check if is a field or parameterless method /// if (m.MemberType == MemberTypes.Field) { getter = new GetterField((FieldInfo)m); } if (m.MemberType == MemberTypes.Method) { MethodInfo mi = (MethodInfo)m; if (mi.GetParameters().Length == 0) { getter = new GetterMethod((MethodInfo)m); } } if (getter == null) { return(false); } if (attr.FormatterType != null) { getter = new GetterFormatter(getter, attr.FormatterType, attr.CtorArgs); } return(true); }
internal static T NativeGet <T>(GetterMethod <IntPtr> getter, Func <IntPtr, bool, T> ctor, bool hasOwnership, [CallerMemberName] string propertyName = "") where T : SafeMapsHandle { return(ctor(NativeGet(getter, propertyName), hasOwnership)); }