private JsExpression CompileImportedTypeCheckCode(IType type, ref JsExpression @this, IRuntimeContext context, bool isTypeIs)
        {
            var def = type.GetDefinition();

            if (def == null)
            {
                return(null);
            }
            var ia = AttributeReader.ReadAttribute <ImportedAttribute>(def);

            if (ia == null || string.IsNullOrEmpty(ia.TypeCheckCode))
            {
                return(null);
            }

            // Can ignore errors here because they are caught by the metadata importer
            var method    = MetadataUtils.CreateTypeCheckMethod(type, _compilation);
            var tokens    = InlineCodeMethodCompiler.Tokenize(method, ia.TypeCheckCode, _ => {});
            int thisCount = tokens.Count(t => t.Type == InlineCodeToken.TokenType.This);

            if (!isTypeIs || thisCount > 0)
            {
                @this = context.EnsureCanBeEvaluatedMultipleTimes(@this, new JsExpression[0]);
            }
            return(JsExpression.LogicalAnd(
                       ReferenceNotEquals(@this, JsExpression.Null, context),
                       InlineCodeMethodCompiler.CompileExpressionInlineCodeMethodInvocation(method, tokens, @this, EmptyList <JsExpression> .Instance, n => { var t = ReflectionHelper.ParseReflectionName(n).Resolve(_compilation); return t.Kind == TypeKind.Unknown ? JsExpression.Null : InstantiateType(t, context); }, t => InstantiateTypeForUseAsTypeArgumentInInlineCode(t, context), _ => {})));
        }
Ejemplo n.º 2
0
		private JsExpression CompileImportedTypeCheckCode(IType type, ref JsExpression @this, IRuntimeContext context, bool isTypeIs) {
			var def = type.GetDefinition();
			if (def == null)
				return null;
			var ia = _attributeStore.AttributesFor(def).GetAttribute<ImportedAttribute>();
			if (ia == null || string.IsNullOrEmpty(ia.TypeCheckCode))
				return null;

			// Can ignore errors here because they are caught by the metadata importer
			var method = MetadataUtils.CreateTypeCheckMethod(type, _compilation);
			var tokens = InlineCodeMethodCompiler.Tokenize(method, ia.TypeCheckCode, _ => {});
			int thisCount = tokens.Count(t => t.Type == InlineCodeToken.TokenType.This);
			if (!isTypeIs || thisCount > 0)
				@this = context.EnsureCanBeEvaluatedMultipleTimes(@this, new JsExpression[0]);
			return JsExpression.LogicalAnd(
			           ReferenceNotEquals(@this, JsExpression.Null, context),
			           InlineCodeMethodCompiler.CompileExpressionInlineCodeMethodInvocation(method, tokens, @this, EmptyList<JsExpression>.Instance, n => { var t = ReflectionHelper.ParseReflectionName(n).Resolve(_compilation); return t.Kind == TypeKind.Unknown ? JsExpression.Null : InstantiateType(t, context); }, t => InstantiateTypeForUseAsTypeArgumentInInlineCode(t, context), _ => {}));
		}