本文整理汇总了C#中ProtoBuf.Meta.BasicList.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# BasicList.IndexOf方法的具体用法?C# BasicList.IndexOf怎么用?C# BasicList.IndexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.Meta.BasicList
的用法示例。
在下文中一共展示了BasicList.IndexOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
/// <summary>
/// Fully compiles the current model into a static-compiled serialization dll
/// (the serialization dll still requires protobuf-net for support services).
/// </summary>
/// <remarks>A full compilation is restricted to accessing public types / members</remarks>
/// <returns>An instance of the newly created compiled type-model</returns>
public TypeModel Compile(CompilerOptions options)
{
if (options == null) throw new ArgumentNullException("options");
string typeName = options.TypeName;
string path = options.OutputPath;
BuildAllSerializers();
Freeze();
bool save = !Helpers.IsNullOrEmpty(path);
if (Helpers.IsNullOrEmpty(typeName))
{
if (save) throw new ArgumentNullException("typeName");
typeName = Guid.NewGuid().ToString();
}
string assemblyName, moduleName;
if(path == null)
{
assemblyName = typeName;
moduleName = assemblyName + ".dll";
}
else
{
assemblyName = new System.IO.FileInfo(System.IO.Path.GetFileNameWithoutExtension(path)).Name;
moduleName = assemblyName + System.IO.Path.GetExtension(path);
}
#if FEAT_IKVM
IKVM.Reflection.AssemblyName an = new IKVM.Reflection.AssemblyName();
an.Name = assemblyName;
AssemblyBuilder asm = universe.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save);
if(!Helpers.IsNullOrEmpty(options.ImageRuntimeVersion) && options.MetaDataVersion != 0)
{
asm.__SetImageRuntimeVersion(options.ImageRuntimeVersion, options.MetaDataVersion);
}
ModuleBuilder module = asm.DefineDynamicModule(moduleName, path);
#else
AssemblyName an = new AssemblyName();
an.Name = assemblyName;
AssemblyBuilder asm = AppDomain.CurrentDomain.DefineDynamicAssembly(an,
(save ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run)
);
ModuleBuilder module = save ? asm.DefineDynamicModule(moduleName, path)
: asm.DefineDynamicModule(moduleName);
#endif
if (!Helpers.IsNullOrEmpty(options.TargetFrameworkName))
{
// get [TargetFramework] from mscorlib/equivalent and burn into the new assembly
Type versionAttribType = null;
try
{ // this is best-endeavours only
versionAttribType = GetType("System.Runtime.Versioning.TargetFrameworkAttribute", MapType(typeof(string)).Assembly);
}
catch { /* don't stress */ }
if (versionAttribType != null)
{
PropertyInfo[] props;
object[] propValues;
if (Helpers.IsNullOrEmpty(options.TargetFrameworkDisplayName))
{
props = new PropertyInfo[0];
propValues = new object[0];
}
else
{
props = new PropertyInfo[1] { versionAttribType.GetProperty("FrameworkDisplayName") };
propValues = new object[1] { options.TargetFrameworkDisplayName };
}
CustomAttributeBuilder builder = new CustomAttributeBuilder(
versionAttribType.GetConstructor(new Type[] { MapType(typeof(string)) }),
new object[] { options.TargetFrameworkName },
props,
propValues);
asm.SetCustomAttribute(builder);
}
}
// copy assembly:InternalsVisibleTo
Type internalsVisibleToAttribType = null;
#if !FX11
try
{
internalsVisibleToAttribType = MapType(typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute));
}
catch { /* best endeavors only */ }
#endif
if (internalsVisibleToAttribType != null)
{
BasicList internalAssemblies = new BasicList(), consideredAssemblies = new BasicList();
foreach (MetaType metaType in types)
{
Assembly assembly = metaType.Type.Assembly;
if (consideredAssemblies.IndexOfReference(assembly) >= 0) continue;
//.........这里部分代码省略.........
示例2: WriteAssemblyAttributes
private void WriteAssemblyAttributes(CompilerOptions options, string assemblyName, AssemblyBuilder asm)
{
if (!Helpers.IsNullOrEmpty(options.TargetFrameworkName))
{
// get [TargetFramework] from mscorlib/equivalent and burn into the new assembly
Type versionAttribType = null;
try
{ // this is best-endeavours only
versionAttribType = GetType("System.Runtime.Versioning.TargetFrameworkAttribute", MapType(typeof(string)).Assembly);
}
catch { /* don't stress */ }
if (versionAttribType != null)
{
PropertyInfo[] props;
object[] propValues;
if (Helpers.IsNullOrEmpty(options.TargetFrameworkDisplayName))
{
props = new PropertyInfo[0];
propValues = new object[0];
}
else
{
props = new PropertyInfo[1] { versionAttribType.GetProperty("FrameworkDisplayName") };
propValues = new object[1] { options.TargetFrameworkDisplayName };
}
CustomAttributeBuilder builder = new CustomAttributeBuilder(
versionAttribType.GetConstructor(new Type[] { MapType(typeof(string)) }),
new object[] { options.TargetFrameworkName },
props,
propValues);
asm.SetCustomAttribute(builder);
}
}
// copy assembly:InternalsVisibleTo
Type internalsVisibleToAttribType = null;
#if !FX11
try
{
internalsVisibleToAttribType = MapType(typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute));
}
catch { /* best endeavors only */ }
#endif
if (internalsVisibleToAttribType != null)
{
BasicList internalAssemblies = new BasicList(), consideredAssemblies = new BasicList();
foreach (MetaType metaType in types)
{
Assembly assembly = metaType.Type.Assembly;
if (consideredAssemblies.IndexOfReference(assembly) >= 0) continue;
consideredAssemblies.Add(assembly);
AttributeMap[] assemblyAttribsMap = AttributeMap.Create(this, assembly);
for (int i = 0; i < assemblyAttribsMap.Length; i++)
{
if (assemblyAttribsMap[i].AttributeType != internalsVisibleToAttribType) continue;
object privelegedAssemblyObj;
assemblyAttribsMap[i].TryGet("AssemblyName", out privelegedAssemblyObj);
string privelegedAssemblyName = privelegedAssemblyObj as string;
if (privelegedAssemblyName == assemblyName || Helpers.IsNullOrEmpty(privelegedAssemblyName)) continue; // ignore
if (internalAssemblies.IndexOf(new StringFinder(privelegedAssemblyName)) >= 0) continue; // seen it before
internalAssemblies.Add(privelegedAssemblyName);
CustomAttributeBuilder builder = new CustomAttributeBuilder(
internalsVisibleToAttribType.GetConstructor(new Type[] { MapType(typeof(string)) }),
new object[] { privelegedAssemblyName });
asm.SetCustomAttribute(builder);
}
}
}
}