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


C# NamedObjectSave.ToString方法代码示例

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


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

示例1: GetMemberInfoForMember

        private static MemberInfo GetMemberInfoForMember(NamedObjectSave namedObjectSave, string typeName, string variableToReset)
        {
            Type type = null;

            if (namedObjectSave.SourceType == SourceType.Entity)
            {
                type = typeof(PositionedObject);

            }
            else
            {
                type = TypeManager.GetTypeFromString(typeName);
            }

            if (type == null)
            {
                // this is an unknown type, so we should just return null;
                return null;
            }
            else
            {

                string firstVariable = variableToReset;

                bool shouldRecur = false;

                if (variableToReset.Contains('.'))
                {
                    firstVariable = variableToReset.Substring(0, variableToReset.IndexOf('.'));
                    shouldRecur = true;
                }

                MemberInfo[] memberInfoArray = type.GetMember(firstVariable);

                if (memberInfoArray.Length == 0)
                {
                    throw new InvalidOperationException("Could not find any members with the name " + firstVariable + " in the NamedObject " + namedObjectSave.ToString() + " of type " + type);
                }

                MemberInfo memberInfo = memberInfoArray[0];

                if (shouldRecur)
                {
                    string typeOfMember = null;

                    if (memberInfo is FieldInfo)
                    {
                        typeOfMember = ((FieldInfo)memberInfo).FieldType.Name;
                    }
                    else
                    {
                        typeOfMember = ((PropertyInfo)memberInfo).PropertyType.Name;
                    }
                    return GetMemberInfoForMember(namedObjectSave, typeOfMember, variableToReset.Substring(variableToReset.IndexOf('.') + 1));
                }
                else
                {
                    return memberInfo;
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:61,代码来源:NamedObjectSaveCodeGenerator.cs

示例2: WriteMethodForClone


//.........这里部分代码省略.........

                if (foundConversion != null)
                {
                    cloneString = foundConversion.ConversionPattern.Replace("{NEW}", objectName);
                    cloneString = cloneString.Replace("{THIS}", rfs.GetInstanceName());
                    usesFullConversion = true;
                }
            }

            if (namedObjectToPullFrom != null)
            {
                containerName = namedObjectToPullFrom;
            }
            if (!string.IsNullOrEmpty(overridingName))
            {
                containerName = overridingName;
            }

            string listMemberName = ContentParser.GetMemberNameForList(FileManager.GetExtension(namedObject.SourceFile), namedObject.InstanceType);

            if (!string.IsNullOrEmpty(listMemberName))
            {
                listMemberName += ".";
            }

            if (nameOfSourceInContainer == "Entire File" && string.IsNullOrEmpty(listMemberName))
            {
                if (usesFullConversion)
                {
                    codeBlock.Line(cloneString + ";");
                }
                else if (cloneString.Contains("{THIS}"))
                {
                    string entireString = cloneString.Replace("{THIS}", objectName);
                    entireString = entireString.Replace("{SOURCE_FILE}", containerName);

                    codeBlock.Line(entireString);
                }
                else
                {
                    codeBlock.Line(string.Format("{0} = {1}{2};",
                                                 objectName,
                                                 containerName,
                                                 cloneString));
                }
            }
            else
            {
                string findByNameLine = "";
                if (nosAti != null)
                {
                    findByNameLine = nosAti.FindByNameSyntax;

                    if (string.IsNullOrEmpty(findByNameLine))
                    {
                        string message = "The object " + namedObject.ToString() + " is part of a file.  To be properly generated " +
                            "the AssetTypeInfo (or CSV value) for " + nosAti.ToString() + " must contain a FindByNameSyntax property";

                        throw new Exception(message);
                    }
                }



                findByNameLine = findByNameLine.Replace("OBJECTNAME", nameOfSourceInContainer);

                string possibleDot = ".";

                if (findByNameLine.StartsWith("["))
                {
                    possibleDot = "";
                }

                //if (namedObject.AddToManagers)
                {
                    // Not sure why we don't clone on a non add to manager.  This post right here suggests we should
                    // and I tend to believe Scott so...I'm following his advice:
                    // http://www.flatredball.com/frb/forum/viewtopic.php?f=26&t=4741
                    codeBlock.Line(string.Format("{0} = {1}{2}{3}{4}{5};",
                                                 objectName,
                                                 containerName,
                                                 possibleDot,
                                                 listMemberName,
                                                 findByNameLine,
                                                 cloneString));
                }
                //else
                //{

                //    stringBuilder.AppendLine(
                //        string.Format("\t\t\t{0} = {1}{2}{3}{4};",
                //            objectName,
                //            containerName,
                //            possibleDot,
                //            listMemberName,
                //            findByNameLine));
                //}
            }
            return containerName;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:101,代码来源:NamedObjectSaveCodeGenerator.cs

示例3: CreateVariableResetField

        private static void CreateVariableResetField(NamedObjectSave namedObjectSave, string typeName, ICodeBlock codeBlock)
        {
            for (int i = 0; i < namedObjectSave.VariablesToReset.Count; i++)
            {
                string variableToReset = namedObjectSave.VariablesToReset[i];

                string typeOfResetVariable = "";
                MemberInfo memberInfo = null;

                try
                {
                    memberInfo = GetMemberInfoForMember(namedObjectSave, typeName, variableToReset);
                }
                catch (InvalidOperationException)
                {
                    // If we got here that means that the object doesn't have a variable matching what was passed in.
                    // That's okay, we can just continue...well, after we tell the user about the problem.
                }

                if (memberInfo == null)
                {
                    GlueGui.ShowMessageBox("Error generating code for " + namedObjectSave.ToString() + ":\nCould not find variable " + variableToReset + " in " + namedObjectSave.SourceClassType);
                }
                else
                {
                    if (memberInfo is PropertyInfo)
                    {
                        typeOfResetVariable = TypeManager.ConvertToCommonType(((PropertyInfo)memberInfo).PropertyType.ToString());
                    }
                    else
                    {
                        typeOfResetVariable = TypeManager.ConvertToCommonType(((FieldInfo)memberInfo).FieldType.ToString());

                    }

                    // 1/2/2011
                    // The following
                    // used to be protected
                    // (instance) variable, but
                    // this greatly bloats the size
                    // of instances.  I'm going to make
                    // these variables static and we'll see
                    // if this causes problems.
                    codeBlock.Line(StringHelper.SpaceStrings("static", typeOfResetVariable, namedObjectSave.InstanceName) +
                                   variableToReset.Replace(".", "") + "Reset;");
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:48,代码来源:NamedObjectSaveCodeGenerator.cs


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