public virtual void CheckEvents(TypeDefinition type, ITranslator translator) { if (type.HasEvents && this.IsObjectLiteral(type)) { TranslatorException.Throw("ObjectLiteral type doesn't support events: {0}", type); } }
public virtual void CheckObjectLiteral(TypeDefinition type, ITranslator translator) { if (this.IsObjectLiteral(type)) { if (type.IsInterface && (type.HasMethods || type.HasProperties || type.HasEvents || type.HasFields)) { TranslatorException.Throw("ObjectLiteral interface doesn't support any contract members: {0}", type); } var objectCreateMode = this.GetObjectCreateMode(type); if (type.BaseType != null) { TypeDefinition baseType = null; try { baseType = type.BaseType.Resolve(); } catch (Exception) { } if (objectCreateMode == 1 && baseType != null && baseType.FullName != "System.Object" && this.GetObjectCreateMode(baseType) == 0) { TranslatorException.Throw("[ObjectLiteral] with Constructor mode should be inherited from class with same options: {0}", type); } if (objectCreateMode == 0 && baseType != null && this.GetObjectCreateMode(baseType) == 1) { TranslatorException.Throw("[ObjectLiteral] with Plain mode cannot be inherited from [ObjectLiteral] with Constructor mode: {0}", type); } } if (type.Interfaces.Count > 0 && objectCreateMode == 1) { foreach (var @interface in type.Interfaces) { TypeDefinition iDef = null; try { iDef = @interface.Resolve(); } catch (Exception) { } if (iDef != null && iDef.FullName != "System.Object" && !this.IsObjectLiteral(iDef)) { TranslatorException.Throw("[ObjectLiteral] should implement an interface which must be object literal also: {0}", type); } } } } }
public virtual void CheckProperties(TypeDefinition type, ITranslator translator) { if (type.HasProperties && this.IsObjectLiteral(type)) { foreach (PropertyDefinition prop in type.Properties) { if ((prop.GetMethod != null && prop.GetMethod.IsVirtual) || (prop.SetMethod != null && prop.SetMethod.IsVirtual)) { TranslatorException.Throw("ObjectLiteral type doesn't support virtual members: {0}", type); } } } }
public virtual void CheckFields(TypeDefinition type, ITranslator translator) { if (this.IsObjectLiteral(type) && type.HasFields) { foreach (FieldDefinition field in type.Fields) { if (field.IsStatic) { TranslatorException.Throw("ObjectLiteral type doesn't support static members: {0}", type); } } } }
public virtual void CheckObjectLiteral(TypeDefinition type, ITranslator translator) { if (!this.IsObjectLiteral(type)) { return; } var objectCreateMode = this.GetObjectCreateMode(type); if (objectCreateMode == 0) { var ctors = type.GetConstructors(); foreach (var ctor in ctors) { foreach (var parameter in ctor.Parameters) { if (parameter.ParameterType.FullName == "Bridge.ObjectCreateMode") { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_PLAIN_NO_CREATE_MODE_CUSTOM_CONSTRUCTOR, type); } if (parameter.ParameterType.FullName == "Bridge.ObjectInitializationMode") { continue; } TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_PLAIN_CUSTOM_CONSTRUCTOR, type); } } } if (type.IsInterface) { if (type.HasMethods && type.Methods.GroupBy(m => m.Name).Any(g => g.Count() > 1)) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_INTERFACE_NO_OVERLOAD_METHODS, type); } if (type.HasEvents) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_INTERFACE_NO_EVENTS, type); } } else { if (type.Methods.Any(m => !m.IsRuntimeSpecialName && m.Name.Contains(".") && !m.Name.Contains("<")) || type.Properties.Any(m => !m.IsRuntimeSpecialName && m.Name.Contains(".") && !m.Name.Contains("<"))) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_INTERFACE_NO_EXPLICIT_IMPLEMENTATION, type); } } if (type.BaseType != null) { TypeDefinition baseType = null; try { baseType = type.BaseType.Resolve(); } catch (Exception) { } if (objectCreateMode == 1 && baseType != null && baseType.FullName != "System.Object" && baseType.FullName != "System.ValueType" && this.GetObjectCreateMode(baseType) == 0) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_CONSTRUCTOR_INHERITANCE, type); } if (objectCreateMode == 0 && baseType != null && this.GetObjectCreateMode(baseType) == 1) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_PLAIN_INHERITANCE, type); } } if (type.Interfaces.Count > 0) { foreach (var @interface in type.Interfaces) { TypeDefinition iDef = null; try { iDef = @interface.Resolve(); } catch (Exception) { } if (iDef != null && iDef.FullName != "System.Object" && !this.IsObjectLiteral(iDef)) { TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_INTERFACE_INHERITANCE, type); } } } if (objectCreateMode == 0) { var hasVirtualMethods = false; foreach (MethodDefinition method in type.Methods) { if (AttributeHelper.HasCompilerGeneratedAttribute(method)) { continue; } if (method.IsVirtual && !(method.IsSetter || method.IsGetter)) { hasVirtualMethods = true; break; } } if (hasVirtualMethods) { Bridge.Translator.TranslatorException.Throw(Constants.Messages.Exceptions.OBJECT_LITERAL_NO_VIRTUAL_METHODS, type); } } }
public virtual void CheckObjectLiteral(TypeDefinition type, ITranslator translator) { if (this.IsObjectLiteral(type)) { var objectCreateMode = this.GetObjectCreateMode(type); if (type.IsInterface) { if (type.HasMethods && type.Methods.GroupBy(m => m.Name).Any(g => g.Count() > 1)) { TranslatorException.Throw("ObjectLiteral interface doesn't support overloaded methods: {0}", type); } if (type.HasEvents) { TranslatorException.Throw("ObjectLiteral interface doesn't support events: {0}", type); } } else { if (type.Methods.Any(m => !m.IsRuntimeSpecialName && m.Name.Contains(".")) || type.Properties.Any(m => !m.IsRuntimeSpecialName && m.Name.Contains("."))) { TranslatorException.Throw("ObjectLiteral doesn't support explicit interface member implementation: {0}", type); } } if (type.BaseType != null) { TypeDefinition baseType = null; try { baseType = type.BaseType.Resolve(); } catch (Exception) { } if (objectCreateMode == 1 && baseType != null && baseType.FullName != "System.Object" && this.GetObjectCreateMode(baseType) == 0) { TranslatorException.Throw("[ObjectLiteral] with Constructor mode should be inherited from class with same options: {0}", type); } if (objectCreateMode == 0 && baseType != null && this.GetObjectCreateMode(baseType) == 1) { TranslatorException.Throw("[ObjectLiteral] with Plain mode cannot be inherited from [ObjectLiteral] with Constructor mode: {0}", type); } } if (type.Interfaces.Count > 0 && objectCreateMode == 1) { foreach (var @interface in type.Interfaces) { TypeDefinition iDef = null; try { iDef = @interface.Resolve(); } catch (Exception) { } if (iDef != null && iDef.FullName != "System.Object" && !this.IsObjectLiteral(iDef)) { TranslatorException.Throw("[ObjectLiteral] should implement an interface which must be object literal also: {0}", type); } } } } }