当前位置: 首页>>代码示例>>C#>>正文


C# FieldInfo.GetRawConstantValue方法代码示例

本文整理汇总了C#中System.Reflection.FieldInfo.GetRawConstantValue方法的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo.GetRawConstantValue方法的具体用法?C# FieldInfo.GetRawConstantValue怎么用?C# FieldInfo.GetRawConstantValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.FieldInfo的用法示例。


在下文中一共展示了FieldInfo.GetRawConstantValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrettyPrintField

 static object PrettyPrintField(FieldInfo fi)
 {
     return "    "
         + (fi.IsLiteral ? "const " : (fi.IsStatic ? "static " : "") + (fi.IsInitOnly ? "readonly " : ""))
         + ObjectToCode.GetCSharpFriendlyTypeName(fi.FieldType)
         + " " + fi.Name
         + (fi.IsLiteral ? " = " + ObjectToCode.ComplexObjectToPseudoCode(fi.GetRawConstantValue()) : "")
         ;
 }
开发者ID:markijbema,项目名称:ExpressionToCode,代码行数:9,代码来源:ApiStabilityTest.cs

示例2: FieldDetail

        public FieldDetail(RootDetail parent, FieldInfo fi)
            : base(parent, fi)
        {
            _name = fi.Name;
            _visibility = VisibilityUtil.GetVisibilityFor(fi);
            _category = "field";

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            if (fi.IsLiteral)
            {
                csb.AppendKeyword("const ");
            }
            else if (fi.IsStatic)
            {
                csb.AppendKeyword("static ");
            }

            if (fi.IsInitOnly)
            {
                csb.AppendKeyword("readonly ");
            }

            csb.AppendType(fi.FieldType);
            csb.AppendText(" ");
            csb.AppendText(fi.Name);

            if (fi.IsLiteral)
            {
                csb.AppendParameterValue(fi.GetRawConstantValue());
            }

            _declaration = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
开发者ID:redoz,项目名称:bitdiffer,代码行数:42,代码来源:FieldDetail.cs

示例3: Build

        public static RxFieldInfo Build(Compiler context, RxTypeInfo typeInfo, FieldInfo fieldInfo, XElement fieldMemberElement, string xid)
        {
            RxFieldInfo instance = new RxFieldInfo();

            instance.id = xid;
            instance.caption = instance.memberName = fieldInfo.Name;
            instance.SetUri(typeInfo, string.Concat("#", fieldInfo.Name));
            instance.BuildComments(context, fieldMemberElement);
            instance.isPublic = fieldInfo.IsPublic;
            instance.isStatic = fieldInfo.IsStatic;
            instance.isLiteral = fieldInfo.IsLiteral;
            if (fieldInfo.IsLiteral)
            {
                instance.literalValue = fieldInfo.GetRawConstantValue().ToString();
            }
            instance.memberInfo = fieldInfo;
            instance.fieldTypeRef = fieldInfo.FieldType.ToXMemberRef();
            //BuildAttributesElement(memberElement, memberInfo.GetCustomAttributes(false));
            return instance;
        }
开发者ID:automatonic,项目名称:refraxion,代码行数:20,代码来源:Compiler.RxFieldInfo.cs

示例4: GetReflectedField

        internal static PythonTypeSlot GetReflectedField(FieldInfo info) {
            PythonTypeSlot res;

            NameType nt = NameType.Field;
            if (!PythonBinder.IsExtendedType(info.DeclaringType) && 
                !info.IsDefined(typeof(PythonHiddenAttribute), false)) {
                nt |= NameType.PythonField;
            }

            lock (_fieldCache) {
                if (!_fieldCache.TryGetValue(info, out res)) {
                    if (nt == NameType.PythonField && info.IsLiteral) {
                        if (info.FieldType == typeof(int)) {
                            res = new PythonTypeUserDescriptorSlot(
                                ScriptingRuntimeHelpers.Int32ToObject((int)info.GetRawConstantValue()),
                                true
                            );
                        } else if (info.FieldType == typeof(bool)) {
                            res = new PythonTypeUserDescriptorSlot(
                                ScriptingRuntimeHelpers.BooleanToObject((bool)info.GetRawConstantValue()),
                                true
                            );
                        } else {
                            res = new PythonTypeUserDescriptorSlot(
                                info.GetValue(null),
                                true
                            );
                        }
                    } else {
                        res = new ReflectedField(info, nt);
                    }

                    _fieldCache[info] = res;
                }
            }

            return res;
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:38,代码来源:PythonTypeOps.cs

示例5: CompiledFieldScope

 public CompiledFieldScope(SymInfo si, FieldInfo fi, CompiledScope declaringType, bool is_global)
 {
     this.si = si;
     this.fi = fi;
     string[] args = declaringType.TemplateArguments;
     if (args != null)
     {
         generic_args = new List<string>();
         generic_args.AddRange(args);
     }
     if (generic_args != null)
     {
         //TypeScope ts = declaringType.instances[fi.FieldType.GenericParameterPosition];
         this.sc = CompiledScope.get_type_instance(fi.FieldType, declaringType.instances);
     }
     else
         this.sc = TypeTable.get_compiled_type(fi.FieldType);
     if (fi.IsLiteral)
         this.cnst_val = fi.GetRawConstantValue();
     if (si.name == null)
         AssemblyDocCache.AddDescribeToComplete(this.si, fi);
     this.si.name = fi.Name;
     this.is_global = is_global;
     this.si.description = this.ToString();
     //this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(fi.DeclaringType.Assembly,"F:"+fi.DeclaringType.FullName+"."+fi.Name);
     this.topScope = declaringType;
     if (fi.IsPrivate)
     {
         this.acc_mod = access_modifer.private_modifer;
         this.si.acc_mod = access_modifer.private_modifer;
     }
     else if (fi.IsFamily || fi.IsFamilyOrAssembly)
     {
         this.acc_mod = access_modifer.protected_modifer;
         this.si.acc_mod = access_modifer.protected_modifer;
     }
     else if (fi.IsFamilyAndAssembly || fi.IsAssembly)
     {
         this.acc_mod = access_modifer.internal_modifer;
         this.si.acc_mod = access_modifer.internal_modifer;
     }
 }
开发者ID:Slav76,项目名称:pascalabcnet,代码行数:42,代码来源:SymTable.cs

示例6: ProcessField

        static void ProcessField(XmlDocument output, XmlElement container, Dictionary<string, XmlElement> lookup, Type type, FieldInfo field)
        {
            if ((field.Attributes & FieldAttributes.SpecialName) != 0)
            {
                return;
            }

            var fieldXmlName = "F:";

            fieldXmlName += GetTypeXmlName(type) + ".";
            fieldXmlName += field.Name;

            XmlElement docs = null;
            if (lookup.ContainsKey(fieldXmlName))
            {
                docs = lookup[fieldXmlName];
            }

            Console.WriteLine("## Processing documentation for " + fieldXmlName);

            var fieldElem = output.CreateElement("Field");
            container.AppendChild(fieldElem);
            fieldElem.SetAttribute("Name", field.Name);
            fieldElem.SetAttribute("Anchor", GetAnchor(field));
            fieldElem.SetAttribute("IsPublic", field.IsPublic ? "True" : "False");
            fieldElem.SetAttribute("IsProtected", field.IsFamily ? "True" : "False");
            fieldElem.SetAttribute("IsPrivate", field.IsPrivate ? "True" : "False");
            fieldElem.SetAttribute("TypeName", field.FieldType.Name);
            fieldElem.SetAttribute("TypeNamespace", field.FieldType.Namespace);
            fieldElem.SetAttribute("TypeFullName", field.FieldType.FullName);
            fieldElem.SetAttribute("TypeAnchor", GetAnchor(field.FieldType));
            try
            {
                var constVal = field.GetRawConstantValue();
                if (constVal != null)
                {
                    if (constVal is string)
                    {
                        fieldElem.SetAttribute("ConstValue", "\"" + field.GetRawConstantValue().ToString().Replace("\\","\\\\").Replace("\"", "\\\"") + "\"");
                    }
                    else
                    {
                        fieldElem.SetAttribute("ConstValue", field.GetRawConstantValue().ToString());
                    }
                }
                else
                {
                    fieldElem.SetAttribute("ConstValue", "null");
                }
            }
            catch (InvalidOperationException ex)
            {
            }

            if (docs != null)
            {
                PortElementFromDocs(field, docs, "summary", fieldElem, "Summary");
                PortElementFromDocs(field, docs, "value", fieldElem, "Value");
            }
        }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:60,代码来源:Program.cs

示例7: FormatField

 public static string FormatField(FieldInfo field)
 {
     var builder = new StringBuilder();
       builder.Append(FourSpaces);
       if (field.IsPublic) {
     builder.Append("public ");
       }
       if (field.IsAssembly) {
     builder.Append("internal ");
       }
       if (field.IsFamily) {
     builder.Append("protected ");
       }
       if (field.IsStatic) {
     builder.Append("static ");
       }
       if (field.IsInitOnly) {
     builder.Append("readonly ");
       }
       builder.Append(FormatType(field.FieldType));
       builder.Append(" ");
       builder.Append(field.Name);
       if (field.IsLiteral) {
     try {
       var obj = field.GetRawConstantValue();
       if (obj is int) {
     builder.Append(" = " + (int)obj + ";");
       } else if (obj is long) {
     builder.Append(" = " + (long)obj + "L;");
       } else {
     builder.Append(";");
       }
     } catch (InvalidOperationException) {
       builder.Append(";");
     }
       } else {
     builder.Append(";");
       }
       return builder.ToString();
 }
开发者ID:peteroupc,项目名称:CBOR,代码行数:40,代码来源:DocVisitor.cs

示例8: ValidateSourceEqual

        private static void ValidateSourceEqual(this FieldInfo targetField, FieldInfo sourceField, Tuple<string, string> rootTargetAndSourceFullNames)
        {
            Contract.Requires(targetField != null);
            Contract.Requires(rootTargetAndSourceFullNames != null);
            Contract.Requires(rootTargetAndSourceFullNames.Item1 != null);
            Contract.Requires(rootTargetAndSourceFullNames.Item2 != null);
            Contract.Requires(rootTargetAndSourceFullNames.Item1 != rootTargetAndSourceFullNames.Item2);

            Assert.That(sourceField != null, "Could not find source type");
            Assert.That(sourceField != targetField);
            Assert.That(sourceField.Attributes == targetField.Attributes);
            Assert.That(sourceField.DeclaringType != targetField.DeclaringType);
            Assert.That(sourceField.IsAssembly == targetField.IsAssembly);
            Assert.That(sourceField.IsFamily == targetField.IsFamily);
            Assert.That(sourceField.IsFamilyAndAssembly == targetField.IsFamilyAndAssembly);
            Assert.That(sourceField.IsFamilyOrAssembly == targetField.IsFamilyOrAssembly);
            Assert.That(sourceField.IsInitOnly == targetField.IsInitOnly);
            Assert.That(sourceField.IsLiteral == targetField.IsLiteral);
            Assert.That(sourceField.IsNotSerialized == targetField.IsNotSerialized);
            Assert.That(sourceField.IsPinvokeImpl == targetField.IsPinvokeImpl);
            Assert.That(sourceField.IsPrivate == targetField.IsPrivate);
            Assert.That(sourceField.IsPublic == targetField.IsPublic);
            Assert.That(sourceField.IsSecurityCritical == targetField.IsSecurityCritical);
            Assert.That(sourceField.IsSecuritySafeCritical == targetField.IsSecuritySafeCritical);
            Assert.That(sourceField.IsSecurityTransparent == targetField.IsSecurityTransparent);
            Assert.That(sourceField.IsSpecialName == targetField.IsSpecialName);
            Assert.That(sourceField.IsStatic == targetField.IsStatic);
            Assert.That(sourceField.MemberType == targetField.MemberType);
            Assert.That(sourceField.Name == targetField.Name);

            targetField.FieldType.ValidateSourceNameEqual(sourceField.FieldType, rootTargetAndSourceFullNames);

            if (sourceField.IsLiteral)
            {
                var sourceValue = sourceField.GetRawConstantValue();
                var targetValue = targetField.GetRawConstantValue();

                if (sourceValue == null) { Assert.That(targetValue == null); }
                else { Assert.That(sourceValue.Equals(targetValue)); }
            }

            Attribute.GetCustomAttributes(targetField, false).ValidateSourceEqual(Attribute.GetCustomAttributes(sourceField, false), rootTargetAndSourceFullNames);
        }
开发者ID:rileywhite,项目名称:Cilador,代码行数:43,代码来源:CommonExtensions.cs

示例9: AddProviderEnumKind

        // adds a enumeration (keyword, opcode, task or channel) represented by 'staticField'
        // to the manifest.  
        private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo staticField, string providerEnumKind)
        {
            Type staticFieldType = staticField.FieldType;
            if (staticFieldType == typeof(EventOpcode))
            {
                if (providerEnumKind != "Opcodes") goto Error;
                int value = (int)staticField.GetRawConstantValue();
                if (value <= 10)
                    throw new ArgumentException(Environment.GetResourceString("EventSource_ReservedOpcode"));
                manifest.AddOpcode(staticField.Name, value);
            }
            else if (staticFieldType == typeof(EventTask))
            {
                if (providerEnumKind != "Tasks") goto Error;
                manifest.AddTask(staticField.Name, (int)staticField.GetRawConstantValue());
            }
            else if (staticFieldType == typeof(EventKeywords))
            {
                if (providerEnumKind != "Keywords") goto Error;
                manifest.AddKeyword(staticField.Name, (ulong)(long)staticField.GetRawConstantValue());
            }
#if FEATURE_MANAGED_ETW_CHANNELS
            else if (staticFieldType == typeof(EventChannel))
            {
                if (providerEnumKind != "Channels") goto Error;
                var channelAttribute = (ChannelAttribute)GetCustomAttributeHelper(staticField, typeof(ChannelAttribute));
                manifest.AddChannel(staticField.Name, (byte)staticField.GetRawConstantValue(), channelAttribute);
            }
#endif
            return;
        Error:
            throw new ArgumentException(Environment.GetResourceString("EventSource_EnumKindMismatch",  staticField.FieldType.Name, providerEnumKind));
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:35,代码来源:eventproviderbase.cs

示例10: GetConstantValue

 private string GetConstantValue(FieldInfo constant)
 {
     var value = constant.GetRawConstantValue().ToString();
     return value;
 }
开发者ID:gitter-badger,项目名称:WebApiProxy,代码行数:5,代码来源:MetadataProvider.cs

示例11: GetDescriptionForCompiledField

 public virtual string GetDescriptionForCompiledField(FieldInfo fi)
 {
     StringBuilder sb = new StringBuilder();
     if (fi.IsPublic)
         sb.Append("public ");
     else if (fi.IsFamily)
         sb.Append("protected ");
     if (!fi.IsLiteral)
         if (fi.IsStatic) sb.Append("class ");
     if (!fi.IsLiteral)
     {
         sb.Append(prepare_member_name(fi.Name));
         sb.Append(" : " + GetFullTypeName(fi.FieldType));
     }
     else
     {
         sb.Append("const " + fi.Name + " : " + GetFullTypeName(fi.FieldType));
         sb.Append(" = " + fi.GetRawConstantValue().ToString());
     }
     sb.Append(";");
     return sb.ToString();
 }
开发者ID:Slav76,项目名称:pascalabcnet,代码行数:22,代码来源:DefaultLanguageInformation.cs

示例12: MapField

        private void MapField(TypeDefinition type_definition, FieldInfo field)
        {
            if (_options.EraseMember(field)) return;

            var field_definition = FieldDefinitionFor(field, type_definition);

            if (field_definition.HasDefault)
                field_definition.Constant = field.GetRawConstantValue();

            if ((field_definition.Attributes & MC.FieldAttributes.HasFieldRVA) != 0)
                field_definition.InitialValue = GetInitialValue(field);

            var attributes = field.GetCustomAttributes(typeof(FieldOffsetAttribute), inherit: false);
            if (attributes.Length > 0)
                field_definition.Offset = ((FieldOffsetAttribute)attributes[0]).Value;

            MapCustomAttributes(field, field_definition);
        }
开发者ID:Horusiath,项目名称:Vagabond,代码行数:18,代码来源:AssemblyParser.cs

示例13: GetFieldInitLiteral

 private string GetFieldInitLiteral(FieldInfo field)
 {
     if (!field.IsLiteral)
         return null;
     var value = field.GetRawConstantValue();
     if (field.FieldType == typeof(String))
         return "\"" + value.ToString() + "\"";
     return value.ToString();
 }
开发者ID:codaxy,项目名称:dox,代码行数:9,代码来源:XmlCommentsDoxProviderImpl.cs

示例14: InternalSetConstant

        private static void InternalSetConstant(FieldInfo fi, JavaArchiveReflectorFieldInfo yi)
        {
            // X:\jsc.svn\examples\java\Test\TestJavaFinalIntegerField\TestJavaFinalIntegerField\Program.cs
            var RawConstantValue = fi.GetRawConstantValue();
            if (RawConstantValue == null)
            {
                // wtf?

                //001b ScriptCoreLibAndroid.Natives android.os.Parcelable
                //System.InvalidOperationException: SetConstant { FieldName = EMPTY_STATE, FieldType = android.view.AbsSavedState }

                yi.IsLiteral = false;

                // enum?
                return;
            }

            var RawConstantValueType = RawConstantValue.GetType();

            if (RawConstantValueType == typeof(int))
                yi.LiteralInt32 = (int)RawConstantValue;
            else if (RawConstantValueType == typeof(short))
                yi.LiteralInt16 = (short)RawConstantValue;
            else if (RawConstantValueType == typeof(long))
                yi.LiteralInt64 = (long)RawConstantValue;
            else if (RawConstantValueType == typeof(sbyte))
                yi.LiteralInt8 = (byte)(sbyte)RawConstantValue;
            else if (fi.FieldType == typeof(string))
                yi.LiteralString = (string)RawConstantValue;
            else
            {

                //Console.WriteLine(

                //"InternalSetConstant " + new { fi.DeclaringType.FullName, fi.Name, RawConstantValueType, fi.FieldType }

                //    );

                yi.IsLiteral = false;
            }
            //throw new InvalidOperationException(
            //);
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:43,代码来源:IJavaArchiveReflector.cs

示例15: GetConstantFieldNode

 public static compiled_class_constant_definition GetConstantFieldNode(FieldInfo fi)
 {
     compiled_class_constant_definition cccd = field_nodes[fi] as compiled_class_constant_definition;
     if (cccd != null) return cccd;
     constant_node cn = CreateConstantNode(fi.GetRawConstantValue());
     if (cn == null)
         return null;
     cccd = new compiled_class_constant_definition(fi, cn);
     field_nodes[fi] = cccd;
     return cccd;
 }
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:11,代码来源:NetHelper.cs


注:本文中的System.Reflection.FieldInfo.GetRawConstantValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。