SetDefaultParameterValue() public méthode

public SetDefaultParameterValue ( int index, CType type, CONSTVAL cv ) : void
index int
type CType
cv CONSTVAL
Résultat void
Exemple #1
0
        /////////////////////////////////////////////////////////////////////////////////

        private void SetParameterAttributes(MethodOrPropertySymbol methProp, ParameterInfo[] parameters, int i)
        {
            if (((parameters[i].Attributes & ParameterAttributes.Optional) != 0) &&
                !parameters[i].ParameterType.IsByRef)
            {
                methProp.SetOptionalParameter(i);
                PopulateSymbolTableWithName("Value", new Type[] { typeof(Missing) }, typeof(Missing)); // We might need this later
            }

            object[] attrs;

            // Get MarshalAsAttribute
            if ((parameters[i].Attributes & ParameterAttributes.HasFieldMarshal) != 0)
            {
                if ((attrs = parameters[i].GetCustomAttributes(typeof(MarshalAsAttribute), false).ToArray()) != null
                    && attrs.Length > 0)
                {
                    MarshalAsAttribute attr = (MarshalAsAttribute)attrs[0];
                    methProp.SetMarshalAsParameter(i, attr.Value);
                }
            }

            // Get the various kinds of default values
            if ((attrs = parameters[i].GetCustomAttributes(typeof(DateTimeConstantAttribute), false).ToArray()) != null
                && attrs.Length > 0)
            {
                // Get DateTimeConstant

                DateTimeConstantAttribute attr = (DateTimeConstantAttribute)attrs[0];

                ConstValFactory factory = new ConstValFactory();
                CONSTVAL cv = factory.Create(((System.DateTime)attr.Value).Ticks);
                CType cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DATETIME);
                methProp.SetDefaultParameterValue(i, cvType, cv);
            }
            else if ((attrs = parameters[i].GetCustomAttributes(typeof(DecimalConstantAttribute), false).ToArray()) != null
                && attrs.Length > 0)
            {
                // Get DecimalConstant

                DecimalConstantAttribute attr = (DecimalConstantAttribute)attrs[0];

                ConstValFactory factory = new ConstValFactory();
                CONSTVAL cv = factory.Create(attr.Value);
                CType cvType = _semanticChecker.GetSymbolLoader().GetOptPredefType(PredefinedType.PT_DECIMAL);
                methProp.SetDefaultParameterValue(i, cvType, cv);
            }
            else if (((parameters[i].Attributes & ParameterAttributes.HasDefault) != 0) &&
                !parameters[i].ParameterType.IsByRef)
            {
                // Only set a default value if we have one, and the type that we're
                // looking at isn't a by ref type or a type parameter.

                ConstValFactory factory = new ConstValFactory();
                CONSTVAL cv = cv = ConstValFactory.GetNullRef();
                CType cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_OBJECT);

                // We need to use RawDefaultValue, because DefaultValue is too clever.
#if UNSUPPORTEDAPI
                if (parameters[i].RawDefaultValue != null)
                {
                    object defValue = parameters[i].RawDefaultValue;
#else
                if (parameters[i].DefaultValue != null)
                {
                    object defValue = parameters[i].DefaultValue;
#endif
                    Type defType = defValue.GetType();

                    if (defType == typeof(System.Byte))
                    {
                        cv = factory.Create((System.Byte)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_BYTE);
                    }
                    else if (defType == typeof(System.Int16))
                    {
                        cv = factory.Create((System.Int16)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_SHORT);
                    }
                    else if (defType == typeof(System.Int32))
                    {
                        cv = factory.Create((System.Int32)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_INT);
                    }
                    else if (defType == typeof(System.Int64))
                    {
                        cv = factory.Create((System.Int64)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_LONG);
                    }
                    else if (defType == typeof(System.Single))
                    {
                        cv = factory.Create((System.Single)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_FLOAT);
                    }
                    else if (defType == typeof(System.Double))
                    {
                        cv = factory.Create((System.Double)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DOUBLE);
                    }
                    else if (defType == typeof(System.Decimal))
                    {
                        cv = factory.Create((System.Decimal)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DECIMAL);
                    }
                    else if (defType == typeof(System.Char))
                    {
                        cv = factory.Create((System.Char)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_CHAR);
                    }
                    else if (defType == typeof(System.Boolean))
                    {
                        cv = factory.Create((System.Boolean)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_BOOL);
                    }
                    else if (defType == typeof(System.SByte))
                    {
                        cv = factory.Create((System.SByte)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_SBYTE);
                    }
                    else if (defType == typeof(System.UInt16))
                    {
                        cv = factory.Create((System.UInt16)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_USHORT);
                    }
                    else if (defType == typeof(System.UInt32))
                    {
                        cv = factory.Create((System.UInt32)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_UINT);
                    }
                    else if (defType == typeof(System.UInt64))
                    {
                        cv = factory.Create((System.UInt64)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_ULONG);
                    }
                    else if (defType == typeof(System.String))
                    {
                        cv = factory.Create((System.String)defValue);
                        cvType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_STRING);
                    }
                    // if we fall off the end of this cascading if, we get Object/null
                    // because that's how we initialized the constval.
                }
                methProp.SetDefaultParameterValue(i, cvType, cv);
            }
        }

        /////////////////////////////////////////////////////////////////////////////////

        private MethodSymbol FindMatchingMethod(MemberInfo method, AggregateSymbol callingAggregate)
        {
            MethodSymbol meth = _bsymmgr.LookupAggMember(GetName(method.Name), callingAggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol();
            while (meth != null)
            {
                if (meth.AssociatedMemberInfo.IsEquivalentTo(method))
                {
                    return meth;
                }
                meth = BSYMMGR.LookupNextSym(meth, callingAggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol();
            }
            return null;
        }