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); } }
public Expression ConvertConstantValue(IConstantValue constantValue) { if (constantValue == null) { throw new ArgumentNullException("constantValue"); } return(ConvertConstantValue(constantValue.Resolve(context))); }
ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context) { if (constantValue != null) { return(constantValue.Resolve(context)); } else { return(new ErrorResolveResult(SharedTypes.UnknownType)); } }
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)); }
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); }
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); }
ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context) { if (constantValue != null) return constantValue.Resolve(context); else return new ErrorResolveResult(SharedTypes.UnknownType); }
public Expression ConvertConstantValue(IConstantValue constantValue) { if (constantValue == null) throw new ArgumentNullException("constantValue"); return ConvertConstantValue(constantValue.Resolve(context)); }