Пример #1
0
            InvocationResolveResult GetCtorInvocation()
            {
                ResolveResult rr = LazyInit.VolatileRead(ref this.ctorInvocation);

                if (rr != null)
                {
                    return(rr as InvocationResolveResult);
                }
                else
                {
                    CSharpResolver  resolver           = new CSharpResolver(context);
                    int             totalArgumentCount = unresolved.positionalArguments.Count + unresolved.namedCtorArguments.Count;
                    ResolveResult[] arguments          = new ResolveResult[totalArgumentCount];
                    string[]        argumentNames      = new string[totalArgumentCount];
                    int             i = 0;
                    while (i < unresolved.positionalArguments.Count)
                    {
                        IConstantValue cv = unresolved.positionalArguments[i];
                        arguments[i] = cv.Resolve(context);
                        i++;
                    }
                    foreach (var pair in unresolved.namedCtorArguments)
                    {
                        argumentNames[i] = pair.Key;
                        arguments[i]     = pair.Value.Resolve(context);
                        i++;
                    }
                    rr = resolver.ResolveObjectCreation(attributeType, arguments, argumentNames);
                    return(LazyInit.GetOrSet(ref this.ctorInvocation, rr) as InvocationResolveResult);
                }
            }
Пример #2
0
 public Expression ConvertConstantValue(IConstantValue constantValue)
 {
     if (constantValue == null)
     {
         throw new ArgumentNullException("constantValue");
     }
     return(ConvertConstantValue(constantValue.Resolve(context)));
 }
Пример #3
0
 ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context)
 {
     if (constantValue != null)
     {
         return(constantValue.Resolve(context));
     }
     else
     {
         return(new ErrorResolveResult(SharedTypes.UnknownType));
     }
 }
Пример #4
0
        public ResolveResult Resolve(ITypeResolveContext context)
        {
            ResolveResult rr = baseValue.Resolve(context);

            if (rr.IsCompileTimeConstant && rr.ConstantValue != null)
            {
                object   val      = rr.ConstantValue;
                TypeCode typeCode = Type.GetTypeCode(val.GetType());
                if (typeCode >= TypeCode.SByte && typeCode <= TypeCode.UInt64)
                {
                    long   intVal = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, val, false);
                    object newVal = CSharpPrimitiveCast.Cast(typeCode, unchecked (intVal + incrementAmount), false);
                    return(new ConstantResolveResult(rr.Type, newVal));
                }
            }
            return(new ErrorResolveResult(rr.Type));
        }
Пример #5
0
        public IMethod ResolveConstructor(ITypeResolveContext context)
        {
            CSharpResolver r    = new CSharpResolver(context);
            IType          type = attributeType.Resolve(context);
            int            totalArgumentCount = 0;

            if (positionalArguments != null)
            {
                totalArgumentCount += positionalArguments.Count;
            }
            if (namedCtorArguments != null)
            {
                totalArgumentCount += namedCtorArguments.Count;
            }
            ResolveResult[] arguments     = new ResolveResult[totalArgumentCount];
            string[]        argumentNames = new string[totalArgumentCount];
            int             i             = 0;

            if (positionalArguments != null)
            {
                while (i < positionalArguments.Count)
                {
                    IConstantValue cv = positionalArguments[i];
                    arguments[i] = cv.Resolve(context);
                    i++;
                }
            }
            if (namedCtorArguments != null)
            {
                foreach (var pair in namedCtorArguments)
                {
                    argumentNames[i] = pair.Key;
                    arguments[i]     = pair.Value.Resolve(context);
                    i++;
                }
            }
            MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult;

            return(mrr != null ? mrr.Member as IMethod : null);
        }
Пример #6
0
        public IList <IAttribute> Resolve(IAssembly currentAssembly)
        {
            // TODO: make this a per-assembly cache
            //				CacheManager cache = currentAssembly.Compilation.CacheManager;
            //				IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
            //				if (result != null)
            //					return result;

            ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
            BlobReader          reader  = new BlobReader(blob, currentAssembly);

            if (reader.ReadByte() != '.')
            {
                // should not use UnresolvedSecurityDeclaration for XML secdecls
                throw new InvalidOperationException();
            }
            ResolveResult securityActionRR = securityAction.Resolve(context);
            uint          attributeCount   = reader.ReadCompressedUInt32();

            IAttribute[] attributes = new IAttribute[attributeCount];
            try
            {
                ReadSecurityBlob(reader, attributes, context, securityActionRR);
            }
            catch (NotSupportedException ex)
            {
                // ignore invalid blobs
                Debug.WriteLine(ex.ToString());
            }
            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes[i] == null)
                {
                    attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
                }
            }
            return(attributes);
            //				return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
        }
Пример #7
0
		ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context)
		{
			if (constantValue != null)
				return constantValue.Resolve(context);
			else
				return new ErrorResolveResult(SharedTypes.UnknownType);
		}
Пример #8
0
		public Expression ConvertConstantValue(IConstantValue constantValue)
		{
			if (constantValue == null)
				throw new ArgumentNullException("constantValue");
			return ConvertConstantValue(constantValue.Resolve(context));
		}