本文整理汇总了C#中System.Reflection.FieldInfo.ExcName方法的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo.ExcName方法的具体用法?C# FieldInfo.ExcName怎么用?C# FieldInfo.ExcName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.FieldInfo
的用法示例。
在下文中一共展示了FieldInfo.ExcName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromFieldInfo
public static FieldTranslationInfo FromFieldInfo(FieldInfo fieldInfo, TranslationInfo info)
{
if (fieldInfo == null)
return null;
var fieldInfoDeclaringType = fieldInfo.DeclaringType;
if (fieldInfoDeclaringType == null)
throw new Exception("fieldInfo.DeclaringType is null"); // Resharper
var fti = new FieldTranslationInfo();
if (fieldInfo.IsLiteral)
fti._destination = FieldTranslationDestionations.ClassConst;
{
fti._scriptName = fieldInfo.Name;
var scriptNameAttribute = fieldInfo.GetCustomAttribute<ScriptNameAttribute>();
if (scriptNameAttribute != null)
{
fti._scriptName = scriptNameAttribute.Name;
fti._isScriptNamePhpEncoded = scriptNameAttribute.Kind == ScriptNameAttribute.Kinds.IntIndex;
}
}
{
var asDefinedConstAttribute = fieldInfo.GetCustomAttribute<AsDefinedConstAttribute>();
if (asDefinedConstAttribute != null)
{
fti._destination = FieldTranslationDestionations.DefinedConst;
if (!string.IsNullOrEmpty(asDefinedConstAttribute.DefinedConstName))
fti._scriptName = asDefinedConstAttribute.DefinedConstName;
}
}
{
var globalVariableAttribute = fieldInfo.GetCustomAttribute<GlobalVariableAttribute>();
if (globalVariableAttribute != null)
{
Check(fieldInfo, fti);
fti._destination = FieldTranslationDestionations.GlobalVariable;
if (!string.IsNullOrEmpty(globalVariableAttribute.GlobalVariableName))
fti._scriptName = globalVariableAttribute.GlobalVariableName;
}
}
{
var asValueAttribute = fieldInfo.GetCustomAttribute<AsValueAttribute>();
if (asValueAttribute != null)
{
Check(fieldInfo, fti);
fti._destination = FieldTranslationDestionations.JustValue;
fti._usGlueForValue = asValueAttribute.Glue;
}
}
var canBeNull = false;
switch (fti._destination)
{
case FieldTranslationDestionations.JustValue:
case FieldTranslationDestionations.GlobalVariable:
canBeNull = true;
fti._includeModule = null; // force null
break;
case FieldTranslationDestionations.DefinedConst:
case FieldTranslationDestionations.ClassConst:
case FieldTranslationDestionations.NormalField:
var cti = info.GetOrMakeTranslationInfo(fieldInfoDeclaringType);
fti._includeModule = cti.ModuleName;
if (cti.BuildIn)
{
fti._includeModule = null;
canBeNull = true;
}
var isFieldOutsideClass = fti._destination == FieldTranslationDestionations.GlobalVariable ||
fti._destination == FieldTranslationDestionations.DefinedConst;
{
// can be in other module for GlobalVariable and DefinedConst
var moduleAttribute = fieldInfo.GetCustomAttribute<ModuleAttribute>();
if (moduleAttribute != null)
{
if (!isFieldOutsideClass)
throw new Exception(string.Format("Module attribute can only be defined for GlobalVariable or DefinedConst. Check {0}.", fieldInfo.ExcName()));
fti._includeModule = new PhpCodeModuleName(moduleAttribute.ModuleShortName,
info.GetOrMakeTranslationInfo(fieldInfoDeclaringType.Assembly));
}
}
if (cti.IsPage)
fti._isDefinedInNonincludableModule = true;
if (!isFieldOutsideClass)
{
if (cti.IsArray || cti.Type.IsEnum || cti.BuildIn)
{
canBeNull = true;
fti._includeModule = null; // force null
}
else if (cti.DontIncludeModuleForClassMembers)
throw new Exception(
string.Format("field {0} belongs to nonincludable class (array, enum or skipped)",
fieldInfo.ExcName()));
}
break;
}
if (!fti._includeModule.IsEmpty())
return fti;
if (canBeNull)
{
//.........这里部分代码省略.........
示例2: Check
private static void Check(FieldInfo fieldInfo, FieldTranslationInfo fti)
{
if (fti == null) throw new ArgumentNullException("fti");
if (fti.Destination != FieldTranslationDestionations.NormalField &&
fti.Destination != FieldTranslationDestionations.ClassConst)
throw new Exception(string.Format("Unable to find right way to convert field {0}",
fieldInfo.ExcName()));
}