public static bool IsFieldProperty(IMemberDefinition property, IEmitter emitter) { var p = property as PropertyDefinition; if (p != null && p.GetMethod != null && !p.GetMethod.IsStatic && property.DeclaringType != null && property.DeclaringType.CustomAttributes.Any(a => a.AttributeType.FullName == "Bridge.ObjectLiteralAttribute")) { return(true); } bool isAuto = AttributeHelper.HasFieldAttribute(property); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { var typeDef = property.DeclaringType; if (emitter.Validator.IsExternalType(typeDef)) { return(false); } return(Helpers.IsAutoProperty((PropertyDefinition)property)); } return(isAuto); }
public static bool IsFieldProperty(PropertyDeclaration property, IEmitter emitter) { ResolveResult resolveResult = emitter.Resolver.ResolveNode(property, emitter) as MemberResolveResult; if (resolveResult != null && ((MemberResolveResult)resolveResult).Member != null) { return IsFieldProperty(((MemberResolveResult)resolveResult).Member, emitter); } string name = "Bridge.FieldProperty"; string name1 = name + "Attribute"; foreach (var i in property.Attributes) { foreach (var j in i.Attributes) { if (j.Type.ToString() == name || j.Type.ToString() == name1) { return true; } resolveResult = emitter.Resolver.ResolveNode(j, emitter); if (resolveResult != null && resolveResult.Type != null && resolveResult.Type.FullName == name1) { return true; } } } if (!emitter.AssemblyInfo.AutoPropertyToField) { return false; } var typeDef = emitter.GetTypeDefinition(); var propDef = typeDef.Properties.FirstOrDefault(p => p.Name == property.Name); return Helpers.IsAutoProperty(propDef); }
public static bool IsFieldProperty(IMember propertyMember, IAssemblyInfo assemblyInfo) { if (propertyMember is IProperty && !propertyMember.IsStatic && propertyMember.DeclaringTypeDefinition != null && propertyMember.DeclaringTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ObjectLiteralAttribute")) { return(true); } bool isAuto = AttributeHelper.HasFieldAttribute(propertyMember); if (!isAuto && assemblyInfo.AutoPropertyToField && propertyMember is IProperty) { var isIgnore = propertyMember.DeclaringTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute") || propertyMember.DeclaringTypeDefinition.ParentAssembly.AssemblyAttributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute"); if (isIgnore) { return(false); } return(propertyMember.DeclaringType.Kind == TypeKind.Interface || Helpers.IsAutoProperty((IProperty)propertyMember)); } return(isAuto || assemblyInfo.AutoPropertyToField); }
public static bool IsFieldProperty(IMemberDefinition property, IEmitter emitter) { bool isAuto = property.CustomAttributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { return(Helpers.IsAutoProperty((PropertyDefinition)property)); } return(isAuto); }
public static bool IsFieldProperty(IMember propertyMember, IAssemblyInfo assemblyInfo) { bool isAuto = propertyMember.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && assemblyInfo.AutoPropertyToField && propertyMember is IProperty) { return(propertyMember.DeclaringType.Kind == TypeKind.Interface || Helpers.IsAutoProperty((IProperty)propertyMember)); } return(isAuto || assemblyInfo.AutoPropertyToField); }
public static bool IsFieldProperty(IMember property, IEmitter emitter) { bool isAuto = property.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { var typeDef = emitter.GetTypeDefinition(property.DeclaringType); var propDef = typeDef.Properties.FirstOrDefault(p => p.Name == property.Name); return(Helpers.IsAutoProperty(propDef)); } return(isAuto); }
public static bool IsFieldProperty(IMemberDefinition property, IEmitter emitter) { bool isAuto = property.CustomAttributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { var typeDef = property.DeclaringType; if (emitter.Validator.IsIgnoreType(typeDef)) { return false; } return Helpers.IsAutoProperty((PropertyDefinition)property); } return isAuto; }
public static bool IsFieldProperty(IMember propertyMember, IEmitter emitter) { bool isAuto = propertyMember.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { var typeDef = emitter.GetTypeDefinition(propertyMember.DeclaringType); if (emitter.Validator.IsIgnoreType(typeDef)) { return false; } var propDef = typeDef.Properties.FirstOrDefault(p => p.Name == propertyMember.Name); return typeDef.IsInterface || Helpers.IsAutoProperty(propDef); } return isAuto; }
public static bool IsFieldProperty(IMember propertyMember, IAssemblyInfo assemblyInfo) { bool isAuto = propertyMember.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && assemblyInfo.AutoPropertyToField && propertyMember is IProperty) { var isIgnore = propertyMember.DeclaringTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute"); if (isIgnore) { return false; } return propertyMember.DeclaringType.Kind == TypeKind.Interface || Helpers.IsAutoProperty((IProperty)propertyMember); } return isAuto || assemblyInfo.AutoPropertyToField; }
private OverloadsCollection(IEmitter emitter, IMember member, bool isSetter = false, bool includeInline = false, bool isField = false) { if (member is IMethod) { var method = (IMethod)member; this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity) { var entity = (IEntity)member; this.Inherit = !entity.IsStatic; this.Static = entity.IsStatic; } this.Emitter = emitter; this.Name = member.Name; this.IsField = isField; if (member is IProperty) { this.CancelChangeCase = !Helpers.IsFieldProperty(member, emitter); this.JsName = Helpers.GetPropertyRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetPropertyRef(member, emitter, !isSetter, true, true); var p = (IProperty)member; this.FieldJsName = Helpers.IsAutoProperty(p) ? (Helpers.IsFieldProperty(p, this.Emitter) ? this.Emitter.GetEntityName(p) : Helpers.GetPropertyRef(p, this.Emitter, true, true, true, false, true)) : null; } else if (member is IEvent) { this.CancelChangeCase = true; this.JsName = Helpers.GetEventRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetEventRef(member, emitter, !isSetter, true, true); this.FieldJsName = Helpers.GetEventRef(member, emitter, true, true, true, false, true); } else { this.JsName = this.Emitter.GetEntityName(member, false, true); } this.IncludeInline = includeInline; this.Member = member; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.IsSetter = isSetter; this.InitMembers(); this.Emitter.OverloadsCacheMembers[new Tuple <IMember, bool, bool>(member, isSetter, includeInline)] = this; }
public static bool IsFieldProperty(PropertyDeclaration propertyDeclaration, IMember propertyMember, IAssemblyInfo assemblyInfo) { if (propertyMember.ImplementedInterfaceMembers.Count > 0 || propertyMember.DeclaringType.Kind == TypeKind.Interface) { return(false); } bool isAuto = propertyMember.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute"); if (!isAuto && assemblyInfo.AutoPropertyToField && propertyMember is IProperty) { return(Helpers.IsAutoProperty(propertyDeclaration, (IProperty)propertyMember)); } return(isAuto || assemblyInfo.AutoPropertyToField); }
private OverloadsCollection(IEmitter emitter, PropertyDeclaration propDeclaration, bool isSetter) { this.Emitter = emitter; this.Name = propDeclaration.Name; this.JsName = Helpers.GetPropertyRef(propDeclaration, emitter, isSetter, true, true); this.AltJsName = Helpers.GetPropertyRef(propDeclaration, emitter, !isSetter, true, true); this.FieldJsName = propDeclaration.Getter != null && propDeclaration.Getter.Body.IsNull ? emitter.GetEntityName(propDeclaration) : null; this.Inherit = !propDeclaration.HasModifier(Modifiers.Static); this.Static = propDeclaration.HasModifier(Modifiers.Static); this.CancelChangeCase = !Helpers.IsFieldProperty(propDeclaration, emitter); this.IsSetter = isSetter; this.Member = this.FindMember(propDeclaration); var p = (IProperty)this.Member; this.FieldJsName = Helpers.IsAutoProperty(p) ? (Helpers.IsFieldProperty(p, this.Emitter) ? this.Emitter.GetEntityName(p) : Helpers.GetPropertyRef(p, this.Emitter, true, true, true, false, true)) : null; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.InitMembers(); this.Emitter.OverloadsCacheNodes[new Tuple <AstNode, bool>(propDeclaration, isSetter)] = this; }
public static bool IsFieldProperty(PropertyDeclaration property, IEmitter emitter) { ResolveResult resolveResult = emitter.Resolver.ResolveNode(property, emitter) as MemberResolveResult; if (resolveResult != null && ((MemberResolveResult)resolveResult).Member != null) { return(Helpers.IsFieldProperty(((MemberResolveResult)resolveResult).Member, emitter)); } if (AttributeHelper.HasFieldAttribute(property, emitter)) { return(true); } if (!emitter.AssemblyInfo.AutoPropertyToField) { return(false); } var typeDef = emitter.GetTypeDefinition(); var propDef = typeDef.Properties.FirstOrDefault(p => p.Name == property.Name); return(Helpers.IsAutoProperty(propDef)); }
public static bool IsFieldProperty(IMember propertyMember, IEmitter emitter) { if (propertyMember is IProperty && !propertyMember.IsStatic && propertyMember.DeclaringTypeDefinition != null && propertyMember.DeclaringTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ObjectLiteralAttribute")) { return(true); } bool isAuto = AttributeHelper.HasFieldAttribute(propertyMember); if (!isAuto && emitter.AssemblyInfo.AutoPropertyToField) { var typeDef = emitter.GetTypeDefinition(propertyMember.DeclaringType); if (emitter.Validator.IsExternalType(typeDef)) { return(false); } var propDef = typeDef.Properties.FirstOrDefault(p => p.Name == propertyMember.Name); return(typeDef.IsInterface || Helpers.IsAutoProperty(propDef)); } return(isAuto); }
protected virtual List <IProperty> GetPropertyOverloads(List <IProperty> list = null, ITypeDefinition typeDef = null) { bool isTop = list == null; list = list ?? new List <IProperty>(); typeDef = typeDef ?? this.TypeDefinition; if (typeDef != null) { var bridgeType = this.Emitter.BridgeTypes.Get(typeDef); var monoTypeDef = bridgeType != null ? bridgeType.TypeDefinition : null; var properties = typeDef.Properties.Where(p => { if (p.IsExplicitInterfaceImplementation) { return(false); } var canGet = p.CanGet && p.Getter != null; var canSet = p.CanSet && p.Setter != null; if (monoTypeDef != null) { var monoProp = monoTypeDef.Properties.FirstOrDefault(mp => mp.Name == p.Name); if (monoProp != null) { canGet = monoProp.GetMethod != null; canSet = monoProp.SetMethod != null; } } if (!this.IncludeInline) { var inline = canGet ? this.Emitter.GetInline(p.Getter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } inline = canSet ? this.Emitter.GetInline(p.Setter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } if (p.IsIndexer && canGet && p.Getter.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute")) { return(false); } } bool eq = false; bool?equalsByGetter = null; if (p.IsStatic == this.Static) { var getterIgnore = canGet && this.Emitter.Validator.IsExternalType(p.Getter); var setterIgnore = canSet && this.Emitter.Validator.IsExternalType(p.Setter); var getterName = canGet ? Helpers.GetPropertyRef(p, this.Emitter, false, true, true) : null; var setterName = canSet ? Helpers.GetPropertyRef(p, this.Emitter, true, true, true) : null; var fieldName = Helpers.IsAutoProperty(p) ? (Helpers.IsFieldProperty(p, this.Emitter) ? this.Emitter.GetEntityName(p) : Helpers.GetPropertyRef(p, this.Emitter, true, true, true, false, true)) : null; if (!getterIgnore && getterName != null && (getterName == this.JsName || getterName == this.AltJsName || getterName == this.FieldJsName)) { eq = true; equalsByGetter = true; } else if (!setterIgnore && setterName != null && (setterName == this.JsName || setterName == this.AltJsName || setterName == this.FieldJsName)) { eq = true; equalsByGetter = false; } else if (fieldName != null && (fieldName == this.JsName || fieldName == this.AltJsName || fieldName == this.FieldJsName)) { eq = true; } } if (eq) { if (p.IsOverride && !this.IsTemplateOverride(p)) { return(false); } if (equalsByGetter.HasValue && this.Member is IMethod && this.AltJsName == null) { this.AltJsName = Helpers.GetPropertyRef(p, this.Emitter, equalsByGetter.Value, true, true); } return(true); } return(false); }); list.AddRange(properties); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { var result = this.GetPropertyOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } return(isTop ? list.Distinct().ToList() : list); }